1. What Kubernetes requests vs limits decide in production

Kubernetes requests vs limits decide four production outcomes: where pods schedule, how CPU is shared under contention, when containers throttle, and when the kernel OOM-kills a process. Requests drive scheduling and sharing; limits drive runtime enforcement, and confusing those roles causes most sizing incidents.

Illustrative composite: a checkout service runs with CPU request 250m and CPU limit 500m, values copied from a tutorial. Node CPU sits at forty percent, yet p99 latency spikes every few minutes and error budgets burn. The on-call engineer adds replicas; latency barely moves. The real cause is CFS throttling: each container exhausts its 500m quota inside busy 100ms periods and waits, throttled, while the node still has idle cores. Raising the limit and right-sizing the request fixes latency without new nodes. That pattern, throttling on an idle node, is the signature failure of Kubernetes requests vs limits set by habit instead of mechanism.

The second signature failure runs the other direction. A worker with memory request 256Mi and no memory limit grows a slow leak, consumes node memory, and triggers kubelet evictions that take down neighbors before the leaker itself dies. Requests without limits surrender the failure boundary; limits without honest requests surrender scheduling accuracy. Production policy needs both fields set deliberately, per resource, because CPU and memory enforce through different physics.

This guide builds that policy from mechanism upward: what each field controls, why CPU and memory need opposite default treatments, how to measure real usage, and how QoS, quotas, autoscaling, and language runtimes interact with the numbers. Where a topic has a dedicated deep dive, the guide links out rather than repeating it, starting with Kubernetes CPU throttling for the throttling mechanics.


2. How Kubernetes requests vs limits map to scheduler and cgroup mechanics

Kubernetes requests vs limits map to different components: the scheduler places pods by requests, the kubelet translates requests into CPU weight and eviction scoring, and cgroup limits enforce CPU quota and memory ceilings. No single component reads both fields the same way.

Four mechanisms read the two fields, and separating them ends most confusion. The CPU request is a scheduling reservation: the scheduler places a pod only on a node whose unreserved CPU covers the sum of requests. At runtime the same request becomes the container's CPU weight, so under contention runnable containers share CPU in proportion to requests. The CPU limit becomes CFS bandwidth control: a quota of CPU time per period, 100ms by default. Spend the quota early in a period and every thread waits for the next period, even on an idle node. That wait is throttling.

Memory splits differently. The memory request guides placement and later feeds kubelet eviction scoring: when node memory runs low, pods using more than their request are evicted first. The memory limit is a hard cgroup ceiling. Exceed it with no reclaimable memory available and the kernel OOM killer terminates the process; the container shows OOMKilled with exit code 137. The scheduler never sees limits, so limits cannot protect placement, and requests cannot stop a runaway process. Each field does one job.

Two defaults surprise teams. Set a limit with no request and Kubernetes copies the limit into the request, unless a LimitRange default intervenes, which can quietly inflate reservations. Set neither and the container is BestEffort: schedulable anywhere, evicted first, throttled by contention with no guaranteed share. Production namespaces should make both defaults impossible through LimitRange defaults and admission checks, covered in the ResourceQuota and LimitRange guardrails guide.


3. Kubernetes requests vs limits: CPU is compressible, memory is not

Kubernetes requests vs limits need opposite defaults because CPU is compressible and memory is not: excess CPU demand throttles and survives, while excess memory demand kills the process. Set memory limits always; treat CPU limits as a deliberate isolation choice, not a default.

Compressibility is the single most consequential idea in resource management. A container that wants more CPU than its limit allows is slowed: the CFS scheduler withholds CPU time until the next period, latency rises, throughput falls, and the process lives. A container that wants more memory than its limit allows is killed: memory cannot be time-shared, the kernel cannot reclaim actively held pages, and the OOM killer picks a victim. Same YAML shape, opposite failure physics. Copying one policy across both resources guarantees one of the two failure modes.

