欢迎光临
我们一直在努力

client-go使用技巧

Pod使用集群kubeconfig

import "k8s.io/client-go/rest"

cfg, err := rest.InClusterConfig()
if err != nil {
	klog.Fatalf("Error building kubeconfig: %s", err.Error())
}

list/watch指定namespace

informerFactory := informers.NewSharedInformerFactoryWithOptions(kubeClient, 0, informers.WithNamespace("default"))

list/watch指定fieldSelector

informerFactory := informers.NewSharedInformerFactoryWithOptions(kubeClient, 0, informers.WithTweakListOptions(
	func(options *metav1.ListOptions) {
		options.FieldSelector = "metadata.name=test"
	}))

list/watch指定labelSelector

informerFactory := informers.NewSharedInformerFactoryWithOptions(kubeClient, 0, informers.WithTweakListOptions(
	func(options *metav1.ListOptions) {
		options.LabelSelector = "app=test"
	}))

 

未经允许不得转载:大有博文 » client-go使用技巧
分享到: 更多 (0)

大前端WP主题 更专业 更方便

联系我们联系我们