Saturday, 11 July 2026

Get Pod Counts via Kubectl in WSL

 It would be usefull to figure out how many pods running in a given AKS cluster sometimes for various diagnostic needs. In this post let's see how we can use kubectl command to get pod count in diffrent combinations.

Below are some examples.


If we need to get all pods in all namespace count we can use below command (s).

Get pod count in all namespaces regardless of their state.

kubectl get pods -A --no-headers | wc -l

or 

kubectl get pods --all-namespaces --no-headers | wc -l

Get only running state pods.

kubectl get pods -A --field-selector=status.phase=Running --no-headers | wc -l

Count pods per namespace

kubectl get pods -A --no-headers | awk '{print $1}' | sort | uniq -c

Count pods per namespace and by their state.

kubectl get pods -A -o json |
jq -r '
  .items[]
  | [.metadata.namespace, .status.phase]
  | @tsv
' |
sort |
uniq -c |
awk '{print $2 "\t" $3 "\t" $1}'

Count pod only by state.

kubectl get pods -A -o json |
jq -r '
  .items[]
  | .status.phase
' |
sort |
uniq -c |
awk '{print $2 "\t" $1}'



No comments:

Popular Posts