The policy consequence is asymmetric. Memory limits are mandatory in production: every container gets one, sized from measured working set plus headroom, because an unbounded container converts a leak into node-wide eviction damage. CPU limits are situational. A CPU limit protects neighbors from a runaway container and makes multi-tenant sharing predictable, but it also throttles latency-sensitive services on idle nodes and interacts badly with multi-threaded runtimes that burst across cores. Many production platforms set CPU requests carefully and omit CPU limits for latency tiers, relying on requests-based sharing and node capacity planning instead.

Property CPU Memory
Over-limit behavior Throttled, process survives OOMKilled, process dies
Compressible Yes No
Request role Scheduling + contention weight Scheduling + eviction scoring
Limit role CFS quota per period Hard cgroup ceiling
Production default Request always; limit situational Request and limit always

Hold the table in mind for every later section. Sizing method, QoS choice, and runtime flags all reduce to respecting that asymmetry instead of fighting it.


4. Measuring usage for Kubernetes requests vs limits with PromQL and VPA

Kubernetes requests vs limits should come from measured usage over one to two weeks: CPU request near sustained p95, memory request near peak working set plus headroom. Prometheus percentiles and VPA recommendations in Off mode give defensible numbers; kubectl top gives only a snapshot.

Start with history, not guesses. CPU usage is a rate, memory usage is a level, and the queries differ. Over a fourteen-day window covering peaks, deploys, and batch cycles, compute per-container CPU p95 and p99 and memory working-set maximum and p99. Working set excludes reclaimable page cache, which is the right basis for memory sizing; raw RSS overstates need for cache-heavy workloads.

promql
# CPU p95 over 14 days, per container (cores)
quantile_over_time(0.95, rate(container_cpu_usage_seconds_total{namespace="payments",container="api"}[5m])[14d:5m])

# Memory working set p99 over 14 days (bytes)
quantile_over_time(0.99, container_memory_working_set_bytes{namespace="payments",container="api"}[14d:5m])

# Throttling ratio: throttled periods over total periods
sum(rate(container_cpu_cfs_throttled_periods_total{namespace="payments"}[5m])) / sum(rate(container_cpu_cfs_periods_total{namespace="payments"}[5m]))

Cross-check with the Vertical Pod Autoscaler in Off mode, which publishes lower bound, target, and upper bound recommendations without applying them. Agreement between your percentile math and the VPA target builds confidence; disagreement usually means seasonality, a recent deploy changed the profile, or the workload is batch-shaped and percentiles mislead. kubectl top pods --containers remains useful for a live sanity check during an incident, but a snapshot cannot size a request. The PromQL guide for SREs supplies the throttling, memory-pressure, and restart alerts that should guard every sizing change you ship.


5. Setting CPU in Kubernetes requests vs limits: request first, limit by exception

Kubernetes requests vs limits for CPU work best with the request set from sustained usage and the limit omitted or set generously for latency-sensitive services. Tight CPU limits cause throttling on idle nodes; reserve them for batch isolation, multi-tenancy, and proven noisy-neighbor control.

Size the CPU request from sustained demand, not from peaks. A request near p95 of normal load keeps scheduling honest: the scheduler reserves what the pod actually uses, bin-packing stays efficient, and contention sharing reflects real need. Requests far below usage overpack nodes and manufacture noisy-neighbor latency. Requests far above usage strand capacity and leave pods Pending on clusters that look empty by utilization. Both errors come from sizing to a feeling instead of a percentile.

Treat the CPU limit as an isolation tool with a latency price. CFS quota is enforced per period, so a limit of 500m on a container with eight busy threads can throttle hard inside busy periods while average utilization looks modest. Multi-threaded runtimes, garbage-collection pauses, and request bursts all collide with per-period quota in ways averages hide. For latency-sensitive services, omit the CPU limit or set it at several times the request, and control abuse through requests, quotas, and alerts. For batch workers, CI runners, and multi-tenant namespaces where one tenant must not starve others, a CPU limit is the right guardrail and throttling is acceptable backpressure.

When throttling appears, diagnose before resizing. A high throttled-period ratio with low node utilization means the limit is the constraint: raise or remove it. Throttling with high node utilization means real contention: raise the request, add capacity, or scale out. The CPU throttling guide walks the metric-by-metric diagnosis, including the CFS period effects that make small limits throttle disproportionately.

