Instantly share code, notes, and snippets.

@jesperfj /k8s.go
Last active Oct 24, 2016

Embed
What would you like to do?
import (
"k8s.io/client-go/1.4/kubernetes"
"k8s.io/client-go/1.4/pkg/api"
"k8s.io/client-go/1.4/pkg/labels"
"k8s.io/client-go/1.4/pkg/apis/extensions/v1beta1"
"k8s.io/client-go/1.4/tools/clientcmd"
)
var (
kubeconfig = flag.String("kubeconfig", os.Getenv("HOME")+"/.kube/config", "absolute path to the kubeconfig file")
)
func main() {
flag.Parse()
var appName = "myapp"
config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
if err != nil {
panic(err.Error())
}
// creates the clientset
clientset, err := kubernetes.NewForConfig(config)
check(err)
m := map[string]string{
"app": appName,
}
dpls, err := clientset.Extensions().Deployments("").List(
api.ListOptions{
LabelSelector: labels.SelectorFromSet(m),
})
check(err)
fmt.Printf("There are %d deployments in the cluster\n", len(dpls.Items))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment