kubernetes – kubectl get pods: Field Selectors

I don’t think kubectl get pods supports field selectors based on the READY column directly.

But kubectl provides a method exporting the resource configuration (YAML) directly into JSON, -o json. Then, we can use jq to read, parse, and mutate K8s object results from kubectl.

In your case, you could use a command like this to filter all pods (excluding the pods from namespaces kube-system, monitoring & rtf) not in ready state:

kubectl get pods --all-namespaces --field-selector=metadata.namespace!=kube-system,metadata.namespace!=monitoring,metadata.namespace!=rtf -ojson | jq '.items[] | select(.status.containerStatuses[].ready==false) | .metadata.name'

and/or change ready=true to get the pods in ready state.

Hope it helps.

Read more here: Source link