A practical test separates limit throttling from genuine saturation. Raise the CPU limit on one replica while leaving its request unchanged, then compare throttled-period ratio and p99 latency against its siblings under the same traffic. If throttling collapses and latency follows, the limit was the constraint and the fleet-wide fix is a limit change, not more nodes. If nothing moves, contention is real and the request, replica count, or node capacity must change instead. Running the experiment on one replica keeps blast radius small and produces evidence a reviewer can check, which matters because CPU limit removal draws fair questions from capacity owners. Record the before-and-after numbers with the change so the decision survives the next cost review.


6. Setting memory in Kubernetes requests vs limits: limit at the request

Kubernetes requests vs limits for memory work best with request and limit set equal, sized from peak working set plus headroom. Equal values make OOMKills predictable, eviction scoring honest, and node packing safe, while a wide request-limit gap invites eviction surprises under pressure.

Memory policy is simpler and stricter than CPU policy. Set the memory request from peak working set over a representative window, add headroom for deploy overlap and traffic growth, and set the limit equal to the request. Equality buys three properties. The scheduler reserves exactly what the container may use, so node packing math is real. Eviction scoring compares usage against a request the container cannot legitimately exceed, so pressure behavior is predictable. An OOMKill means the workload truly outgrew its allocation, which is a sizing or leak signal rather than an artifact of a loose ceiling.

A wide gap between memory request and limit feels safe and behaves badly. The scheduler packs by request, so ten pods requesting 256Mi with 2Gi limits can land on one node; when several grow toward their limits together, the node runs out of memory and the kubelet evicts by usage-over-request scoring, killing pods that never exceeded their limits. The failure looks random because it is: survival depends on neighbors' growth, not on the victim's behavior. Narrow gaps are acceptable for workloads with rare, brief spikes, but the spike headroom should be measured, not vibes.

Size headroom by workload shape. Stateless services with flat working sets need modest headroom. Caches and data-processing workers need headroom for the largest legitimate dataset, plus runtime overhead outside the heap. Always account for memory the limit must cover beyond the application heap: page cache the process depends on, native allocations, thread stacks, and sidecar containers in the same pod each carry their own requests and limits. When an OOMKill lands, the OOMKilled troubleshooting guide separates a too-low limit from a genuine leak before you raise numbers.

Verify memory sizing with a load-shaped check rather than a deploy-shaped one. Working set during a quiet rollout understates peak demand by a wide margin for services with daily cycles, batch overlap, or cache warm-up effects. Compare the chosen request against the highest working set observed across deploys, traffic peaks, and dependency slowdowns, since slow downstreams inflate in-flight request memory. Services that buffer responses or hold connection pools grow memory precisely when the system is stressed, which is when an undersized limit converts stress into restarts. Headroom sized from calm-period data fails exactly when it is needed.


7. QoS classes in Kubernetes requests vs limits: Guaranteed, Burstable, BestEffort

Kubernetes requests vs limits determine QoS class: Guaranteed when every container sets requests equal to limits for CPU and memory, Burstable when any request is set without full equality, BestEffort when nothing is set. QoS drives eviction order and CPU sharing under pressure.

QoS class is computed from the request-limit relationship across every container in the pod, init containers included. Guaranteed requires requests equal to limits for both CPU and memory on all containers. Burstable covers everything with at least one request set but without full equality, which is where most production services live. BestEffort means no requests or limits anywhere, a class that should not exist in production namespaces. The class is assigned at creation and, as the in-place resize rules reinforce, it does not drift afterward.

Under node memory pressure, the kubelet evicts BestEffort first, then Burstable pods using more than their requests, then Guaranteed last. Under CPU contention, requests act as weights, so Guaranteed and Burstable pods receive shares proportional to requests while BestEffort pods get leftovers. QoS is therefore a survival contract: Guaranteed pods trade burst flexibility for protection, Burstable pods trade protection for elasticity, and the request values inside Burstable decide who suffers first.

