How to calculate Percentage utilization of particular pod in kubernetes with metrics server?

11/26/2019

I want to calculate the CPU and Memory Percentage of Resource utilization of an individual pod in Kubernetes. For that, I am using metrics server API

  1. From the metrics server, I get the utilization from this command

kubectl top pods --all-namespaces

kube-system   coredns-5644d7b6d9-9whxx                   2m           6Mi
kube-system   coredns-5644d7b6d9-hzgjc                   2m           7Mi
kube-system   etcd-manhattan-master                      10m          53Mi
kube-system   kube-apiserver-manhattan-master            23m          257Mi

But I want the percentage utilization of individual pod Both CPU % and MEM%

From this output by top command it is not clear that from how much amount of cpu and memory it consumes the resultant amount?

I don't want to use Prometheus operator I saw one formula for it

sum (rate (container_cpu_usage_seconds_total{image!=""}[1m])) by (pod_name)

Can I calculate it with MetricsServer API?

I thought to calculate like this

CPU% = ((2+2+10+23)/ Total CPU MILLICORES)*100

MEM% = ((6+7+53+257)/AllocatableMemory)* 100

Please tell me if I right or wrong. Because I didn't see any standard formula for calculating pod utilization in Kubernetes documentation

-- UDIT JOSHI
kubectl
kubernetes

1 Answer

11/26/2019

Unfortunately kubectl top pods provides only a quantity values and not a percentages.

Here is a good explanation of how to interpret those values.

It is currently not possible to list pod resource usage in percentages with a kubectl top command.

You could still chose Grafana with Prometheus but it was already stated that you don't want to use it (however maybe another member of the community with similar problem would do so I am mentioning it here).

EDIT:

Your formulas are correct. They will calculate how much CPU/Mem is being consumed by all Pods relative to total CPU/Mem you got.

I hope it helps.

-- OhHiMark
Source: StackOverflow