Search code examples
kuberneteskubectl

How to get a list of pods that have status Running without resorting to external commands?


Is it possible to get a list of pods that have status Running from kubectl?

Using an external command it would be:

kubectl get pods | grep Running

Can I ask this from kubectl directly instead of string matching with grep or awk?


Solution

  • You can use a golang template: kubectl get pods --all-namespaces -o go-template --template '{{range .items}}{{if eq (.status.phase) ("Running")}}{{.metadata.name}}{{"\n"}}{{end}}{{end}}' Of course {{.metadata.name}} can be replaced or extended with any informations you need.