Skip to main content
Running workloadsLesson 2 of 14

Requests and limits

Each container declares resources as two values: "I need at least this much" (requests) and "I can never use more than this" (limits). Here we follow how each value is used at placement time and at run time. The detailed way the scheduler filters and picks nodes is in Which Node Gets the Pod (Scheduling).

CPU allocated (example)—
web CPU / limit250m requested
web memory / limit256Mi requested
web statusnone
worker-2Pod specrequests·limitsScheduleruses request totalskubeletenforces limitswebBurstablepayGuaranteedtempBestEffortplace me
RequestAppears in a later step

What you will learn

  • Requests are a reservation; limits are a hard line
  • The scheduler looks at request totals, not usage
  • Hitting the CPU limit slows you down; hitting the memory limit kills you
  • What happens with empty requests, and QoS classes

Myths and facts​

MythFact
Low usage means there is room for a podThe scheduler only looks at request totals. When allocation is full, it is Pending regardless of usage
Going over the limit kills the container, CPU or memoryCPU is only slowed (throttling); only memory is killed (OOMKilled)
Requests can be left emptyPlacement goes wrong, creation is rejected in namespaces with quotas, and the HPA cannot compute utilization
HPA CPU 80% means 80% of the limitIt is measured against requests
Generous requests are saferPods fail to place even with room, and resources are wasted

Try it yourself​

kubectl get pod <pod> -o jsonpath='{.spec.containers[*].resources}' # Requests and limits
kubectl get pod <pod> -o jsonpath='{.status.qosClass}' # QoS class (eviction order)
kubectl top pod # Actual usage (needs metrics-server)
kubectl describe node <node> | grep -A 8 'Allocated resources' # Request totals on the node
kubectl get pod <pod> -o jsonpath='{.status.containerStatuses[*].lastState.terminated.reason}' # OOMKilled?

Check yourself

  1. The node's CPU usage graph looks idle, yet a new pod stays Pending. What is most likely?
  2. A container keeps trying to use more than its limit. Which outcome matches the lesson?
  3. Node memory runs short. Which pod does the kubelet evict first?

Further reading: Resource management for Pods and containers · Kubernetes scheduler · Configure Quality of Service for Pods · Which Node Gets the Pod (Scheduling)