我正在使用kubectl来检索 pod 列表:
kubectl get pods --selector=artifact=boot-example -n my-sandbox
我得到的结果是:
NAME READY STATUS RESTARTS AGE
boot-example-757c4c6d9c-kk7mg 0/1 Running 0 77m
boot-example-7dd6cd8d49-d46xs 1/1 Running 0 84m
boot-example-7dd6cd8d49-sktf8 1/1 Running 0 88m
我只想获得“ ready ”(已通过readinessProbe)的 pod 。是否有任何kubectl命令仅返回“ ready ” Pod?如果不是kubectl命令,那么也许还有其他方法吗?
最佳答案
您可以使用以下命令:
kubectl -n your-namespace get pods -o custom-columns=NAMESPACE:metadata.namespace,POD:metadata.name,PodIP:status.podIP,READY-true:status.containerStatuses[*].ready | grep true
这将为您返回带有“ ready ”容器的容器。
要在没有grep的情况下执行此操作,可以使用以下命令:
kubectl -n your-namespace get pods -o go-template='{{range $index, $element := .items}}{{range .status.containerStatuses}}{{if .ready}}{{$element.metadata.name}}{{"\n"}}{{end}}{{end}}{{end}}'
kubectl -n your-namespace get pods -o jsonpath='{range .items[*]}{.status.containerStatuses[*].ready.true}{.metadata.name}{ "\n"}{end}'
这将返回“ ready ”的广告连播名称
关于kubernetes - 如何获取 "ready"的Pod列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58992774/