How to list containers running in a kubernetes pod

Unfortunately, there isnt a simple get command that can be run to retrieve containers running inside pods. However, the custom-columns command can be exposed via kubectl to get this information out.

For more info on custom-columns visit the kubectl docs –

The following command will list pod name and container name for all pods in the default namespace

kubectl get pods,CONTAINERS:.spec.containers[*].name

The output is something like this:


You can also just get the container via the jsonpath option

kubectl get pods mongod-1 -o jsonpath='{.spec.containers[*].name}'

The reason I did a bit of research (5 minutes!) into this was because the container name is required when running the exec command in kubectl. eg:

kubectl exec -ti mongod-1 -c mongod-container bash