首页 新闻 赞助 找找看

kubectl 命令如何列出所有非 Running 状态的 pod

0
悬赏园豆:30 [已解决问题] 解决于 2022-02-03 12:21

想通过 kubectl get pods 命令列出所有非 Running 状态的 pod,使用下面的命令

$ kubectl get pods --field-selector status.phase!=Running

输出却是

No resources found in production namespace.

实际有不少处于 CrashLoopBackOff 与 Terminating 状态的 pod,而使用 status.phase=Running 参数

$ kubectl get pods --field-selector status.phase=Running

却会列出所有 Running 状态与非 Running 状态的pod。

请问如何解决这个问题?

k8s
dudu的主页 dudu | 高人七级 | 园豆:31075
提问于:2022-02-02 14:45
< >
分享
最佳答案
0

在博文 List all failed Pods in a namespace with kubectl 中找到了原因:

kubectl get pods says the Pod is in CrashLoopBackOff, but when manually printing out the field the Pod is running? It turns out that the .status.phase field actually describes the scheduling state, not the actual state.

与解决方法:

$ kubectl get pods -o custom-columns="POD:metadata.name,STATE:status.containerStatuses[*].state.waiting.reason" | grep -v none
dudu | 高人七级 |园豆:31075 | 2022-02-02 15:00

回答中的命令不会列出处于 Terminating 状态的 pod,后来受 grep -v none 的启发(v=invert-match),找到了最简单的命令

kubectl get pods | grep -v Running
dudu | 园豆:31075 (高人七级) | 2022-02-03 12:21
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册