问题描述
使用以下代码,我可以获取集群中运行的所有 Pod。如何使用 Kubernetes go-client 库找到 Pod 控制器(Deployment/DaemonSet)?
var kubeconfig *string
if home := homedir.HomeDir(); home != "" {
kubeconfig = flag.String("kubeconfig",filepath.Join(home,".kube","config"),"(optional) absolute path to the kubeconfig file")
} else {
kubeconfig = flag.String("kubeconfig","","absolute path to the kubeconfig file")
}
flag.Parse()
// use the current context in kubeconfig
config,err := clientcmd.BuildConfigFromFlags("",*kubeconfig)
if err != nil {
panic(err.Error())
}
// create the kubeClient
kubeClient,err := kubernetes.NewForConfig(config)
metricsClient,err := metricsv.NewForConfig(config)
if err != nil {
panic(err.Error())
}
pods,err := kubeClient.CoreV1().Pods("").List(context.TODO(),metav1.ListOptions{})
if err != nil {
panic(err.Error())
}
for _,pod := range pods.Items {
fmt.Println(pod.Name)
// how can I get the Pod controller? (Deployment/DaemonSet)
// e.g. fmt.Println(pod.Controller.Name)
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)