import ( "k8s.io/client-go/rest" "k8s.io/client-go/util/homedir" "k8s.io/client-go/tools/clientcmd" "fmt" ) func main() { kubeconfig := filepath.Join(homedir.HomeDir(), ".kube", "config") config, err := clientcmd.BuildConfigFromFlags("", kubeconfig) if err != nil { panic(err.Error()) } config.QPS = 50 // Create the clientset clientset, err := kubernetes.NewForConfig(config) if err != nil { panic(err.Error()) } deployments, err := clientset.AppsV1().Deployments("").List(context.Background(), metav1.ListOptions{}) if err != nil { panic(err) } fmt.Printf("There are %d deployments in the cluster\n", len(deployments.Items)) }
import ( "k8s.io/client-go/rest" "k8s.io/client-go/kubernetes" "fmt" ) func main() { config, err := rest.InClusterConfig() if err != nil { panic(err.Error()) } config.QPS = 100 // Create the clientset clientset, err := kubernetes.NewForConfig(config) if err != nil { panic(err.Error()) } deployments, err := clientset.AppsV1().Deployments("").List(context.Background(), metav1.ListOptions{}) if err != nil { panic(err) } fmt.Printf("There are %d deployments in the cluster\n", len(deployments.Items)) }In this example, we use the `rest.InClusterConfig()` function to build a configuration object for a Kubernetes client running inside a pod. We then set the `QPS` field of the `Config` struct to 100 before creating the clientset.