import ( "context" "fmt" "os" "github.com/googlecloudplatform/kubernetes/pkg/client" "github.com/googlecloudplatform/kubernetes/pkg/client/config" ) func main() { kubeconfig := config.GetConfig() client, err := client.New(kubeconfig) if err != nil { fmt.Fprintf(os.Stderr, "failed to create Kubernetes client: %v\n", err) os.Exit(1) } ctx := context.TODO() // Now you can use the client object to interact with the Kubernetes API server }
import ( "context" "fmt" "os" "github.com/googlecloudplatform/kubernetes/pkg/client" "github.com/googlecloudplatform/kubernetes/pkg/client/config" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func main() { kubeconfig := config.GetConfig() client, err := client.New(kubeconfig) if err != nil { fmt.Fprintf(os.Stderr, "failed to create Kubernetes client: %v\n", err) os.Exit(1) } ctx := context.TODO() // List all running pods in the "default" namespace podList, err := client.CoreV1().Pods("default").List(ctx, metav1.ListOptions{ FieldSelector: "status.phase=Running", }) if err != nil { fmt.Fprintf(os.Stderr, "failed to list pods: %v\n", err) os.Exit(1) } // Print the names of all running pods for _, pod := range podList.Items { fmt.Printf("%s\n", pod.Name) } }In the above examples, we are using the Kubernetes client library for Go to create a new client object and list all running pods in a namespace. The package library being used is github.com.googlecloudplatform.kubernetes.pkg.client.