Last active
October 24, 2016 19:49
-
-
Save jesperfj/964815ea856310c9c0cc413d230d03c9 to your computer and use it in GitHub Desktop.
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
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