How do CPU/Memory Requests, Limits, and HorizontalPodAutoscaler (HPA) work together?
Quick Summary: Requests reserve guaranteed node capacity used by the kube-scheduler and HPA utilization math, whereas Limits enforce hard ceilings (CPU throttles cleanly via CFS, while exceeding Memory limit triggers an immediate OOMKilled termination).
Direct Interview Answer
resources.requests informs the Kubernetes scheduler which worker node has enough available capacity to place a Pod, and acts as the denominator for HPA CPU percentage scaling.
resources.limits caps burst usage: CPU excess is throttled in Linux cgroups (raising latency), while Memory excess triggers the kernel OOM killer (OOMKilled / exit code 137).
Detailed Technical Explanation
Always align JVM -XX:MaxRAMPercentage or Node --max-old-space-size safely around 70–75% of the container Memory Limit so runtimes perform GC before Linux kills the container abruptly.
Practical Walkthrough
Pod container sizing with matching Guaranteed/Burstable resources for HPA scaling.
resources:
requests:
cpu: "250m"
memory: "512Mi"
limits:
cpu: "1000m"
memory: "768Mi"
Scheduler guarantees 250m CPU & 512Mi RAM; HPA scales replicas cleanly against 250m baseline.
Real-World Production Use Case
Preventing noisy-neighbor node exhaustion and unexpected OOMKilled crashes during flash-sale traffic spikes.
Common Interview Mistakes to Avoid
- Forgetting resource requests entirely, causing HPA to fail metric calculations ("missing request for cpu").
- Setting tight CPU limits without monitoring CFS throttling latencies.