Requests, limits, QoS classes, and eviction

Requests are for scheduling, limits are for enforcement. A CPU limit throttles in 100 ms windows; a memory limit kills. Guaranteed, Burstable and BestEffort decide who gets evicted first.

Read the briefing
About 8 min to read 8 drills

What to remember

  1. Requests schedule, limits enforce. Half of Kubernetes resource confusion disappears once this is automatic.
  2. CPU limits throttle, memory limits kill. Throttling shows as latency with idle CPU; a memory limit shows as exit 137.
  3. QoS class comes from requests versus limits. Equal = Guaranteed, some = Burstable, none = BestEffort — and that order is the eviction order.
  4. Eviction ranks usage over requests. Honest requests are what protect you when a node runs short, not a low limit.
  5. A default CPU limit from a LimitRange can throttle everything. Default requests always; default memory limits usually; default CPU limits almost never.

The big picture

Requests and limits are the two numbers that decide where a pod lands and what happens when it uses more than it asked for. Requests are a scheduling promise counted against node allocatable; limits are a runtime ceiling the kubelet writes into cgroups; the QoS class derived from the pair decides whom the kubelet evicts when the node itself runs short. Interviewers probe this because most p99 latency mysteries (CFS throttling), most OOMKills, and most "the cluster is full but idle" complaints trace back to these settings.

The mental model

Two ledgers and a tiebreaker. The scheduler's ledger counts requests against allocatable and never looks at usage. The kernel's ledger enforces limits per container through cgroups: CPU over the limit is paused until the next 100 ms period, memory over the limit is killed. QoS is the tiebreaker read off those two ledgers: when the node is short, the kubelet reclaims from whoever is furthest over what they asked for, BestEffort first, Guaranteed last.

In depth

Requests and limits are enforced by different components

A request is consumed once, at scheduling: kube-scheduler sums the requests of every pod already bound to a node and refuses a pod whose request would push the total past allocatable (capacity minus kube-reserved, system-reserved and the hard eviction threshold). After binding, a memory request enforces nothing; a CPU request becomes the cgroup's cpu.weight (cpu.shares on cgroup v1), which only matters when the node is contended and then gives each container CPU time in proportion to its request. That is the one runtime meaning of a request, and it is why "requests-only CPU" is still fair.

A limit is enforced continuously by the kubelet through the container's cgroup: cpu.max (a quota per 100 ms period) for CPU and memory.max for memory. Exceed the CPU quota and the container is throttled until the period ends; exceed the memory limit and the kernel OOM killer ends the container with exit code 137 and Reason: OOMKilled. The two knobs are independent: a pod with requests and no limits may burst into whatever is free, and a pod that specifies only limits gets requests defaulted equal to those limits, which silently makes it Guaranteed and expensive to schedule.

What to look at: kubectl describe node <node> shows Allocatable and an Allocated resources table of requests and limits as percentages; kubectl get pod <p> -o jsonpath='{.status.qosClass}' shows the derived class; inside a container cat /sys/fs/cgroup/cpu.max and memory.max show what the kubelet actually wrote. The interview tell is a candidate who says "limit" when the question is about scheduling.

CPU limits and CFS throttling

CPU is compressible, so a CPU limit never kills anything; it makes the container wait. The CFS bandwidth controller grants quota microseconds of CPU per period (100 ms by default): limits.cpu: 500m becomes cpu.max = 50000 100000, meaning 50 ms of CPU time per 100 ms window across all threads. A service with eight worker threads can spend that 50 ms in about 6 ms of wall time and then sit frozen for the remaining 94 ms. Average utilization reads 40%; p99 latency spikes by roughly one period. This is the classic "low CPU, high tail latency" signature, and it is worse for runtimes that size thread pools from the node's core count rather than the cgroup (Go's default GOMAXPROCS, JVM pools, Node cluster mode).

Measure it before you touch anything: the ratio rate(container_cpu_cfs_throttled_periods_total[5m]) / rate(container_cpu_cfs_periods_total[5m]) above a few percent means the limit is actively shaping latency; container_cpu_cfs_throttled_seconds_total gives the time lost. On the node, cpu.stat in the container's cgroup shows nr_throttled and throttled_usec.

