Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'd like to do a kubectl get pods and filter where the pod is in a status of ImagePullBackOff.

I've tried kubectl get pods --field-selector=status.phase=waiting and kubectl get pods --field-selector=status.phase=ImagePullBackOff but that returns no results.

I've had a look at the JSON output with -o json:

...
            {
                "image": "zzzzzzzzzzzzzzzz",
                "imageID": "",
                "lastState": {},
                "name": "nginx",
                "ready": false,
                "restartCount": 0,
                "state": {
                    "waiting": {
                        "message": "Back-off pulling image \"zzzzzzzzzzzzzzzz\"",
                        "reason": "ImagePullBackOff"
                    }
                }
            }
...

If I try target that value:

kubectl get pods --field-selector=state.waiting=ImagePullBackOff 
Error from server (BadRequest): Unable to find "/v1, Resource=pods" that match label selector "", field selector "state.waiting=ImagePullBackOff": field label not supported: state.waiting
like image 215
Chris Stryczynski Avatar asked Jul 26 '19 14:07

Chris Stryczynski


People also ask

How do you check Kubernetes PODS status using kubectl?

Using kubectl describe pods to check kube-system If the output from a specific pod is desired, run the command kubectl describe pod pod_name --namespace kube-system . The Status field should be "Running" - any other status will indicate issues with the environment.

What does status ImagePullBackOff mean?

So what exactly does ImagePullBackOff mean? The status ImagePullBackOff means that a Pod couldn't start, because Kubernetes couldn't pull a container image. The 'BackOff' part means that Kubernetes will keep trying to pull the image, with an increasing delay ('back-off').

How do I check the status of my pods?

To check if the status of your pods is healthy, the easiest way is to run the kubectl get pods command. After that, you can use kubectl describe and kubectl logs to obtain more detailed information.


1 Answers

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.

like image 96
Egor Stambakio Avatar answered Sep 21 '22 08:09

Egor Stambakio