mirekphd
mirekphd

Reputation: 6871

Get names of all deployment configs with no running pods

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.

Upvotes: 1

Views: 2530

Answers (1)

Anton Kostenko
Anton Kostenko

Reputation: 9033

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.

Upvotes: 4

Related Questions