The fixes, in order of preference for latency-sensitive tiers: raise or remove the CPU limit while keeping an honest request (fairness under contention still comes from cpu.weight); make the runtime cgroup-aware (automaxprocs, -XX:ActiveProcessorCount) so it stops over-subscribing its own quota; or, for workloads that need exclusive cores, make the pod Guaranteed with an integer CPU request and enable the kubelet's static CPU manager policy. Keep CPU limits on batch and on tenants you do not trust, where a bounded share matters more than tail latency.

Memory: the container's own limit versus node-pressure eviction

Two different killers produce two different statuses, and confusing them sends you to the wrong fix.

OOMKilled is the memory cgroup enforcing this container's memory.max. The kernel picks a process inside the cgroup (normally the main process), the container exits with code 137 (128 + SIGKILL) and Last State: Terminated, Reason: OOMKilled, and the kubelet restarts it in place according to restartPolicy. The pod stays on the node, and the node may have gigabytes free. The fix is a limit set from the observed working set (container_memory_working_set_bytes), or finding the leak.

Evicted is the kubelet protecting the node. It watches memory.available against the eviction thresholds (--eviction-hard defaults to memory.available<100Mi, plus soft thresholds with a grace period), sets the MemoryPressure condition and the node.kubernetes.io/memory-pressure:NoSchedule taint, and evicts pods ranked by three keys: whether usage exceeds requests, then pod priority, then how far usage exceeds requests. BestEffort pods have no requests so they are always "over" and go first; Burstable pods above their request go next; Guaranteed pods (never over their request, since request equals limit) go last. The evicted pod's phase becomes Failed with Reason: Evicted and a message naming the threshold; its controller creates a replacement elsewhere, while a bare pod simply stays dead.

The kernel gets a vote too: the kubelet sets each container's oom_score_adj from its QoS (Guaranteed -997, BestEffort 1000, Burstable scaled by request as a share of node memory), so if the node OOMs before the kubelet reacts, the kernel still prefers to kill the same pods the kubelet would have evicted. Check kubectl describe node <node> under Conditions and kubectl get events --field-selector reason=Evicted.

QoS classes are derived, not declared

You never set a QoS class; the API server computes it from the containers' requests and limits and writes it to status.qosClass. Guaranteed: every container has CPU and memory limits, and each request equals its limit (specifying only limits qualifies, because requests default to them). Burstable: at least one container has a CPU or memory request or limit, but the pod does not meet the Guaranteed rule. BestEffort: no requests or limits anywhere in the pod. A single sidecar without resources turns a carefully specified pod into Burstable, which is the most common surprise when people finally check qosClass.

The class changes three things and nothing else: node-pressure eviction order, the kernel oom_score_adj, and eligibility for exclusive CPUs under the static CPU manager policy (Guaranteed pods with integer CPU requests). It does not change scheduling, which uses requests regardless of class, and it does not exempt a container from its own limits: a Guaranteed container that exceeds memory.max is OOMKilled exactly like any other.

Choosing a class is choosing a tradeoff. Guaranteed buys predictability at the cost of headroom you cannot share, because request equals limit. Burstable with a memory limit and no CPU limit is the workhorse pattern for latency-sensitive services: honest requests for placement and fairness, a hard memory ceiling so one leak cannot take out the node, and no CFS clipping. BestEffort is acceptable only for work you are happy to lose first, and a LimitRange in the namespace should make it impossible by accident.

Units, LimitRange and ResourceQuota

CPU is expressed in cores or millicores: 1, 0.5 and 500m are all valid and 1000m equals 1. Memory is bytes with either decimal (K, M, G) or binary (Ki, Mi, Gi) suffixes, and the two are not the same: 1G is 1,000,000,000 bytes, 1Gi is 1,073,741,824. A lowercase m on memory is the SI milli prefix, so memory: 512m requests 0.512 bytes, parses without complaint, schedules anywhere and buys nothing. The API does reject one class of mistake at admission: a limit lower than the request for the same resource (must be less than or equal to cpu limit).

LimitRange is a per-namespace admission object: defaultRequest and default fill in requests and limits for containers that omit them, min and max bound what may be asked, and maxLimitRequestRatio caps how bursty a container may be. It is applied when the pod is created, so changing it does not touch running pods. ResourceQuota caps the namespace's aggregate: requests.cpu, requests.memory, limits.memory, object counts and more. Once a quota names a compute resource, every pod in the namespace must specify it or be rejected with must specify limits.memory, which is why a LimitRange with defaults always accompanies a quota. kubectl describe quota -n <ns> shows Used against Hard.

