如何在不借助外部命令的情况下获取状态为 运行 的 pods 的列表?
How to get a list of pods that have status Running without resorting to external commands?
是否可以从 kubectl
获得状态为 Running
的 pods 的列表?
使用外部命令将是:
kubectl get pods | grep Running
我可以直接从 kubectl
询问这个问题,而不是使用 grep 或 awk 进行字符串匹配吗?
您可以使用 golang 模板:
kubectl get pods --all-namespaces -o go-template --template '{{range .items}}{{if eq (.status.phase) ("Running")}}{{.metadata.name}}{{"\n"}}{{end}}{{end}}'
当然 {{.metadata.name}}
可以用您需要的任何信息替换或扩展。
是否可以从 kubectl
获得状态为 Running
的 pods 的列表?
使用外部命令将是:
kubectl get pods | grep Running
我可以直接从 kubectl
询问这个问题,而不是使用 grep 或 awk 进行字符串匹配吗?
您可以使用 golang 模板:
kubectl get pods --all-namespaces -o go-template --template '{{range .items}}{{if eq (.status.phase) ("Running")}}{{.metadata.name}}{{"\n"}}{{end}}{{end}}'
当然 {{.metadata.name}}
可以用您需要的任何信息替换或扩展。