Last active
November 8, 2016 16:27
-
-
Save thomastaylor312/43a8f3e75711264d8bd2f4b4060ceb06 to your computer and use it in GitHub Desktop.
Using the Kubernetes library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"k8s.io/kubernetes/pkg/api" | |
client "k8s.io/kubernetes/pkg/client/unversioned" | |
"k8s.io/kubernetes/pkg/fields" | |
"k8s.io/kubernetes/pkg/labels" | |
) | |
func main() { | |
//Get node information through Kubernetes api | |
kubeClient, err := client.NewInCluster() | |
if err != nil { | |
log.Fatalf("Failed to create client: %v", err) | |
} | |
listAll := api.ListOptions{LabelSelector: labels.Everything(), FieldSelector: fields.Everything()} | |
//Find snap-service through the api | |
services, err := kubeClient.Services("default").List(listAll) | |
if err != nil { | |
log.Fatalf("Failed to list services: %v", err) | |
} | |
var snapServiceIP string | |
for _, service := range services.Items { | |
if service.Name == "snap-service" { | |
log.Printf("\tsnap-service:%v \n", service.Spec.ClusterIP) | |
snapServiceIP = service.Spec.ClusterIP | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment