How can I summarize all the resource limits and requests in Kubernetes with kubectl?
Unfortunately, it is not possible to do so with the use of the kubectl
solely.
However, you could for example consider using:
Returns the arithmetic sum of an array of numbers.
We’ll walk through steps necessary to monitor how much resources (CPUor memory) a Kubernetes pod is using. Hence we’ll look at:
CPU requests / limits / actual usage / throttling
Memory requests / limits / actual usage / termination
or alternatively monitor Kubernetes Node CPU and Memory Requests/Limits:
Node CPU requests/limits are a sum of the CPU requests/limits for allpods running on that node. Similarly, node memory requests/limits area sum of memory requests/limits of all pods
kube-state-metrics is a simple service that listens to the KubernetesAPI server and generates metrics about the state of the objects. (Seeexamples in the Metrics section below.) It is not focused on thehealth of the individual Kubernetes components, but rather on thehealth of the various objects inside, such as deployments, nodes andpods.
It is not possible with just kubectl
commands. However, you can use the output of kubectl
and write a basic shell script to compute the total values.
The following shell script will output total CPU limits(in m
units) of all the pods in all namespaces.
res=$(kubectl get pods -o=jsonpath='{.items[*]..resources.limits.cpu}' -A)let tot=0for i in $resdo if [[ $i =~ "m" ]]; then i=$(echo $i | sed 's/[^0-9]*//g') tot=$(( tot + i )) else tot=$(( tot + i*1000 )) fidoneecho $tot
You can extend the above to compute the CPU requests and the memory requests and limits values as well.