简体   繁体   English

如何使用go-client获取kubernetes中Pod的状态

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

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. 我正在尝试删除kubernetes集群中的Pod,然后检查其状态以查看Pod下来需要多长时间才能重新启动。 I could not find any helpful example for the second part which is getting a specific pod status using go-client. 对于第二部分,我找不到任何有用的示例,该示例使用go-client获取特定的pod状态。 Any help is appreciated. 任何帮助表示赞赏。

You can use Get function to get specific pod information (below examples are getting whole Status struct): 您可以使用Get函数获取特定的pod信息(以下示例将获取整个Status结构):

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: 另外,您可以使用List函数获取特定名称空间中的所有Pod,然后对其进行范围调整:

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! 希望这可以帮助!

状态信息是整个Pod的子结构,因此您可以使用常规的吸气剂(clientset.CoreV1()等),然后查看.Status结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM