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.
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}'