List all containers in all pods with status

2/27/2019

I am trying to get a list of all non-READY containers in all pods to debug a networking issue in my cluster.

Is it possible to use kubectl to get a clean list of all containers in all pods with their status (READY/..)?

I am currently using

$ kubectl get pods 

However, the output can be huge and it can be difficult to know which containers are READY and which ones have issues.

Thanks.

-- user674669
kubectl
kubernetes

1 Answer

2/27/2019

kubectl get pods -o=jsonpath='{range .items[*]}{"\n"}{.metadata.name}{":\t"}{range .status.containerStatuses[*]}{.ready}{", "}{end}{end}'

Adapted from this doc: https://kubernetes.io/docs/tasks/access-application-cluster/list-all-running-container-images/#list-containers-by-pod

Edit to describe what the jsonpath is doing:

From what I understand with the jsonpath, range iterates all of the .items[*] returned by getting the pods. \n is added to split the result to one per line, otherwise the result would come to one line. To see how the rest work, you should choose one of your pods and run: kubectl get pod podname -o yaml
.metadata.name corresponds to

apiVersion: v1
kind: Pod
metadata:
  name: podname

Similarly, .status.containerStatuses[*] corresponds to the list of container statuses that should be towards the bottom.

-- Joshua Oliphant
Source: StackOverflow