Requests, Limits, QoS & OOMKilled
How Kubernetes CPU/memory requests and limits shape QoS classes, CPU throttling vs OOMKilled (exit 137), plus a fictional training postmortem example.
TL;DR
Requests reserve capacity for scheduling; limits cap usage via Linux cgroups. Going over CPU limits throttles your app silently; going over memory limits triggers OOMKilled (exit 137). Together, requests and limits determine your Pod's QoS class (Guaranteed, Burstable, or BestEffort).
Why it exists
Without resource boundaries, one memory-leaking Pod can starve every other Pod on the same node, causing node-wide kernel OOM kills and cascading evictions. Requests let kube-scheduler bin-pack Pods safely; limits isolate noisy neighbors.
Mental model
1. Compressible (CPU) vs Incompressible (Memory)
- CPU (
requests.cpu/limits.cpu): Compressible. If a container hitslimits.cpu, the Linux CFS quota throttles it until the next 100 ms period—requests get slower, but the Pod is not killed. - Memory (
requests.memory/limits.memory): Incompressible. If a container exceedslimits.memory, the kernel OOM killer terminates it withSIGKILL(OOMKilled, exit137).
2. QoS classes
| QoS Class | Condition | Eviction priority under node pressure |
|---|---|---|
Guaranteed | Every container sets requests == limits for both CPU and memory | Evicted last |
Burstable | At least one container sets a request or limit, but not Guaranteed | Evicted second |
BestEffort | Zero CPU/memory requests or limits anywhere in the Pod | Evicted first |
Do it
Set realistic memory requests == limits (to avoid surprise node-pressure OOMs) and inspect OOM events with kubectl describe pod:
# Partial Pod container spec (not run against a cluster)
resources:
requests:
cpu: "250m"
memory: "512Mi"
limits:
memory: "512Mi"
# Many teams omit limits.cpu (or set it generously) to avoid CFS throttling spikes# Check if a Pod was OOMKilled (not run)
kubectl describe pod web-7d9f8c-abc12 | grep -A5 "Last State"Postmortem example (fictional training scenario)
Note: The incident below is a fictional training scenario written to illustrate the
kind: postmortemstructure—it is not a real outage of this site.
- Incident:
api-reportsPods enteredCrashLoopBackOffwithReason: OOMKilled(Exit Code: 137) every Monday at 09:00 UTC. - Root cause: A weekly CSV export loaded the entire query result into memory (
~680 MiBpeak) inside a container withlimits.memory: 512Mi. - Detection & mitigation:
kubeletemittedOOMKilled; on-call rolled back/bumpedlimits.memoryto1Gitemporarily to restore service. - Permanent fix: Streamed the SQL cursor directly to the HTTP response (constant ~40 MiB memory) and added a memory saturation alert at 80% of
limits.memory.
When you DON'T need this
- Static sites and serverless isolates (like this site): Cloudflare Workers / static asset hosting enforces fixed per-isolate memory caps in the platform—there are no Kubernetes
requests,limits, or QoS classes to tune. - Single-tenant dev clusters: On a local
kindorminikubecluster with plenty of RAM, omit strictlimits.cpuso builds and dev servers aren't artificially throttled. - Cost / complexity trade-off: Over-sized
requestswaste cloud money on idle node CPU/RAM; under-sizedlimits.memorycauseOOMKilledcrashes. Use vertical/historical metrics (VPA recommendations or 7-day p99 memory usage) to right-size requests rather than guessing.
Gotchas
- Exit code
137isn't always OOMKilled:137meansSIGKILL(128 + 9), which happens on bothOOMKilledandterminationGracePeriodSecondstimeout. Always checkLast State: Terminated (Reason: OOMKilled)inkubectl describe pod. - Node.js / JVM ignoring cgroup limits (older runtimes): Always ensure your runtime respects container cgroup memory limits (modern Node 22+ and JVM 17+/21+ do; set
--max-old-space-sizeexplicitly if needed so Node GCs before hitting the hard cgroup limit). - Tight
limits.cpucausing mysterious p99 latency spikes: Even when node CPU is 70% idle, a strictlimits.cpu: 200mthrottles bursty startup or JSON parsing.
Production checklist
- Every production Pod sets
requests.cpuandrequests.memory(noBestEffortworkloads in prod). -
limits.memoryequalsrequests.memory(or is sized within node capacity) so OOMs are predictable. - Alerts watch container memory working-set approaching
limits.memory(e.g., > 85%). - Node.js / JVM heap flags leave headroom below
limits.memoryfor native/off-heap buffers.
Check yourself
Check Yourself
1. A container briefly uses more CPU than its limits.cpu value while the node has plenty of spare CPU. What does Kubernetes do?
2. Which Pod QoS class is evicted FIRST when a Kubernetes node runs out of memory?
Sources
Kubernetes Probes: Liveness, Readiness, Startup
How livenessProbe, readinessProbe, and startupProbe differ, what each failure triggers, and how failing readiness removes a Pod from EndpointSlices.
ConfigMaps and Secrets in Kubernetes
Store non-sensitive config in ConfigMaps, understand why Secrets are only base64 by default, and configure encryption at rest or external secret managers.