Listing pod name which consumes highest CPU

11/10/2019

I have to list the name of the pod which consumes highest CPU. I am close with this command.

kubectl top pod| sed -n '2p'

It prints pod-01 34 45Mi

How do I extract just the pod name out of this.

-- Naxi
kubernetes

1 Answer

11/11/2019

Actually, with kubectl top pods, you are not getting the pod with the highest CPU, but you get the list of pods with their CPU usage. With your command you will get the first listed pod's name, not the one's with highest CPU. The command would be:

kubectl top pod --sort-by cpu --no-headers=true | head -1 | awk '{print $1}'
-- suren
Source: StackOverflow