Finally, know which tool shows which number: kubectl top pod and kubectl top node show usage from metrics-server; kubectl describe node shows requests and limits; the Vertical Pod Autoscaler in recommendation mode turns usage history into request suggestions. "The node is at 30%" means nothing until you say which of the two you measured.

Myths and facts

Myth: The scheduler places pods using their limits.

Fact: Placement uses requests against allocatable. Limits are written into cgroups by the kubelet and never enter the scheduling decision.

Myth: A CPU limit is free protection for the other pods on the node.

Fact: Fair sharing under contention already comes from cpu.weight derived from requests. A limit adds CFS throttling, which stalls a bursty process every 100 ms period even when the node is idle.

Myth: OOMKilled means the node ran out of memory.

Fact: OOMKilled is the container exceeding its own memory limit; the node may have plenty free. A node running short shows MemoryPressure and pods with Reason: Evicted.

Myth: Guaranteed pods cannot be OOMKilled.

Fact: Guaranteed only protects against node-pressure eviction order. A Guaranteed container that exceeds memory.max is killed like any other.

Myth: memory: 512m means 512 megabytes.

Fact: Lowercase m is the SI milli prefix: 512m is 0.512 bytes. Memory uses Mi/Gi (binary) or M/G (decimal), and the API accepts the typo silently.

Myth: kubectl top shows how full the cluster is for scheduling purposes.

Fact: kubectl top shows usage. The scheduler fills nodes by the sum of requests, which kubectl describe node reports; the two routinely disagree by a factor of two.

How pros do it

  • Set requests for every container from observed p95 usage (VPA in recommendation mode or metrics history), and review them on a schedule; scheduling is only as honest as the requests are.
  • Always set a memory limit; memory is incompressible and one leak without a ceiling takes out the node. Set it from the observed working set plus headroom, and equal to the request for tiers that must survive node pressure.
  • Decide CPU limits per tier: none (or Guaranteed with the static CPU manager policy) for latency-critical services, kept for batch and untrusted tenants; alert when the throttled-period ratio exceeds a few percent.
  • Make runtimes cgroup-aware: automaxprocs for Go, container support and -XX:MaxRAMPercentage for the JVM, so thread pools and heaps size to the cgroup rather than the node.
  • Put a LimitRange with defaults and a ResourceQuota in every shared namespace so nothing is BestEffort by accident and no team can consume the cluster.
  • Use binary suffixes (Mi, Gi) everywhere and lint manifests for a lowercase m on memory; treat a limit below a request as a review failure, not just an admission error.

Questions people ask

Why is my pod OOMKilled when kubectl top nodes shows 20 GiB free?

Say the limit is per container, enforced by that container's memory cgroup, so node memory is irrelevant. Then name what you compare: container_memory_working_set_bytes against limits.memory, and remember that a tmpfs emptyDir (medium: Memory) counts against the writer's limit. 'Container limit, not node' is the sentence to lead with.

Should I just stop setting CPU limits?

Give a tiered answer, not a slogan: for latency-sensitive services on clusters you control, often yes; keep an honest CPU request, keep the memory limit, and verify with the throttling ratio. Keep CPU limits for batch and for tenants who would otherwise starve others, because requests alone guarantee a fair share, not a bounded one. Naming the tradeoff is what the interviewer wants.

What is the difference between Evicted and OOMKilled in kubectl get pods?

Two killers, two statuses: OOMKilled is a container status, it exceeded its own limit and is restarted in place; Evicted is a pod phase (Failed) set by the kubelet reclaiming node memory or disk, the pod is gone and its controller must recreate it elsewhere. Say which fix each one points at: the container's limit versus node headroom and honest requests.

Does QoS class affect where a pod is scheduled?

Say no: scheduling uses requests only. Then list what QoS does change, so the answer is complete: eviction order under node pressure, the kernel oom_score_adj, and eligibility for exclusive CPUs; nothing about placement.

If I set only limits, what are my requests?

