Kubernetes Resource Requests & Limits
Advancedv1.0.0
Configure CPU and memory requests and limits for Kubernetes workloads — prevent OOMKilled errors, avoid CPU throttling, optimize cluster utilization, and set up resource quotas.
Content
Overview
Resource requests and limits control how much CPU and memory each container can use. Requests guarantee minimum resources for scheduling. Limits cap maximum usage to prevent noisy neighbors. Misconfigured resources cause OOMKilled errors, CPU throttling, and scheduling failures.
Why This Matters
- -Scheduling — Kubernetes uses requests to decide which node can host a pod
- -Stability — limits prevent runaway containers from consuming all node resources
- -Cost — right-sized requests avoid wasting cluster capacity
- -QoS — request/limit ratios determine eviction priority
Resource Configuration
CPU vs Memory Behavior
| Resource | Over Request | Over Limit |
|---|---|---|
| CPU | Throttled (slowed down) | Throttled |
| Memory | OK if available | OOMKilled (container killed) |
QoS Classes
Namespace Resource Quotas
LimitRange (Default Limits)
Sizing Guide
Best Practices
- -Always set memory requests AND limits (OOMKilled is unrecoverable)
- -Set CPU requests but consider omitting CPU limits (throttling causes latency)
- -Start with requests = observed P95 usage, limits = 2x requests for memory
- -Use LimitRange to set defaults for pods that forget to specify resources
- -Use ResourceQuota to cap total namespace resource consumption
- -Monitor with VPA recommendations before setting final values
Common Mistakes
- -Not setting any resources (BestEffort QoS, first to be evicted)
- -Setting CPU limits too low (causes throttling and latency spikes)
- -Setting memory limits equal to requests (no burst room, frequent OOMKilled)
- -Overcommitting requests (scheduler thinks cluster is full, pods Pending)
FAQ
Discussion
Loading comments...