Kubernetes List All Containers that are not running

12/23/2020

How to list All Containers that are not running using Kubectl command. I want output like

CONTAINER_NAME   STATUS        POD_NAME       NAMESPACE <br>
container_1      Running       pod_1          ns1       <br>
container_2      Not Running   pod_2          ns2       <br>
container_3      Running       pod_2          ns2       <br>
-- prosenjit
customcolumn
jsonpath
kubectl
kubernetes

1 Answer

12/23/2020
kubectl get pods --field-selector status.phase!=Running

Above command will above list down all pods, not in Running status for default namespace.

if you want to run a command across all namespaces & list down all PODS

kubectl get pods --field-selector status.phase!=Running --all-namespaces

You can also print custom column as per require if you want to print Namespace

kubectl get pod --field-selector status.phase!=Running -o=custom-columns=NAME:.metadata.name,STATUS:.status.phase,NAMEDPACE:.metadata.namespace

Final command the way you are looking forward with columns

kubectl get pod --field-selector status.phase!=Running -o=custom-columns=POD_NAME:.metadata.name,STATUS:.status.phase,NAMEDPACE:.metadata.namespace,CONTAINER_NAME:.spec.containers[*].name
-- Harsh Manvar
Source: StackOverflow