How can I view pods with kubectl and filter based on having a status of ImagePullBackOff?

Using json output and piping through jq:

kubectl get pod -o=json | jq '.items[]|select(any( .status.containerStatuses[]; .state.waiting.reason=="ImagePullBackOff"))|.metadata.name'

Last chunk |.metadata.name means it'll list pod names instead of the entire structures.


You can use command below:

kubectl get pods --all-namespaces -o custom-columns=NAMESPACE:metadata.namespace,POD:metadata.name,PodIP:status.podIP,STATE:status.containerStatuses[*].state.waiting.reason | grep ImagePullBackOff

BTW: your command kubectl get pods --field-selector=state.waiting=ImagePullBackOff fails because there is no state.waiting selector in kubernetes. Thats why you see field label not supported: state.waiting error.

As per official documentation and Field Selectors docs:

A Pod’s status field is a PodStatus object, which has a phase field.

Here are the possible values for phase:

  • Pending
  • Running
  • Succeeded
  • Failed
  • Unknown

So use custom-columns output.


As you can see in the offical doc for kubernetes,

Supported field selectors vary by Kubernetes resource type. All resource types support the metadata.name and metadata.namespace fields. Using unsupported field selectors produces an error.

Ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/field-selectors/#supported-fields

You can try this:

kubectl get pod --all-namespaces | grep "ImagePullBackOff" | awk '{print $2 " -n " $1}' | xargs kubectl get pod -o json

Or:

kubectl get pod -o jsonpath='{.items[?(@.status.containerStatuses[*].state.waiting.reason=="ImagePullBackOff")].metadata.name}'