Requests and limits are the most consequential numbers in a Kubernetes manifest. Too low and pods are throttled or killed; too high and the cluster is full of reserved but idle capacity. Both are common, and both are fixable with measurement.
What each setting does
| Setting | CPU | Memory |
|---|---|---|
| Request | Reserved for scheduling; also the pod's share under contention | Reserved for scheduling |
| Limit | Hard cap; above it the container is throttled | Hard cap; above it the container is OOMKilled |
CPU is compressible: a container over its limit runs slower. Memory is not: a container over its limit is killed. That asymmetry drives most of the advice below.
QoS classes
Kubernetes assigns each pod a quality-of-service class from its settings:
- Guaranteed: every container has requests equal to limits for CPU and memory. Last to be evicted.
- Burstable: requests set, limits higher or missing. Evicted after BestEffort under node pressure.
- BestEffort: no requests or limits. First to be evicted.
Production services should be Guaranteed or Burstable, never BestEffort.
A sizing method
- Measure: collect CPU and memory usage per container for a week, including peak traffic.
- Memory request: around the p95 of steady usage.
- Memory limit: the peak plus headroom (often 20 to 50%). Never set it close to normal usage; see OOMKilled.
- CPU request: around typical usage under normal load, so the scheduler places pods realistically.
- CPU limit: either a generous cap or none. Many teams omit CPU limits for latency-sensitive services, because throttling causes latency spikes even when the node has idle CPU; others keep limits for fairness. Decide deliberately.
- Revisit monthly or after major changes.
Throttling: the hidden latency
A container with a 500m CPU limit can use half a core per scheduling period. A burst of work that would take 100 ms on a full core is spread over several periods, and p99 latency jumps. Check throttling with the container's cpu.stat (nr_throttled, throttled_usec) or the throttling metrics your agent exposes. If latency spikes line up with throttling, raise or remove the CPU limit.
Runtimes must know their limits
- Java: use
-XX:MaxRAMPercentageso the heap fits the limit; see Java memory usage. - Node.js: set
--max-old-space-sizebelow the limit. - Go: set
GOMEMLIMITto help the GC stay under the limit. - Python: size worker counts to the memory available.
Common mistakes
- No requests at all: pods pile onto the same node and fight.
- Limits equal to typical usage: every spike is an OOM kill.
- Copy-pasted values from another service.
- Measuring CPU against the node: a pod at 90% of its limit is hot even if the node is idle.
- Forgetting sidecars: their requests and limits count too.
Autoscaling depends on requests
The Horizontal Pod Autoscaler's CPU target is a percentage of the request. A request set far too high makes the HPA scale late; too low and it scales constantly. See HPA autoscaling.
Monitoring requests and limits
Chart usage as a percentage of limits per pod, alert when memory stays above 90% of its limit, and track throttling and restarts. VitalRix infrastructure monitoring shows CPU and memory as a share of each instance's limit, and alert rules watch each pod separately so one hot replica is not averaged away. More in Kubernetes monitoring.
A worked example
An API service had requests: 100m CPU, 256Mi and limits: 500m, 300Mi, copied from a template. Under normal load it used 350m CPU and 270Mi memory. Two problems followed: the scheduler packed eight of these pods on one node because each "needed" only 100m, so they fought for CPU, and memory spikes during report generation exceeded 300Mi, causing OOM kills twice a day. Measured values led to requests: 400m, 400Mi, limits: memory 600Mi and no CPU limit. Restarts stopped, p99 latency fell, and the cluster autoscaler added one node, which cost less than the incidents had.
LimitRanges and ResourceQuotas
Cluster administrators can set default requests and limits per namespace with a LimitRange, so pods without explicit values do not become BestEffort, and cap total usage per namespace with a ResourceQuota. Defaults are a safety net; each service should still be sized from its own measurements.
Vertical Pod Autoscaler
The VPA can recommend, or automatically set, requests based on observed usage. Running it in recommendation-only mode is a low-risk way to get sizing suggestions for every workload.
Should I set CPU limits?
It depends. Limits guarantee fairness but can cause throttling and latency spikes. Many teams set CPU requests and omit or loosen CPU limits for latency-sensitive services.
Should memory request equal memory limit?
For predictable memory use and Guaranteed QoS, often yes. Otherwise set the limit above the request with headroom for peaks.
How do I know my limits are too low?
OOMKilled restarts for memory, and CPU throttling metrics that line up with latency spikes for CPU.
Try VitalRix free
Uptime monitoring, APM, logs, real user monitoring and status pages in one place. No credit card needed.