Choose per tier. Databases, control-plane components, and latency-critical singletons earn Guaranteed with memory request equal to limit and CPU request equal to limit, accepting no burst above allocation. Stateless APIs usually run Burstable with memory request equal to limit and no CPU limit, which keeps memory behavior Guaranteed-like while allowing CPU bursts. Batch and best-effort analytics run Burstable with low requests and firm limits, absorbing eviction and throttling as backpressure. The QoS classes and eviction order guide gives the full eviction ranking and OOM score mechanics behind these choices.


8. Runtime alignment for Kubernetes requests vs limits: JVM, Go, and Node.js

Kubernetes requests vs limits only work when language runtimes agree with them: JVM heap flags, Go memory limits, and Node.js old-space settings must derive from the container limit. A runtime sized for the node instead of the cgroup will OOMKill or underuse memory regardless of YAML.

Containers report cgroup limits to runtimes inconsistently, and each major runtime needs explicit alignment. The JVM historically sized heap from host memory; modern JVMs respect container limits with -XX:MaxRAMPercentage, but explicit -Xmx overrides everything and must stay below the memory limit with room for metaspace, thread stacks, direct buffers, and GC overhead. A pod with a 1Gi limit and -Xmx1g is an OOMKill waiting for load. Size heap at roughly seventy to eighty percent of the limit and verify with native memory tracking when kills persist.

Go programs benefit from GOMEMLIMIT, which the runtime can derive from the cgroup limit when set through the automaxprocs and automemlimit patterns or explicit environment. Without it, Go's garbage collector targets heap growth relative to live heap and can exceed tight limits during allocation bursts, producing OOMKills at usage levels that look safe on average graphs. Node.js fixes old-space size with --max-old-space-size; leave it unset on a small container and Node assumes gigabytes of heap, growing into the cgroup ceiling. Set it to roughly seventy-five percent of the memory limit.

CPU alignment matters too. Runtimes that size thread pools from visible CPUs can oversubscribe a small CPU limit, creating thread contention that looks like application slowness. Go's GOMAXPROCS now respects CPU quota in recent versions; JVMs and Node thread pools may need explicit sizing on tightly limited containers. The checklist is mechanical: for every container, confirm heap settings derive from the memory limit, thread pools respect the CPU allocation, and both survive a limit change without a code edit.


9. Autoscaling interplay in Kubernetes requests vs limits: HPA, VPA, and quotas

Kubernetes requests vs limits interact with autoscaling because HPA utilization is computed against requests and VPA rewrites requests from usage. Wrong requests distort both signals, so fix sizing before tuning autoscalers, and bound namespaces with ResourceQuota and LimitRange guardrails in production namespaces today.

The Horizontal Pod Autoscaler expresses CPU utilization as usage divided by request. Inflate requests and utilization reads low, so HPA scales late or never; deflate requests and HPA scales on noise. Memory-based HPA inherits the same distortion. This is why sizing comes before autoscaler tuning: an HPA target of seventy percent means seventy percent of whatever request you declared, and a dishonest request makes the target meaningless. The HPA v2 tutorial covers scaling behavior once requests are honest.

The Vertical Pod Autoscaler closes the loop from the other side, recommending requests from observed usage. Running VPA and HPA on the same CPU or memory signal fights: VPA raises requests while HPA adds replicas for the same pressure. Standard practice pairs VPA recommendations, applied manually or through in-place updates, with HPA on custom or external metrics, or uses VPA in Off mode as a sizing oracle. Namespace guardrails keep both honest: ResourceQuota caps total requests and limits per namespace, and LimitRange sets default requests, default limits, and min-max bounds so no container ships undeclared. The ResourceQuota and LimitRange guide details those controls, and HPA vs VPA helps choose which autoscaler owns which signal.

Sequence the rollout of new values like a release, not a config edit. Change requests and limits on one canary replica or a small deployment slice first, watch throttling ratio, working set, restart counts, and HPA behavior across a traffic peak, then expand. Request changes alter scheduling for new pods immediately and HPA utilization math as soon as pods restart, so a fleet-wide change can shift replica counts in ways that look like autoscaler bugs. Staged changes keep cause and effect readable. They also protect quota headroom: raising requests across a namespace consumes ResourceQuota, and discovering the ceiling mid-rollout leaves half the fleet on old values.


