import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" "k8s.io/client-go/kubernetes/typed/apps/v1" ) // Create a Kubernetes clientset config, err := rest.InClusterConfig() if err != nil { panic(err.Error()) } clientset, err := kubernetes.NewForConfig(config) if err != nil { panic(err.Error()) } // Create a Deployment object deployment := &v1.Deployment{ ObjectMeta: metav1.ObjectMeta{ Name: "my-deployment", Namespace: "my-namespace", }, Spec: v1.DeploymentSpec{ Replicas: int32p(3), Selector: &metav1.LabelSelector{ MatchLabels: map[string]string{ "app": "my-app", }, }, Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ "app": "my-app", }, }, Spec: corev1.PodSpec{ Containers: []corev1.Container{ { Name: "my-container", Image: "my-image", }, }, }, }, }, } // Create the Deployment object in the Kubernetes cluster _, err = clientset.AppsV1().Deployments("my-namespace").Create(deployment) if err != nil { panic(err.Error()) }
import ( "fmt" "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" ) // Create a Kubernetes clientset config, err := rest.InClusterConfig() if err != nil { panic(err.Error()) } clientset, err := kubernetes.NewForConfig(config) if err != nil { panic(err.Error()) } // List all Pods in a Namespace pods, err := clientset.CoreV1().Pods("my-namespace").List(v1.ListOptions{}) if err != nil { panic(err.Error()) } for _, pod := range pods.Items { fmt.Println(pod.Name) }This code lists all Pods in a specified namespace using the clientset, and then iterates over the list of Pods and prints their names. In conclusion, the k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset Interface is a part of the Kubernetes Go client library, which provides a programmatic way to interact with a Kubernetes cluster. The library can be found in the kubernetes/client-go package.