[英]kubectl - How to get the list of all pods that have been restarted at least once
[英]How to get the list of pods with container name for pods that have restarted
使用此命令,我能够获取已重新启动的容器名称。
kubectl get pods -o jsonpath='{.items[*].status.containerStatuses[?(@.restartCount>0)].name}'
有没有办法在同一命令中也获取 pod 名称?
用kubectl得到json再用jq处理就简单多了:
#!/usr/bin/env bash
kubectl get pods -o=json |
jq -r '.items[] |
"\(.metadata.name) \(.status.containerStatuses[]|select(.restartCount>0).name)"'
我没试过这个。
如果 (,) 有效。 这不是您想要的,因为它应该为您提供每个 Pod 名称,然后是与谓词匹配的容器名称列表。
我认为您不能单独使用kubectl --output=jsonpath
来仅过滤具有重启容器的 Pod 名称。
FILTER='
{range .items[*]}
{.metadata.name}
{"\t"}
[
{.status.containerStatuses[?(@.restartCount>0)].name}
]
{"\n"}
{end}
'
kubectl get pods \
--output=jsonpath="${FILTER}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.