how to get status of a pod in kubernetes using go-client

醉酒当歌 提交于 2021-02-07 08:19:11

问题


I am trying to delete a pod in my kubernetes cluster, then check its status to see how long does it take for the pod to get down, and up again. I could not find any helpful example for the second part which is getting a specific pod status using go-client. Any help is appreciated.


回答1:


You can use Get function to get specific pod information (below examples are getting whole Status struct):

pod, _ := clientset.CoreV1().Pods("kubernetes").Get(pod.Name, metav1.GetOptions{})
fmt.Println(pod.Status)

Also, you can use List function to get all pods in the particular namespace and then range them:

pods, _ := clientset.CoreV1().Pods("kubernetes").List(metav1.ListOptions{FieldSelector: "metadata.name=kubernetes"})
for _, pod := range pods.Items {
    fmt.Println(pod.Name, pod.Status)
}

Hope this helps!




回答2:


The status info is a sub-struct of the pod as a whole so you use the normal getter (clientset.CoreV1() etc) and then look in the .Status struct.



来源:https://stackoverflow.com/questions/53857593/how-to-get-status-of-a-pod-in-kubernetes-using-go-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!