Kubernetes requests and limits: how to size containers without surprises
Requests decide scheduling, limits decide throttling and OOM kills. How CPU and memory differ, what QoS classes mean, and a sensible way to start.

Every container in Kubernetes can declare two numbers for CPU and for memory: a request and a limit. They look similar, but they serve different purposes, and CPU and memory react differently when a container exceeds its limit. Understanding this difference clears up most of the confusion around "why was my pod killed?" and "why is my service slow when the node looks idle?".
Requests and limits in one minute
According to the Kubernetes documentation:
- A request is the amount the container is guaranteed. The kube-scheduler uses requests to decide which node a pod fits on.
- A limit is the most the container may use. It is enforced by the kubelet and the container runtime, with the kernel (through cgroups on Linux) doing the actual work.
A container can use more than its request if the node has spare capacity. A pod's request or limit is the sum across its containers. And if you set a limit but no request, and nothing else supplies a default, Kubernetes uses the limit as the request.
containers:
- name: api
image: example/api:1.4.2
resources:
requests:
cpu: 250m
memory: 256Mi
limits:
memory: 512Mi
Here 250m means a quarter of a CPU core. The container is scheduled as if it needs a quarter core and 256 MiB, and it may be stopped if it grows past 512 MiB.
CPU and memory are different
This is the part worth remembering.
| Resource | What happens at the limit | Can it recover? |
|---|---|---|
| CPU | The kernel throttles the container; it is capped | Yes, it just runs slower |
| Memory | The container can be OOM-killed when the kernel detects memory pressure | No, the process is terminated |
The documentation describes CPU limits as a hard cap enforced through throttling, while memory limits are enforced reactively: a container can briefly exceed its limit, and the kill occurs when the kernel detects memory pressure.
The practical result is that a CPU limit set too low makes your service slow in ways that can look like network or database issues. Latency rises, nothing crashes, and dashboards that only show average CPU look fine. A memory limit set too low causes restarts, which are easy to spot.
Note
Whether to set CPU limits at all is a debated choice among teams. Both approaches are used. What matters is that you choose on purpose, and that you always set CPU requests, because the scheduler depends on them.
Quality of service classes
From the requests and limits you declare, Kubernetes derives a quality of service class for each pod:
- Guaranteed: every container has a CPU and memory request and limit, all greater than zero, with request equal to limit.
- Burstable: the pod does not meet the Guaranteed rules, but at least one container has some request or limit.
- BestEffort: no CPU or memory requests or limits at all.
The class matters when a node runs short of resources. Kubernetes evicts BestEffort pods first, then Burstable, and Guaranteed last. Under resource pressure, the pods that are candidates for eviction are those using more than they requested.
So a pod with no resources set is first in line to be removed. And a pod whose request is far below its real use is exposed too: it was placed on a node on the strength of a small number, and it now competes for what is left.
flowchart LR R[Requests] --> S[Scheduler picks a node] L[Limits] --> K[Kernel enforces] K --> C[CPU: throttled] K --> M[Memory: OOM kill] R --> Q[QoS class] L --> Q Q --> E[Eviction order under pressure]
How to pick numbers
Guessing is the usual start, and guessing is fine for a first deploy. The trick is to replace guesses with measurements quickly.
- Start with a modest request and a memory limit. Use what the app needs at normal load, with some headroom.
- Watch real usage for a week or so, including your busiest hours. Look at peaks and not only averages. Your metrics system will have per-container CPU and memory series.
- Set the memory request near typical use and the limit above the peak. A memory limit that sits barely above the peak turns every traffic spike into a restart.
- Set the CPU request near typical use. This is what the scheduler will reserve for you, so it is also what you pay for in capacity.
- Revisit after releases. A new version that caches more or serves more routes changes the numbers.
Some memory is easy to forget: language runtimes keep their own heaps and caches, and the container's total includes things such as file buffers and thread stacks. If your app has a configurable heap size, keep it comfortably under the container's memory limit.
Problems and where to look
- Pod restarts with reason OOMKilled: the memory limit is too low, or the app leaks.
kubectl describe podshows the last termination reason. - Latency rises under load but nothing restarts: check whether CPU throttling is happening. Throttling metrics are available from the container runtime metrics most clusters collect.
- Pod stays Pending: requests are larger than any node can offer. The events on the pod say which resource is short.
- Pods get evicted at odd times: look at the node's pressure conditions, and at whether the evicted pods had requests at all.
- Slow starts that turn into restarts: a startup that needs a burst of CPU can be throttled until it fails its probes; see Kubernetes probes for a startup probe that gives it time.
Short version
- Always set requests; the scheduler needs them.
- Set a memory limit with room above the peak.
- Decide about CPU limits deliberately, and watch for throttling if you set them.
- Pods with equal requests and limits are evicted last; pods with none are evicted first.
- Measure, then adjust. Resource settings are a living part of the deployment, not a one-time guess.