10. Worked examples: Kubernetes requests vs limits by workload class

Kubernetes requests vs limits differ by workload class: latency APIs run Burstable with memory limit at request and no CPU limit, databases run Guaranteed, and batch workers run low requests with firm limits. Copy the pattern per class, then replace every number with measured values.

Three patterns cover most production tiers. Numbers below are starting shapes, not recommendations; replace each with your percentile measurements.

Latency-sensitive API, Burstable, CPU burst allowed, memory pinned:

yaml
resources:
  requests:
    cpu: 500m
    memory: 512Mi
  limits:
    memory: 512Mi

Database or stateful singleton, Guaranteed, no burst, protected under pressure:

yaml
resources:
  requests:
    cpu: "2"
    memory: 4Gi
  limits:
    cpu: "2"
    memory: 4Gi

Batch worker, Burstable, low reservation, hard ceiling as backpressure:

yaml
resources:
  requests:
    cpu: 250m
    memory: 256Mi
  limits:
    cpu: "1"
    memory: 1Gi

Read the patterns as contracts. The API contract says: schedule me at half a core, let me burst CPU when the node allows, and kill me predictably if I exceed half a gigabyte. The database contract says: reserve exactly this, never throttle or evict me for a neighbor's growth, and never let me burst into unreserved capacity. The batch contract says: pack me densely, cap me firmly, and treat throttling and eviction as acceptable queueing. Choosing the contract first makes the numbers a measurement exercise instead of a negotiation.

Treat the worked patterns as review templates. A manifest review that asks which contract a workload runs, protected, burstable, or batch, catches sizing errors that numeric review misses. A batch worker declared Guaranteed wastes reserved capacity; a database declared Burstable with a wide memory gap invites eviction during the incident it most needs to survive. Naming the contract in the pull request description, with the percentile window behind the numbers, turns sizing into an auditable decision. Over time the namespace converges on three or four contracts with measured parameters, and new services inherit a pattern instead of inventing numbers.


11. Troubleshooting Kubernetes requests vs limits failures

Kubernetes requests vs limits troubleshooting matches symptom to mechanism: throttling on idle nodes means CPU limits, OOMKills mean memory ceilings or leaks, Pending pods mean requests exceed schedulable capacity, and evictions mean requests understate real usage. Check the mechanism before changing numbers.

Work the matrix by symptom. Each row names the mechanism, the confirming check, and the fix, in the order incidents usually present.

Symptom Mechanism Confirm with Fix
Latency spikes, node CPU idle CPU limit throttling Throttled-period ratio Raise or remove CPU limit
Latency under load, node saturated Requests understate demand Usage vs request percentiles Raise CPU request, add capacity or replicas
OOMKilled, exit 137 Memory limit reached Working set vs limit, leak check Raise limit and request together or fix leak
Evictions under memory pressure Usage exceeds requests Eviction events, usage-over-request Raise memory requests; narrow limit gaps
Pods Pending, cluster looks empty Requests exceed allocatable Scheduler events, node allocatable Lower inflated requests or add nodes
HPA never scales Inflated requests deflate utilization Usage divided by request Right-size requests, then retune HPA
One tenant starves others Missing limits and quotas Per-namespace usage vs quota Add CPU limits, ResourceQuota, LimitRange
JVM OOMKilled below heap size Native memory outside heap Native memory tracking Lower MaxRAMPercentage, raise limit headroom

Two habits keep troubleshooting honest. Change one variable at a time and watch the mechanism metric, throttling ratio for CPU changes and working set for memory changes, across a full traffic cycle. Record before-and-after percentiles with the change, so the next engineer inherits evidence instead of folklore. Raising every number at once feels decisive and teaches nothing; the next incident starts from zero.


12. Production checklist for Kubernetes requests vs limits

