Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the Pod which has the maximum CPU usage

Tags:

kubernetes

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

like image 917
Gowtham Avatar asked Jan 25 '19 20:01

Gowtham


People also ask

How much CPU is a pod using?

Each container has a limit of 0.5 CPU and 128MiB of memory. You can say the Pod has a request of 0.5 CPU and 128 MiB of memory, and a limit of 1 CPU and 256MiB of memory.

What happens if pod exceeds CPU limit?

"A Container might or might not be allowed to exceed its CPU limit for extended periods of time. However, it will not be killed for excessive CPU usage." Container will not be allowed to use more CPU than it's limit on average, other container will be protected from excessive CPU usage.

How do I set CPU limit in Kubernetes?

Specify a CPU request and a CPU limit To specify a CPU request for a container, include the resources:requests field in the Container resource manifest. To specify a CPU limit, include resources:limits . The args section of the configuration file provides arguments for the container when it starts.


4 Answers

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

kubectl top po -A --sort-by=cpu
like image 133
Akhila. G.Krishnan Avatar answered Oct 03 '22 15:10

Akhila. G.Krishnan


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.

like image 39
Ryan Dawson Avatar answered Oct 03 '22 17:10

Ryan Dawson


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

like image 42
Lukasz Dynowski Avatar answered Oct 03 '22 15:10

Lukasz Dynowski


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

like image 32
parth shah Avatar answered Oct 03 '22 16:10

parth shah