How do i list all containers in Kubernetes cluster using kubectl?

Current documentation doesn't mention anything like 'container' resource.

kubectl get pod -o json

lists all pods which contains container descriptions. But is it possible to list containers as first class citizens?


This will get all container with the namespace in a pretty format:

kubectl get pods --all-namespaces -o=custom-columns=NameSpace:.metadata.namespace,NAME:.metadata.name,CONTAINERS:.spec.containers[*].name
| improve this answer | |

When you don't use the namespace flag you are only looking in the default namespace. Try

kubectl get pod --all-namespaces

That will list all the pods in your cluster

You can filter via namespace like

kubectl get pod -n kube-system

To show all containers

kubectl get pods --all-namespaces -o jsonpath={.items[*].spec.containers[*].name}
| improve this answer | |
  • Commands in the answer list pods. Is there any way how to list containers in a similar way? – czerny Sep 13 '17 at 16:24
  • 1
    you can do this kubectl get pods --all-namespaces -o jsonpath={.items[*].spec.containers[*].name} its not as nicely printed out – Mike Sep 13 '17 at 16:31
  • Thanks. Could you please copy it to the main answer since the question is really about containers, not pods? – czerny Sep 13 '17 at 17:39
  • done.. I made an edit – Mike Sep 14 '17 at 10:58
kubectl get pods --all-namespaces

EDIT : damn, burned ! :)

| improve this answer | |

You can list all containers in default namespace

kubectl get pods -o=jsonpath="{.items[*].spec.containers[*].name}"

Also you can user --namespace and --selector.

kubectl get pods --namespace default --selector app=nginx -o=jsonpath="{.items[*].spec.containers[*].name}"


https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#get https://kubernetes.io/docs/reference/kubectl/jsonpath/

| improve this answer | |
kubectl describe pods <pod name>

This will list containers in pods of given name.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.