They default to the limits. Then say the consequence: set memory and CPU limits alone and the pod becomes Guaranteed, which is safe but expensive to place because the scheduler reserves the full limit. Knowing this default is how you explain a 'full' cluster at 30% usage.

How do I see whether a container is being throttled?

Name the query: the rate of container_cpu_cfs_throttled_periods_total divided by container_cpu_cfs_periods_total for the container, or cpu.stat in its cgroup for nr_throttled and throttled_usec. Then say what you correlate it with: spikes in p99 against those counters. A few percent throttled is already shaping latency.

Why does kubectl apply fail with 'must specify limits.memory'?

Say the namespace has a ResourceQuota that names limits.memory, so every pod must declare it. Then the fix: add a LimitRange with a default so pods that omit it get one instead of being rejected. Pairing every quota with a LimitRange is the practice to state.

Further reading

Drills · 8

Answer in your head, or out loud, before you reveal. Mark each one: "Again" brings it back, "Got it" counts on your desk.

1 Pick the strongest answer

A container with limits.cpu: 500m gets a burst and wants two full cores for a few hundred milliseconds. What happens to it, and is that the same thing that happens when it exceeds its memory limit?

  1. The kubelet evicts the pod for exceeding its CPU limit. Node-pressure eviction is about memory, disk, and PIDs; CPU over-use is handled by throttling.
  2. It is throttled: the CFS quota lets it run 50 ms of every 100 ms period and it waits for the rest, so latency rises but nothing is killed. CPU is a compressible resource; the kernel enforces the limit by pausing the cgroup once its quota for the period is spent.
  3. The scheduler moves the pod to a node with more free CPU. Scheduling happens once; nothing moves running pods for resource reasons.
  4. It is OOMKilled with exit code 137. OOMKill is a memory mechanism; CPU limits never kill.
In short

The container is throttled to 50 ms of CPU every 100 ms, so latency rises but nothing is killed.

Why

CPU limits are enforced by the CFS bandwidth controller: cpu.max grants a quota per 100 ms period, and a multi-threaded process can exhaust a 500m quota in 25 ms across two threads, then sit idle for 75 ms. That is why services can show low average CPU and high p99 latency at the same time. Interviewers look for "throttled, not killed" and for knowing where to see it (container_cpu_cfs_throttled_periods_total).

The common mistake

Saying the container is OOMKilled or evicted for exceeding CPU. CPU is compressible and is paused until the next period; only memory limits kill, and only node pressure evicts.

Read the docs

2 Answer out loud

Requests versus limits: what does each do, who enforces it, and how do the QoS classes that fall out of them decide who gets evicted when a node runs short of memory? Three to six sentences.

In short

A strong answer says requests are for scheduling, limits are enforced by cgroups, and QoS sets the eviction order under node pressure.

What a strong answer does
  • mechanism: Requests against allocatable at scheduling; limits via cgroups: CPU throttled by CFS quota, memory OOMKilled; notes they are independent knobs.
  • qos and eviction: Derivation rule, eviction ranks usage-over-request (BestEffort first, Guaranteed last), and the practical consequence: set requests from real usage.
  • communication: Two crisp halves (knobs, then consequences) with precise vocabulary.
Why

Interviewers want the two halves kept separate: how the knobs are enforced (scheduling vs cgroups, throttle vs kill) and what QoS changes (eviction order, not container-level enforcement).

The common mistake

Calling requests and limits 'min and max', or saying Guaranteed pods cannot be OOMKilled. Requests enforce nothing at runtime beyond CPU weight, and QoS only changes eviction order.

3 Pick the strongest answer

A pod has two containers, each with requests equal to limits for CPU and memory. What QoS class does it get, and what does that class actually buy you?

  1. BestEffort: QoS only depends on whether a PriorityClass is set. PriorityClass affects scheduling and preemption; QoS class is derived purely from requests and limits.
  2. Burstable: any pod with limits set is Burstable. Burstable is for pods with some requests that are not equal to limits; equal requests and limits everywhere means Guaranteed.
  3. Guaranteed: it is the last class the kubelet evicts under node pressure and its memory limit is exactly its request. Every container must have requests equal to limits for both resources; the class is computed per pod from all containers.
  4. Guaranteed, and it can never be OOMKilled. Guaranteed pods are still killed if a container exceeds its own memory limit; the class protects against node-pressure eviction, not against the container's own limit.
