Get names of all deployment configs with no running pods

5/24/2020

Is there a simple method (that won't require googling at every use) to get names of all deployment configs with no running pods (scaled to 0) in Kubernetes / Openshift? Methods without JSON tokens and awk please.

The docs of oc get dc --help are way too long to decipher for the occasional need.

-- mirekphd
kubectl
kubernetes
openshift
openshift-client-tools
openshift-origin

1 Answer

5/24/2020

The only CLI arg for advanced filtering without working with JSON is a --field-selector, but it has a limited scope which not include spec.replicas field.

So, there will be some magic around JSON with other flag - jsonpath.

Here is a command to filter and print names of all deployments which are scaled to 0:

kubectl get deployments --all-namespaces -o=jsonpath='{range .items[?(@.spec.replicas==0)]}{.metadata.name}{"\n"}{end}'

Jsonpath reference is here.

-- Anton Kostenko
Source: StackOverflow