How to Right-Size Kubernetes Container CPU and Memory
The single biggest source of wasted Kubernetes spend is over-provisioning pods. Most production clusters have CPU requests set 2–5× higher than actual usage. The fix is mechanical, not strategic: measure real usage, then size from data.
The Right-Sizing Rule of Thumb
- CPU request = P95 of actual CPU usage over a representative period (e.g. 7 days under peak traffic). Don't pad it.
- CPU limit = 2–3× the request, or unset if your app handles throttling gracefully. CPU throttling causes mysterious latency spikes — be conservative.
- Memory request = P95 of actual RSS / working set. Memory is incompressible — if you exceed the limit, the pod is OOMKilled instantly.
- Memory limit = 1.5–2× the request. Tighter than CPU because memory bursts are usually unbounded.
Runtime Multipliers: Why Java Needs 2× the Memory of Go
Runtimes have very different baseline footprints. Sizing recommendations should account for this:
- Rust — 0.4× memory, 0.7× CPU (most efficient)
- Go — 0.5× memory, 0.8× CPU
- Node.js — 1× baseline
- Python — 1.2× both (interpreter overhead)
- .NET — 1.1× CPU, 1.3× memory
- Java / JVM — 1.5× CPU, 2.0× memory (heap + JIT)
Common Mistakes to Avoid
- Setting CPU limits equal to requests — kills burst capacity for legitimate traffic spikes. Use limits at 2–3× request, or omit limits entirely (modern recommendation).
- Sizing from a dev environment — load characteristics differ from prod. Always measure in production or a realistic staging environment.
- Not using HPA — Horizontal Pod Autoscaler scales pod count based on CPU/memory or custom metrics. Combine with right-sized requests for maximum efficiency.
- Ignoring init containers — they reserve resources too. Size them tight.
Translating Sizes to Cluster Cost
Right-sizing typically reduces required node count by 30–50%. Use the Kubernetes Cost Calculator to see what those savings look like in dollars across EKS, GKE, and AKS. For EKS-specific compute pricing including Fargate, see the EKS Pricing Calculator.