Kubernetes requests vs limits are production-ready when every container declares measured requests, memory limits equal requests by default, CPU limits exist only with a stated isolation reason, runtimes derive heap from limits, and namespaces enforce defaults through LimitRange and ResourceQuota.

Ship sizing changes against this checklist:

  • Every container, including sidecars and init containers, declares CPU and memory requests from fourteen days of percentile data.
  • Memory limit equals memory request unless a measured spike pattern justifies a narrow gap, documented in the manifest review.
  • CPU limits exist only with a written isolation reason: batch backpressure, multi-tenancy, or proven noisy-neighbor control.
  • QoS class is chosen per tier on purpose: Guaranteed for protected stateful work, Burstable with pinned memory for APIs, firm limits for batch.
  • JVM, Go, and Node.js heap and thread settings derive from container limits and survive limit changes without code edits.
  • LimitRange sets default requests and limits plus min-max bounds; ResourceQuota caps namespace totals; admission rejects undeclared containers.
  • HPA targets are reviewed after any request change, because utilization is computed against requests.
  • VPA runs in Off mode as a sizing oracle, or in-place updates are bounded with min and max allowed values.
  • Throttling ratio, OOMKill, and eviction alerts guard every sizing change across one full traffic cycle.
  • Before-and-after percentiles are recorded with each change, and rightsizing is reviewed monthly against cost using Kubernetes cost optimization with OpenCost.

Requests and limits look like two small YAML fields and behave like a scheduling contract, a sharing policy, and a failure boundary at once. Teams that size from mechanism and measurement get predictable latency, honest packing, and OOMKills that mean something. Teams that copy numbers inherit throttling on idle nodes and evictions that look random, and pay for both in incident time.

Frequently Asked Questions

What is the difference in Kubernetes requests vs limits?

Requests reserve resources for scheduling and contention sharing: the scheduler places pods by requests, CPU requests become sharing weights, and memory requests feed eviction scoring. Limits enforce runtime ceilings through cgroups: CPU limits throttle through CFS quota, and memory limits OOMKill processes that exceed them.

In Kubernetes requests vs limits, should I set CPU limits in production?

Set CPU requests always, from sustained usage percentiles. Set CPU limits only with an isolation reason, such as batch backpressure or multi-tenant fairness. For latency-sensitive services, omit the CPU limit or set it well above the request, because tight limits throttle containers even on idle nodes.

In Kubernetes requests vs limits, should memory request equal memory limit?

Yes, as the production default. Equal values make scheduling honest, eviction behavior predictable, and OOMKills meaningful signals of true overgrowth. Allow a narrow gap only for measured spike patterns, since wide gaps let pods pack by request and then evict each other under pressure.

Why is my pod throttled when the node has free CPU?

The CPU limit is the constraint, not the node. CFS quota grants CPU time per 100ms period; a container that spends its quota early waits for the next period regardless of idle cores. Check the throttled-period ratio, then raise or remove the CPU limit.

How do I size Kubernetes requests vs limits from Prometheus?

Collect fourteen days of per-container usage. Set CPU request near p95 of sustained rate, memory request near peak working set plus headroom, and memory limit equal to the request. Cross-check with VPA recommendations in Off mode, then watch throttling and OOM signals after shipping.

How do Kubernetes requests vs limits affect QoS and eviction?

Requests equal to limits for CPU and memory on every container gives Guaranteed QoS, evicted last. Any request set without full equality gives Burstable, evicted by usage over request. No requests or limits gives BestEffort, evicted first. Choose QoS per tier deliberately.

Why does my JVM get OOMKilled below its heap size?

The memory limit covers more than heap: metaspace, thread stacks, direct buffers, code cache, and GC overhead all count. A heap sized at the full limit leaves no room for native memory. Set MaxRAMPercentage near seventy percent and verify with native memory tracking.

⚡ KUBERNETES SCENARIO INTERVIEW PREP

Preparing for Senior Platform & SRE Interviews

Practice real-world cluster triage, RBAC debugging, and pod scheduling scenarios in our Kubernetes scenario interview questions hub.

Explore Interview Scenarios →