Skip to content

Instantly share code, notes, and snippets.

@rnemeth90
Created October 7, 2022 19:17
Show Gist options
  • Save rnemeth90/498bcc5cb52cc34c17af2bd5f0fefc2d to your computer and use it in GitHub Desktop.
Save rnemeth90/498bcc5cb52cc34c17af2bd5f0fefc2d to your computer and use it in GitHub Desktop.
Kubernetes: Get Count of Pods per Node
nodes=$(kubectl get nodes --no-headers | awk '{print $1}')
for n in ${nodes[@]}; do
pods=$(kubectl get pod -A --field-selector spec.nodeName=$n --no-headers | awk '{print $2}')
echo $n = $(echo $pods | wc -w)
done
@mloskot
Copy link

mloskot commented Oct 15, 2024

Nice! A one-liner version:

for n in $(kubectl get nodes --no-headers | awk '{print $1}'); do echo -n "${n}: "; kubectl get pod -A --field-selector spec.nodeName=$n --no-headers | awk '{print $1}' | wc -w; done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment