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
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.
"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.
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.
you can run the below command to sort all pods across all namespaces by their cpu utilization.
kubectl top po -A --sort-by=cpu
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.
$ kubectl top pods --all-namespaces --sort-by cpu
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With