How to List all Containers Running in a Cluster
Problem
View all the containers runnings inside a cluster.
Environment
- Platform9 Managed Kubernetes - All Versions
- kubectl
Procedure
- Download the kubeconfig for the cluster you want the information for.
- Save the kubeconfig at the following path ~/.kube/config or run the kubectl command with the --kubeconfig= command
- Run the following command to get a list and number of running containers of each type.
kubectl get pods --all-namespaces -o jsonpath="{.items[*].spec.containers[*].name}" | tr -s ' ' '\n' |sort |uniq -c
Additional Information
You can obtain other information about the containers by changing the spec. value. For example you can get a list and number of all images running in a cluster by running the above command with spec.containers[*].image
.
Was this page helpful?