clientset, _ := kubernetes.NewForConfig(config) deploymentsClient := clientset.AppsV1().Deployments(namespace) deployment := &appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ Name: "my-deployment", }, Spec: appsv1.DeploymentSpec{ Replicas: int32Ptr(2), 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: "nginx:latest", }, }, }, }, }, } result, err := deploymentsClient.Create(ctx, deployment, metav1.CreateOptions{})
clientset, _ := kubernetes.NewForConfig(config) deploymentsClient := clientset.AppsV1().Deployments(namespace) deployment, err := deploymentsClient.Get(ctx, "my-deployment", metav1.GetOptions{}) deployment.Spec.Replicas = int32Ptr(3) result, err := deploymentsClient.Update(ctx, deployment, metav1.UpdateOptions{})
clientset, _ := kubernetes.NewForConfig(config) podClient := clientset.CoreV1().Pods(namespace) deletePolicy := metav1.DeletePropagationForeground err := podClient.Delete(ctx, "my-pod", metav1.DeleteOptions{ PropagationPolicy: &deletePolicy, })This example deletes an existing pod with the specified name. The go k8s.io.kubernetes.pkg.client.clientset_generated.clientset Interface is a part of the Kubernetes client library.