1

Is there a way query cpu request and limit with kubectl for each container in a kubernetes context / namespace, just as I can query cpu usage with kubectl top pods.

morfys
  • 2,195
  • 3
  • 28
  • 35

1 Answers1

4

Requests and limits are the mechanisms Kubernetes uses to control resources such as CPU and memory. Requests are what the container is guaranteed to get. If a container requests a resource, Kubernetes will only schedule it on a node that can give it that resource. Limits, on the other hand, make sure a container never goes above a certain value. The container is only allowed to go up to the limit, and then it is restricted.Limit can never be lower than the request.

As said by @chris, try the following commands for cpu requests and limits for kubernetes namespaces

You can get the pods and their CPU requests with the following command.

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

You can get the pods and their CPU Limits with the following command.

kubectl get pods --all-namespaces  -o=jsonpath="{range .items[*]}{.metadata.namespace}:{.metadata.name}{'\n'}{range .spec.containers[*]} {.name}:{.resources.limits.cpu}{'\n'}{end}{'\n'}{end}"
Srividya
  • 1,678
  • 3
  • 10