clientset := kubernetes.NewForConfigOrDie(config) nodeList, err := clientset.CoreV1().Nodes().List(metav1.ListOptions{}) if err != nil { return nil, err } for _, node := range nodeList.Items { // do something with the node }
clientset := kubernetes.NewForConfigOrDie(config) deployment := &appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ Name: "nginx-deployment", }, Spec: appsv1.DeploymentSpec{ Replicas: int32Ptr(2), Selector: &metav1.LabelSelector{ MatchLabels: map[string]string{ "app": "nginx", }, }, Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ "app": "nginx", }, }, Spec: corev1.PodSpec{ Containers: []corev1.Container{ { Name: "nginx", Image: "nginx:1.7.9", Ports: []corev1.ContainerPort{ { ContainerPort: 80, }, }, }, }, }, }, }, } result, err := clientset.AppsV1().Deployments(apiv1.NamespaceDefault).Create(deployment)These examples show how to use the generated clientset interface to interact with the Kubernetes API. The package library is k8s.io/kubernetes/pkg/client/clientset_generated/release_1_5.