الانتقال إلى المحتوى
DevOps والـ CloudKubernetes· 8 دقائق للقراءة

Requests vs Limits: How Kubernetes Schedules, Throttles and OOM-Kills Your Pods

Requests are reservations the scheduler adds up; limits are ceilings the kernel enforces, by throttling CPU and OOM-killing on memory.

ReadIn

مقال كل يوم يفرق معاك

22 نوفمبر 2026
  • كاتب موثّق
محتويات المقال

A team adds limits: { cpu: "8", memory: 64Mi } to every service "to be safe", reasoning that a limit only caps what a container may use. Then a routine scale-up leaves one replica stuck in Pending, although every dashboard shows the node almost idle. Meanwhile, a worker restarts every few hours with exit code 137, and nobody connects it to that 64Mi.

The common misconception

The belief: requests and limits are two names for the same cap. A container "gets" the number you write, so you set one of them, or both to the same value, and move on.

It's easy to see why. They sit side by side in the same resources block, use the same units, and templates often give them the same values. Kubernetes even fills in a missing request from the limit. And for memory, when both are equal, they really do behave like one number.

The half-truth: they can hold the same value, but they're read by different components, at different times, for different decisions.

What actually happens

Requests are for the scheduler

The docs put it plainly: "the kube-scheduler uses this information to decide which node to place the Pod on." It checks that "the sum of the resource requests of the scheduled containers is less than the capacity of the node", and real usage doesn't matter: "although actual memory or CPU resource usage on nodes is very low, the scheduler still refuses to place a Pod on a node if the capacity check fails." A request is not a cap, either: it's "possible (and allowed) for a container to use more resource than its request" when the node has room.

Limits are for the kernel

Limits "are applied by the kubelet (and container runtime), and are ultimately enforced by the kernel", through on Linux. The two resources fail differently. For CPU, the limit is "a hard ceiling on how much CPU time the container can use": when it's used up, "the kernel waits before allowing that cgroup to resume execution." That's , and the docs add that runtimes "don't terminate Pods or containers for excessive CPU usage." For memory, going over the limit makes "the Linux kernel out-of-memory subsystem" step in, typically "stopping one of the processes in the container that tried to allocate memory."

Requests also set a weight and an eviction line

The CPU request "typically defines a weighting": when containers compete, "workloads with larger CPU requests are allocated more CPU time." And when a node runs short of memory, the kubelet evicts first "BestEffort or Burstable pods where the usage exceeds requests." The summarizes where a Pod stands: Guaranteed when every container's CPU and memory requests equal its limits, BestEffort with none at all, Burstable otherwise.

A limit without a request becomes the request

"If you specify a CPU limit for a Container but do not specify a CPU request, Kubernetes automatically assigns a CPU request that matches the limit", and the same goes for memory. A limit meant as "at most 8 CPUs" quietly becomes "keep 8 CPUs free for me on the node."

Watching it on a cluster

We ran this on Docker Desktop's Kubernetes (server v1.34.3, kubectl v1.34.1), with one node that has 20 allocatable CPUs, in a namespace of our own with no LimitRange; --context and -n are left out for space. The Deployment runs 3 replicas of busybox:1.37 serving HTTP. Here are the resources blocks of the two versions we applied:

YAML api.yaml
resources:  limits:          # meant as "at most", also becomes the request    cpu: "8"    memory: 64Mi
Bash terminal
kubectl apply -f api.yaml   # 3 replicas, limits onlykubectl get pods# NAME                   READY   STATUS    RESTARTS   AGE# api-5b99d6d69d-8gpp2   1/1     Running   0          8s# api-5b99d6d69d-h5hs7   0/1     Pending   0          8s# api-5b99d6d69d-k92w7   1/1     Running   0          8skubectl get pod api-5b99d6d69d-8gpp2 \  -o jsonpath='{.spec.containers[0].resources.requests}'# {"cpu":"8","memory":"64Mi"}kubectl get pod api-5b99d6d69d-8gpp2 -o jsonpath='{.status.qosClass}'# Guaranteed

