How to find CPU/Mem consumption of pods running on a specific node

I am trying to find a way to figure out each pod consumption (CPU/Mem) running on any given k8s worker node for eg.

So basically, when we do $kubectl top nodes, we get the CPU/Mem consumption of each node in the cluster. Now, if I want to drill down on a specific node, and see how much each Pod running on a given node is consuming the CPU/Mem resources. How would I find this, using any kubectl or any shell script ?

Please help or point me to any reference docs.

Regards,
Raj

1 Like

You may use this -

kubectl top pods --all-namespaces --no-headers | awk ‘{print $2, $1, $3, $4}’ | while read pod ns cpu mem; do node=$(kubectl get pod $pod -n $ns -o jsonpath=‘{.spec.nodeName}’); echo -e “NAMESPACE: $ns\tPOD: $pod\tCPU: $cpu\tMEMORY: $mem\tNODE: $node”; done | grep

1 Like