How to get Kubernetes CPU allocation for all pods

With the a average person using Kubernetes to deploy workloads it’s likely you’ll hit a CPU allocation wall pretty early. To help debug and optimize your limits, the following lists the cpu requests for each pod.

Credit to abelal83 for the solution.

kubectl get po --all-namespaces -o=jsonpath="{range .items[*]}{.metadata.namespace}:{.metadata.name}{'\n'}{range .spec.containers[*]}  {.name}:{.resources.requests.cpu}{'\n'}{end}{'\n'}{end}"

In my usage however I’ve found the need to also see the not only the cpu requests but memory requests as well as cpu/mem limits. To do so I’ve tweaked the above to be the following

kubectl get po --all-namespaces -o=jsonpath="{range .items[*]}{.metadata.namespace}:{.metadata.name}{'\n'}{range .spec.containers[*]}  {.name}:{'limits.cpu'}:{.resources.limits.cpu}{'\n'}  {.name}:{'limits.memory'}:{.resources.limits.memory}{'\n'}  {.name}:{'requests.cpu'}:{.resources.requests.cpu}{'\n'}  {.name}:{'requests.memory'}:{.resources.requests.memory}{'\n'}{end}{'\n'}{end}"

the output of of the above looks like

...
ingress-nginx:nginx-ingress-ingress-nginx-controller-78cd6f9c66-lw9kk
  controller:limits.cpu:
  controller:limits.memory:
  controller:requests.cpu:100m
  controller:requests.memory:90Mi
...
vpscritic:vpscritic-staging-54f6dd9c76-hpl5k
  vpscritic-staging:limits.cpu:500m
  vpscritic-staging:limits.memory:512Mi
  vpscritic-staging:requests.cpu:100m
  vpscritic-staging:requests.memory:128Mi
...

You may also like...

Leave a Reply