List `kubectl top pods` filtered by node

8/13/2019

Is there a way to get top pods filtered by node?

Use case: I have a node which is reported to use 103% of the cpu and I want to validate which pods are causing it.

-- Vojtěch
kubernetes

1 Answer

8/13/2019

I don't think there is direct way to do it with kubectl top pods command since the only option to filter is label/selector which apply to pod only.

For your use case, you can use the command:

kubectl get pods -o wide | grep <node> | awk {'print $1'} | xargs -n1 command kubectl top pods --no-headers

  • kubectl get pods -o wide: display pods with their associated node information
  • grep <node>: let you filter pod located on a specific node
  • awk {'print $1'}: print the first column (name of the pods)
  • xargs -n1 command kubectl top pods --no-headers: execute the top command for each pod without the headers (NAME, CPU, MEMORY)

Additionally, you can check the limits you've set for each pod in one specific node using the command kubectl describe node <node>

-- Titou
Source: StackOverflow