Resource Requests and Limits: Preventing Noisy Neighbor Problems
Kubernetes requests and limits explained: scheduling, CPU throttling, memory OOM kills, QoS classes, eviction and right-sizing tips.

A cluster runs smoothly until a reporting job lands on the same node as the checkout service. The job has no resource settings and starts using all the CPU and most of the memory it can find. Checkout latency triples, and then the node runs low on memory and the kubelet starts evicting pods, including two checkout replicas. Nothing was misconfigured in the checkout service itself. Its neighbor simply had no boundaries.
Kubernetes manages CPU and memory per container with two settings. Requests are guarantees used for scheduling: a pod is placed only on a node with enough unreserved capacity for the sum of its containers’ requests. Limits are caps enforced by the node through Linux cgroups, the same mechanism behind Docker’s resource limits.
resources:
requests:
cpu: 250m # a quarter of a CPU core
memory: 256Mi
limits:
memory: 512Mi # no CPU limit; see below
CPU is measured in cores, with m meaning thousandths: 250m is a quarter of a core. Memory uses bytes with binary suffixes: Mi and Gi. Note that M means 1,000,000 bytes, not 1,048,576; using 512M where you meant 512Mi is a common small mistake.
What requests do
- Scheduling. The scheduler sums the requests of pods already on each node and only places a new pod where its requests fit within the node’s allocatable capacity (total capacity minus what is reserved for the operating system and Kubernetes itself). Actual usage is not considered.
- CPU share under contention. When a node’s CPU is busy, each container gets CPU time in proportion to its request. A container with a 1-core request gets roughly four times the CPU of one with
250mwhen they compete. - Autoscaling. The Horizontal Pod Autoscaler computes utilization as a percentage of the request, so wrong requests produce wrong scaling decisions.
A pod without requests is scheduled as if it needed nothing. Put enough of them on a node and the node is promised far more than it has.
What limits do: CPU throttles, memory kills
| Exceeding the request | Hitting the limit | |
|---|---|---|
| CPU | Allowed if the node has idle CPU | Throttled: the container waits until the next scheduling period, adding latency |
| Memory | Allowed if the node has free memory, but the pod becomes an early eviction candidate | The container is OOM-killed and restarted; the pod shows OOMKilled |
CPU is compressible: taking it away just makes work slower. Memory is not: the kernel cannot take memory back from a process, so it kills it.
The CPU limits debate
Many experienced operators recommend setting CPU requests but no CPU limits for most services. The argument: CPU limits are enforced in short periods (100 milliseconds by default), so a multi-threaded service can use its whole quota in a burst early in a period and then sit throttled for the rest of it, even when the node has idle CPU. That shows up as tail latency that is hard to explain. Without a CPU limit, a container can use idle CPU freely, while requests still guarantee each container its fair share when the node is busy.
CPU limits still make sense when you need predictable, repeatable performance for benchmarking, in multi-tenant clusters where one team must not consume another’s spare capacity, or for batch jobs you deliberately want to cap. If you do set them, watch the throttling metric container_cpu_cfs_throttled_periods_total rather than average CPU usage, which hides throttling.
For memory, the advice is the opposite: always set a limit, and for latency-sensitive services consider setting it equal to the request, so a pod never relies on memory the node might need back.
QoS classes and eviction
Kubernetes assigns every pod a Quality of Service class from its resource settings:
| QoS class | Condition | Eviction priority under node pressure |
|---|---|---|
Guaranteed |
Every container has CPU and memory requests equal to limits | Evicted last |
Burstable |
At least one request or limit set, but not Guaranteed | Evicted by how far usage exceeds requests |
BestEffort |
No requests or limits at all | Evicted first |
When a node runs low on memory or disk, the kubelet evicts pods to protect the node, starting with BestEffort pods and Burstable pods using the most above their requests. The reporting job in the opening example was BestEffort, but checkout pods using more memory than they requested were next in line. Accurate memory requests protect important services.
Namespace guardrails
apiVersion: v1
kind: LimitRange
metadata:
name: defaults
namespace: reporting
spec:
limits:
- type: Container
defaultRequest:
cpu: 100m
memory: 128Mi
default:
memory: 512Mi
max:
memory: 4Gi
---
apiVersion: v1
kind: ResourceQuota
metadata:
name: team-quota
namespace: reporting
spec:
hard:
requests.cpu: "8"
requests.memory: 16Gi
limits.memory: 32Gi
pods: "50"
A LimitRange fills in defaults for containers that specify nothing and rejects values outside a range, so no pod in the namespace is BestEffort by accident. A ResourceQuota caps the total a namespace can request, which is how platform teams keep one team from consuming the whole cluster.
Right-sizing
Requests should reflect real usage. A reliable process:
- Measure each container’s CPU and memory over a representative period, including peaks, with your metrics stack or
kubectl topfor a quick look. - Set CPU requests near typical usage under normal load, and memory requests near the steady-state peak.
- Set memory limits with headroom above observed peaks, and configure the runtime to respect them:
-XX:MaxRAMPercentagefor Java,--max-old-space-sizefor Node.js,GOMEMLIMITfor Go. - Revisit after significant releases.
The Vertical Pod Autoscaler can help: in recommendation-only mode it watches usage and suggests requests without changing anything, which is a low-risk way to find badly sized workloads. Changing resources still requires recreating pods today; in-place pod resizing exists only as an alpha feature.
Over-requesting wastes money, because nodes fill with reservations nobody uses. Under-requesting causes contention and evictions. Comparing total requests with actual usage across the cluster is usually the fastest cost win in Kubernetes.
Frequently Asked Questions
What is the difference between requests and limits in Kubernetes?
Requests are the resources reserved for a container, used by the scheduler to place pods and to share CPU under contention. Limits are the maximum a container may use: exceeding the CPU limit causes throttling, and exceeding the memory limit gets the container killed.
Should I set CPU limits in Kubernetes?
Many teams set CPU requests without CPU limits for latency-sensitive services, because limits can throttle bursts even when the node has idle CPU. CPU limits are still useful for strict multi-tenancy, predictable benchmarks or capping batch jobs. Always set memory limits.
What happens when a pod exceeds its memory limit?
The container is killed by the kernel’s out-of-memory killer and restarted by the kubelet. kubectl describe pod shows the last state as OOMKilled with exit code 137.
What are QoS classes in Kubernetes?
Guaranteed, Burstable and BestEffort, derived from each pod’s requests and limits. They determine eviction order when a node runs short of memory or disk: BestEffort pods are evicted first and Guaranteed pods last.
Boundaries make neighbors good
Requests describe what a workload needs; limits describe what it may never exceed. Set accurate requests everywhere, memory limits always, CPU limits deliberately, and namespace defaults so nothing slips through. The scheduler can then pack nodes sensibly, the kubelet evicts the right pods under pressure, and the Horizontal Pod Autoscaler has accurate numbers to scale on. The official documentation is worth keeping open: the resource management documentation and the Pod Quality of Service classes. Related reading on this site: cgroups and container isolation.
Originally posted on 23 April 2024 and post last modified on 23 April 2024