import ( "context" "fmt" client "github.com/googlecloudplatform/kubernetes/pkg/client" v1 "k8s.io/api/core/v1" ) func main() { // create a new client service clientset, err := client.NewClient() if err != nil { panic(err.Error()) } // create a new pod resource pod := &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: "my-pod", }, Spec: v1.PodSpec{ Containers: []v1.Container{ { Name: "my-container", Image: "nginx", Command: []string{"echo", "hello"}, }, }, }, } // create a new pod in the cluster newPod, err := clientset.CoreV1().Pods().Create(context.Background(), pod, metav1.CreateOptions{}) if err != nil { panic(err.Error()) } fmt.Printf("Created pod %q\n", newPod.ObjectMeta.Name) }
import ( "context" "fmt" client "github.com/googlecloudplatform/kubernetes/pkg/client" appsv1 "k8s.io/api/apps/v1" ) func main() { // create a new client service clientset, err := client.NewClient() if err != nil { panic(err.Error()) } // get the deployment resource deployment, err := clientset.AppsV1().Deployments("default").Get(context.Background(), "my-deployment", metav1.GetOptions{}) if err != nil { panic(err.Error()) } // update the replica count of the deployment deployment.Spec.Replicas = int32Ptr(3) // update the deployment in the cluster updatedDeployment, err := clientset.AppsV1().Deployments("default").Update(context.Background(), deployment, metav1.UpdateOptions{}) if err != nil { panic(err.Error()) } fmt.Printf("Updated deployment %q\n", updatedDeployment.ObjectMeta.Name) } // helper function to convert int32 to int32 pointer func int32Ptr(i int32) *int32 { return &i }In summary, the go github.com.googlecloudplatform.kubernetes.pkg.client Client Services is a powerful package library that provides a straightforward and comprehensive way to interact with Kubernetes clusters through Go programming language. It offers a wide range of functionality, from creating and updating resources in a cluster, to discovering the status and events related to the cluster resources.