No single Kubernetes setting causes more waste and more 3am pages than resource requests and limits. Set them too high and you over-provision nodes; too low and pods get CPU-throttled or OOM-killed.
What each one actually does
- requests: what the scheduler reserves - drives bin-packing and autoscaling
- limits: the hard ceiling - exceed memory and the kernel OOM-kills the container
- CPU over the limit is throttled (slow), memory over the limit is killed (dead)
Set them from measured usage
# 95th percentile memory over the last 7d, per pod
quantile_over_time(0.95, container_memory_working_set_bytes{container="web"}[7d])resources:
requests: { cpu: 100m, memory: 160Mi } # ~measured p95 + headroom
limits: { memory: 256Mi } # memory limit only; avoid CPU limits for latency-sensitive appsA common, defensible pattern: set memory request and limit close together (memory is incompressible), set a CPU request, and skip CPU limits for latency-sensitive services to avoid throttling.
Most clusters are 40-70% over-provisioned. Right-sizing from real data is the fastest cloud saving there is.
Measure, set, and revisit after load changes. Pair it with the HorizontalPodAutoscaler and you get elasticity without paying for peak all month.