In short

The pod is Guaranteed, so it is evicted last under node pressure, but it can still be OOMKilled by its own limit.

Why

QoS is derived, not declared: Guaranteed when every container has requests equal to limits for CPU and memory, BestEffort when nothing is set, Burstable otherwise. It matters at eviction time and for CPU manager policies. It does not exempt a container from its own limits.

Read the docs

4 Read the output

The node is under memory pressure. In what order does the kubelet consider these pods for eviction?

$ kubectl get pods -o custom-columns=NAME:.metadata.name,QOS:.status.qosClass,REQ:.spec.containers[0].resources.requests.memory,LIM:.spec.containers[0].resources.limits.memory
NAME        QOS          REQ      LIM
cache       BestEffort   <none>   <none>
api         Burstable    256Mi    1Gi
ledger      Guaranteed   2Gi      2Gi

$ kubectl top pods
NAME        CPU(cores)   MEMORY(bytes)
cache       12m          180Mi
api         240m         900Mi
ledger      310m         1900Mi

$ kubectl describe node worker-3 | grep MemoryPressure
  MemoryPressure   True   ...  kubelet has insufficient memory available
  1. api first, because it has the largest gap between request and limit. The limit does not enter eviction ranking; usage above request does, and BestEffort still ranks ahead.
  2. cache first (BestEffort), then api (Burstable, using far more than its request), then ledger (Guaranteed) last. Eviction ranks by usage relative to requests: BestEffort pods have no requests, Burstable pods over their request come next, Guaranteed pods within their limits go last.
  3. ledger first, because it uses the most memory. Absolute usage is not the criterion; ledger is within its request, which is the protected case.
  4. Random: eviction order is not defined. The kubelet's eviction order is documented and deterministic given usage and requests.
In short

cache goes first as BestEffort, then api because it uses far more than its request, and ledger goes last as Guaranteed.

Why

Node-pressure eviction is the kubelet protecting the node, not the API server scheduling. It reclaims from pods whose usage exceeds their requests, ranked by how far over they are and by priority; BestEffort pods (no requests) are always over. A Guaranteed pod within its limits is evicted only if nothing else is left. The practical lesson: set requests from real usage so your important pods are not "over".

Read the docs

5 Scenario: what do you do next?

The RPC gateway pods that front your Solana RPC fleet show p99 latency spikes of 800 ms every few seconds. kubectl top shows each pod at about 40% of its 2-core CPU limit and 60% of its memory limit. No OOMKills, no restarts, nodes are healthy, request rate is flat.

Step 1. Where do you look first?

  1. Restart the pods. Restarts erase evidence and change nothing structural.
  2. Raise the memory limit. Memory is at 60% with no OOMKills; nothing points there.
  3. Add two more replicas. Request rate is flat and utilization is low; capacity is not the hypothesis and the spikes would persist per pod.
  4. CPU throttling metrics for the containers: container_cpu_cfs_throttled_periods_total versus container_cpu_cfs_periods_total. Average CPU well under the limit with periodic latency spikes is the signature of CFS throttling; the metric confirms or kills the hypothesis in one query.

Step 2. Throttled periods are 35% of all periods. The gateway is a multi-threaded Rust service that fans out each request to several backends. What is the mitigation?

  1. Increase the readiness probe period so the pod is not marked unready during spikes. The pods are not flapping; this would hide a symptom that is not even present.
  2. Lower the CPU request so more pods fit per node. That makes scheduling less honest and does nothing about the quota that causes throttling.
  3. Raise or remove the CPU limit while keeping the CPU request, so bursts are not clipped by the quota; verify with the throttling ratio and p99. The request keeps scheduling honest; the limit is what causes the stalls. For latency-sensitive services many teams run requests-only CPU (or Guaranteed with a static CPU policy).
  4. Set the pod to Guaranteed by making memory requests equal limits. QoS class does not change how the CFS quota throttles a container; only the CPU limit does.

Step 3. p99 drops to 90 ms. For the postmortem, what policy do you propose for the fleet?

  1. Requests set from p95 usage with a headroom rule, CPU limits removed for latency-critical tiers (kept for batch), throttling ratio alerting, and a LimitRange that prevents unlimited memory. It encodes the mechanism as policy: honest requests for scheduling, no CPU clipping where latency matters, memory still bounded, and the metric that caught it becomes an alert.
  2. Tell developers to set CPU limits carefully. A reminder, not a mechanism.
  3. Remove all limits everywhere. Unbounded memory lets one leak take down a node; the policy should distinguish CPU from memory and tiers from each other.
