如何使用go-client获取kubernetes中Pod的状态 [英] how to get status of a pod in kubernetes using go-client

查看:1182
本文介绍了如何使用go-client获取kubernetes中Pod的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试删除kubernetes集群中的一个Pod,然后检查其状态以查看Pod下降需要多长时间,然后再次上升.对于第二部分,我找不到任何有用的示例,该示例使用go-client获取特定的pod状态.任何帮助表示赞赏.

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.

推荐答案

您可以使用Get函数获取特定的pod信息(以下示例将获取整个Status结构):

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)

此外,您可以使用List函数来获取特定命名空间中的所有Pod,然后对其进行范围调整:

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)
}

希望这会有所帮助!

这篇关于如何使用go-client获取kubernetes中Pod的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