Gowtham
Gowtham

Reputation: 414

Get the Pod which has the maximum CPU usage

I would like to sort the pod by maximum CPU usage. I know there is a lot of tools which comes with monitoring. I would like to find this by using 'kubectl top' command.

any help is appreciated - thanks

Upvotes: 16

Views: 20386

Answers (4)

Ryan Dawson
Ryan Dawson

Reputation: 12538

For a general command that gives usage see stackoverflow.com/a/64025079/2746623. On unix I was doing kubectl top pod | sort -k2 -n but the linked answer is more general.

That'll tell you usage but if you want allocation (based on requests and limits) then you might instead want kubectl describe nodes. There's a github thread with some further suggestions and discussion.

Upvotes: 12

parth shah
parth shah

Reputation: 21

You can use k top pods -A --sort-by=cpu | head -4 // it will show with headers, so need head -4.

k top pods -A --sort-by=cpu --no-headers | head -3 //print without headercolumns OR

//To get top 3 pods k top pods | sort --reverse --numeric --key 2 | head -3

refer all imperative commands here-: https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#top also u can run below cmd to get understanding with examples -: k top --help

Upvotes: 1

Akhila. G.Krishnan
Akhila. G.Krishnan

Reputation: 206

you can run the below command to sort all pods across all namespaces by their cpu utilization.

kubectl top po -A --sort-by=cpu

Upvotes: 19

Lukasz Dynowski
Lukasz Dynowski

Reputation: 13570

$ kubectl top pods --all-namespaces --sort-by cpu

Upvotes: 2

Related Questions