In short

Check the CPU throttling metrics first, then raise or remove the CPU limit while keeping the request.

Why

The classic low-average, high-p99 signature. CFS enforces cpu.max per 100 ms period, so a multi-threaded burst exhausts the quota early in the period and the container stalls until the next one, even at 40% average utilization. RPC gateways and validators are exactly the workloads where this bites, and the fix is a policy about requests and limits, not more hardware.

Read the docs

6 Design round

You inherit a 30-node cluster shared by six teams and about forty services. Batch jobs starve latency-sensitive APIs, two teams run with no limits at all, and average utilization is 35%. Design the resource policy for this cluster and say how you would prove it works.

  • One cluster; no budget for a second.
  • Latency-sensitive APIs have p99 SLOs; batch has a 06:00 completion deadline.
In short

A strong answer sets quotas and LimitRange defaults per namespace, requests from real usage, and no CPU limits on latency-critical services.

A strong answer covers
  • Namespace ResourceQuotas per team so no team can consume the cluster.
  • LimitRange defaults so pods without requests get sane ones, and memory is always bounded.
  • Requests derived from observed p95 usage (VPA in recommendation mode or metrics), not guesses.
  • No CPU limits (or Guaranteed with a static CPU policy) for latency-critical services; CPU limits retained for batch.
  • PriorityClasses so API pods preempt batch under pressure, with PDBs on APIs.
  • Verification: throttling ratio and eviction counts as alerts, a load test replaying peak, and utilization target with a headroom rule.
What a strong answer does
  • design quality: Quotas, LimitRange defaults, requests from usage, tiered CPU-limit policy, priority and PDBs, and a verification plan.
  • tradeoffs: Two or more tradeoffs with a decision (e.g. accept batch slippage risk, mitigate with a batch SLO alert).
  • communication: Restates constraints, states the policy per tier, names failure modes, ends with the decision.
Why

The primitives interviewers expect: quotas and LimitRanges for boundaries, requests from real usage for honest scheduling, a deliberate CPU-limit policy per tier because throttling and killing are different failure modes, priority and PDBs for the batch-vs-API conflict, and a plan that proves it with metrics rather than hope.

Read the docs

7 Quick recall

Follow-up: every container has requests equal to limits for CPU and memory. Which QoS class is that?

In short

The pod gets the Guaranteed QoS class.

Accepted

Guaranteed · guaranteed · guaranteed qos

Why

Guaranteed; Burstable when some requests are set but not equal to limits; BestEffort when none are set.

8 Find what's broken

kubectl apply rejects this manifest. A colleague 'fixes' the rejection, after which the pods schedule onto already-full nodes and are soon evicted under memory pressure. Which two lines are wrong?

apiVersion: apps/v1
kind: Deployment
metadata:
  name: cache
spec:
  replicas: 2
  selector:
    matchLabels: { app: cache }
  template:
    metadata:
      labels: { app: cache }
    spec:
      containers:
        - name: redis
          image: redis:7.2
          resources:
            requests:
              cpu: "2"
              memory: 512m
            limits:
              cpu: 500m
              memory: 1Gi
In short

memory: 512m means 0.512 bytes, not 512 MiB, and a CPU limit below the request is rejected.

What's broken
  • Line 19: 512m on memory means 512 millibytes (0.512 bytes), not 512 MiB; the request is effectively zero, so the container lands on any node and scheduling gives it nothing.
  • Line 21: A CPU limit (500m) below the CPU request (2) is invalid; the API server rejects the pod spec.
Why

Two unit-and-semantics traps. Kubernetes memory uses binary suffixes (Ki, Mi, Gi); a lowercase m is the SI milli prefix and is valid syntax, so nothing warns you. Limits must be at least requests for the same resource, which the API enforces at admission. Candidates who know the second rule but miss the first reveal they have never read a rejected pod's status closely.

Read the docs

Next lesson API server: authn, authz, admission, watches, and deprecations
Drill · Requests, limits, QoS classes, and eviction
0:00

Loading…