In the first tab, two replicas reserved 16 of the node's CPUs, and the third couldn't fit; its event said "0/1 nodes are available: 1 Insufficient cpu." The copied requests also made the Pods Guaranteed, the best QoS class, for capacity they never touched. In the second tab, all three fit. Inside a container you can see where each number went: the request became cpu.weight, there's no CPU ceiling (max), and the memory limit became memory.max, 64 MiB in bytes.

Then we gave two Pods jobs that cross their limits: tail /dev/zero, which buffers forever, under a 64Mi memory limit, and a shell busy loop under a 200m CPU limit:

Bash terminal
kubectl apply -f leak.yaml   # tail /dev/zero, memory limit 64Mikubectl get pod leak# NAME   READY   STATUS      RESTARTS     AGE# leak   0/1     OOMKilled   1 (8s ago)   8skubectl get pod leak -o jsonpath='{..lastState.terminated.reason}'# OOMKilledkubectl apply -f spin.yaml   # busy loop, cpu limit 200mkubectl exec spin -- cat /sys/fs/cgroup/cpu.max# 20000 100000kubectl exec spin -- \  grep -E "usage_usec|nr_periods|nr_throttled" /sys/fs/cgroup/cpu.stat# usage_usec 1359686# nr_periods 67# nr_throttled 67# (the same command, 10 seconds later)# usage_usec 3430017# nr_periods 171# nr_throttled 171

The leak was killed within seconds, with exit code 137, and restarted. The busy loop was never killed. Its quota is 20 ms of CPU per 100 ms period, and it was throttled in every one of those periods: over the 104 periods between the two reads it got about 2.07 seconds of CPU, almost exactly 0.2 of a core.

RequestLimit
Read byThe scheduler, then the kernel as a CPU weightThe kubelet and runtime, enforced by the kernel
CPUReserved on a node; your share under contentionA ceiling; the container is throttled above it
MemoryReserved on a node; the line for evictionA ceiling; the container is OOM-killed above it
If you leave it outCopied from the limit, if there is oneNo ceiling, unless a LimitRange adds one
In the cgroupcpu.weightcpu.max, memory.max

How to apply it in your project

  1. Set requests from real usageRequests decide how many replicas fit on your nodes, so base them on usage at normal load. Too high wastes nodes and leaves Pods Pending; too low means you lose out under contention and get evicted first.
  2. Set the memory limit equal to the memory requestIn our view, that's the safest default: usage then can't exceed the request, so the Pod isn't among the first to be evicted, and its OOM threshold is a number you chose. Size both from the measured peak.
  3. Decide on CPU limits on purposeA CPU limit trades burst speed for predictability: the busy loop above got 0.2 of a core on a 20-CPU node. Without one, the container can use idle CPU, and requests still decide each Pod's share under contention.
  4. Check what you actually gotRun kubectl get pod <name> -o jsonpath='{.status.qosClass}' and look at "Allocated resources" in kubectl describe node. A LimitRange in your namespace may have added limits you didn't write.

Key takeaways

  • Requests are reservations for scheduling; limits are ceilings the kernel enforces.
  • The scheduler adds up requests, not usage, so oversized requests leave Pods Pending on idle nodes.
  • Above a CPU limit a container is throttled; above a memory limit it's OOM-killed with exit code 137.
  • A limit without a request becomes the request, which can reserve far more than you meant.
  • Size memory request and limit from the measured peak, and choose CPU limits deliberately.

📚 المصادر

  1. Resource Management for Pods and Containers — Kubernetes Documentation
  2. Pod Quality of Service Classes — Kubernetes Documentation
  3. Assign CPU Resources to Containers and Pods — Kubernetes Documentation
  4. Node-pressure Eviction — Kubernetes Documentation

التعليقات (0)