# Kubernetes Resource Requests and Limits: QoS, Throttling, and Right-Sizing

> Set Kubernetes CPU and memory requests and limits correctly: QoS classes, CPU throttling versus OOMKilled, LimitRange and quotas, HPA and VPA, and verification.

**Quick answer:** Requests tell the scheduler what a pod needs and are the denominator the HPA divides by; limits tell the kernel what it may consume. CPU limits throttle, memory limits trigger OOMKilled. Match requests to measured p95 usage, keep memory limits above the peak working set, set CPU limits only when isolation outweighs throttling risk, and verify QoS, throttling, and restarts in production.

## Key takeaways

- A request is a scheduling reservation that also serves as the HPA's denominator; a limit is a cgroup ceiling enforced at runtime, so the two must be reasoned about separately.
- CPU limits throttle and leave the process alive, while memory limits trigger OOMKilled; a healthy-looking average can hide both failures.
- QoS class is computed from requests and limits and decides eviction order and OOM score, so Guaranteed is a priority promise, not protection from a bad limit.
- Right-size from two weeks of p95 utilization, peak working set, and throttling data, with per-environment values and headroom for bursts, rollouts, and sidecars.
- LimitRange and ResourceQuota bound mistakes but never size a workload; HPA and VPA must not fight over the same metric, and every value should be checked on the admitted pod.

---

Every Kubernetes incident eventually becomes a resource question. A pod that is OOMKilled at 3 a.m., a service whose p99 latency doubles while average CPU sits at 40%, a node that cannot schedule a deployment because requests reserve capacity nobody uses: all three are the same configuration surface seen from different angles. Requests and limits look like two adjacent YAML fields. In practice they are two separate contracts. The scheduler reads requests to decide where a pod can run, while the kubelet and the kernel use limits to decide what happens when the pod tries to exceed them. Confusing those contracts produces clusters that are over-provisioned and unreliable at the same time.

Defaults make it worse: scaffolds ship with no resources, tutorials recommend 100m and 128Mi for everything, and Helm charts copy development values into production. None of this is validated at admission, and none of it fails in staging, which lacks production's traffic, page cache, and sidecars. Resource configuration is an engineering artifact: measure it, review it, and verify it like any other production setting.

## Requests and limits are two different contracts

A request is a scheduling reservation. The scheduler adds it to the node's allocated CPU and memory and refuses to place the pod where it does not fit. A limit is a runtime ceiling enforced through cgroups: the container's CPU quota and memory ceiling. Removing a limit does not free capacity for the scheduler, and raising a request does not give the process more CPU at runtime. Only the request affects where the pod lands.

Units matter: `500m` is half a core, `1` is one core, and `256Mi` is 4.6% larger than `256M`. Mixing milli and binary suffixes in a capacity spreadsheet produces nodes that hold fewer pods than planned.

One admission-time behavior surprises almost everyone: when a container declares a limit but no request, Kubernetes copies the limit into the request. The pod is scheduled as if it needed its full burst, which destroys bin-packing, and the source YAML never shows why. A LimitRange can inject a default as well, so the effective value must be read from the admitted object. The [Kubernetes YAML validator](/tools/kubernetes-yaml) catches schema mistakes, but only an admission review or `kubectl get pod -o yaml` shows the values Kubernetes actually stored.

## CPU throttling and memory OOMKilled are not the same failure

CPU is a compressible resource. When a container reaches its CPU limit, the kernel does not kill it; the CFS scheduler stops scheduling its threads until the next 100 ms period. The process survives, but every request that arrived during the pause waits. Average CPU can sit at 40% while p99 latency doubles, because the quota is consumed in short bursts and the application is throttled for the rest of each period. Throttling is easy to miss: `kubectl top` reports an average and the restart count stays at zero. cAdvisor exposes `container_cpu_cfs_throttled_periods_total` and `container_cpu_cfs_throttled_seconds_total`; a sustained throttled-period ratio above roughly 5-10% at peak means the limit is too tight for the workload's burstiness.

Memory is incompressible. When a container's cgroup reaches its memory limit, the kernel OOM killer selects a process in that cgroup and kills it; the kubelet reports `OOMKilled` with exit code 137 and restarts the container according to the pod's restart policy. A restart loop that looks like a crash is often a memory limit below real usage. The number to compare is not RSS but the cgroup working set, which includes active page cache and can rise sharply during a backup, a cache warm-up, or a large response. The JVM, Go, and Node each hold memory beyond the visible heap, so a limit set to the heap size alone will OOM under load.

CPU limits trade latency for isolation. Many services run better with a CPU request and no CPU limit, relying on namespace quotas and node autoscaling to contain noisy neighbors. Memory limits are non-negotiable, because an unbounded container can take down the node, but they need headroom above the peak working set, not the average.

## QoS classes decide who gets evicted first

Kubernetes derives a QoS class from the requests and limits themselves; you do not set it. Guaranteed requires every container to declare CPU and memory requests equal to their limits. Burstable covers pods that declare something but miss that condition. BestEffort covers pods with no requests or limits at all. The class changes behavior in two places: kubelet eviction under node pressure and the OOM score applied to each container.

| QoS class | How it is assigned | Behavior under pressure | What it costs |
| --- | --- | --- | --- |
| Guaranteed | CPU and memory requests equal limits on every container | Last to be evicted; most favorable OOM score | No burst above the request; capacity reserved for peaks that may never happen |
| Burstable | At least one request or limit, not all equal | Evicted after BestEffort; OOM score scales with the request | Needs deliberate headroom; the common production default |
| BestEffort | No requests and no limits | First to be evicted; least favorable OOM score | Cheapest to schedule, worst isolation, hardest to reason about |

Eviction is not OOM termination. The kubelet evicts to reclaim node resources, ordered by QoS and usage above requests; the OOM killer acts inside a cgroup that reaches its own limit. A BestEffort pod can be evicted because a neighbor consumes memory, while a Guaranteed pod with a too-small limit is still killed by its own cgroup. Guaranteed promises priority and a fixed reservation, not a sufficient limit.

## LimitRange and ResourceQuota are guardrails, not sizing

`LimitRange` is namespace-scoped and mutates pods at admission. `defaultRequest` and `default` fill omitted values, `min` and `max` reject absurd ones, and `maxLimitRequestRatio` blocks extreme bursts. The mutation happens before quota evaluation, so a default consumes quota even when the author wrote nothing. Existing pods are never retroactively updated, and a default limit copied into a request turns an unspecified workload into an accidental reservation.

`ResourceQuota` caps the aggregate declared values in a namespace: `requests.cpu`, `limits.memory`, `pods`, `count/deployments.apps`, `requests.ephemeral-storage`, and similar. It counts declarations, not usage, so a namespace can be full while its pods idle at 5% CPU, and a rollout can be rejected because `maxSurge` needs quota for one extra pod. Create quota before you need it, leave rollout headroom, and alert on quota consumption rather than a failed deployment. Neither object sizes a workload; they only bound the damage of a wrong size.

## HPA, VPA, and the feedback loops between them

The Horizontal Pod Autoscaler scales replicas from a metric ratio. For CPU utilization the denominator is the pod's CPU request: a pod using 400m with a 500m request reports 80%, and a pod with no request cannot produce a utilization figure at all, so the HPA reports a missing-metric condition instead of scaling. Requests that are too low make it scale out aggressively; requests that are too high make it scale in while latency climbs. Memory is a poor HPA signal because it rarely falls after traffic drops, so replicas stay high; queue depth, in-flight requests, or requests per second are better custom metrics.

The Vertical Pod Autoscaler adjusts requests instead of replica count. In recommendation mode it watches usage and publishes suggested values; in update modes it changes the pod spec, sometimes evicting pods to apply the change. Running VPA and HPA on the same resource is a known conflict: VPA raises requests, which lowers reported utilization, which makes the HPA scale in, which raises utilization again. Use VPA to set requests and HPA on a different signal, or pick one, and prefer a week of recommendations reviewed by a human before automating updates.

## Right-sizing from observed usage instead of intuition

Right-sizing is a measurement loop, not a one-time calculation. Collect two weeks of per-container data, because a weekly batch or a Monday peak is invisible in an hour-long sample. For CPU, look at p95 usage during peak traffic and at the throttling ratio; set the request near p95 so the scheduler reserves what the workload uses, and treat any CPU limit as a latency budget rather than a capacity target. For memory, look at the peak working set, including page cache and runtime overhead, then set the request near the p95 working set and the limit 20-30% above the observed maximum.

Three signals confirm the result. A throttled-period ratio that stays low at peak means the CPU limit, if present, is not punishing bursts. Zero `OOMKilled` terminations over a full traffic cycle means the memory limit covers real peaks, including deploys and cache warm-up. A stable restart count and stable p99 as traffic rises mean the requests are honest enough for the scheduler and the HPA. If throttling is high, raise the CPU limit or remove it; if `OOMKilled` appears, raise the memory limit before touching the request.

Numbers also differ by environment. Development can run at 100m and 128Mi; production at the same values will throttle under a fraction of real traffic. Keep resources in per-environment overlays, review them like code, and never promote a development manifest without a sizing pass. The [YAML formatter](/tools/yaml-formatter) will not choose the numbers, but consistent structure makes a diff between overlays readable.

## Init containers, sidecars, and pod-level arithmetic

The scheduler does not simply sum requests. Its effective request for a pod is the larger of the sum of the app containers' requests and the largest request among the init containers. An init container that needs 2 CPU for a migration makes the whole pod unschedulable on a node with 1.5 CPU free, even though it runs for thirty seconds and the app needs 500m. That behavior is correct, but init container values belong in capacity planning.

The manifest below makes the arithmetic visible.

```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: checkout
spec:
  replicas: 3
  selector:
    matchLabels: { app: checkout }
  template:
    metadata:
      labels: { app: checkout }
    spec:
      initContainers:
        - name: migrate
          image: registry.example.com/checkout:2.14.0
          command: ["./migrate", "--wait"]
          resources:
            requests: { cpu: 500m, memory: 256Mi }
            limits: { cpu: "1", memory: 512Mi }
      containers:
        - name: api
          image: registry.example.com/checkout:2.14.0
          resources:
            requests: { cpu: 500m, memory: 512Mi }
            limits: { memory: 768Mi }   # no CPU limit: throttling would hurt p99
        - name: istio-proxy
          image: proxyv2:1.22
          resources:
            requests: { cpu: 100m, memory: 128Mi }
            limits: { memory: 256Mi }
```

Sidecars are regular containers for accounting. Every service-mesh proxy, log shipper, and metrics agent adds requests and limits, and its memory grows with connections and buffered logs. A sidecar with a 64Mi limit will be OOMKilled during a spike long before the application notices, and its restart takes the pod's networking with it. Native sidecars, declared as init containers with `restartPolicy: Always`, start before the app and stop after it, but they consume resources for the whole pod lifetime. Add their numbers to the pod's real cost, and remember that a generous sidecar limit can change the QoS class.

## Ephemeral storage and node eviction

Ephemeral storage is the resource teams forget until a node fills up. The container's writable layer, its log files, and `emptyDir` volumes all count against `requests.ephemeral-storage` and `limits.ephemeral-storage`. Exceeding the limit does not produce `OOMKilled`; the kubelet evicts the pod with an `Evicted` status and a message about ephemeral storage. Logs are the usual culprit: an application that prints a stack trace per request writes gigabytes per hour, and default rotation may still leave the node above its eviction threshold.

Set a request that reflects normal scratch usage and a limit that caps the damage. Give `emptyDir` a `sizeLimit` when the workload writes temporary files, and use `medium: Memory` only when the data belongs in memory, because that volume counts against the memory limit instead. Watch `container_fs_usage_bytes` and node disk metrics; image pulls and logs compete for the same disk, and a node that cannot write logs will soon evict pods.

## Common mistakes and the rules that prevent them

The expensive mistakes repeat across teams:

- A limit without a request, so Kubernetes silently schedules the full burst and density collapses.
- A CPU limit equal to average usage, which throttles every burst and doubles tail latency while dashboards look healthy.
- A memory limit below the runtime's real footprint, producing a restart loop that looks like an application bug.
- Development values copied to production, where 128Mi and 100m meet real traffic for the first time.
- An HPA on CPU with missing or stale requests, so the autoscaler reports a metric error or scales on a fiction.
- VPA and HPA fighting over the same metric, producing oscillation that looks like a traffic problem.
- No ephemeral storage limit or quota, so a log storm evicts unrelated pods or a typo reserves a node.

The rules are short. Every container declares CPU and memory requests; every memory limit sits above the measured peak; CPU limits exist only where isolation is worth the throttling risk; requests are reviewed per environment; HPA and VPA never share a metric; and quota leaves room for a rollout surge. Guardrails catch what review misses, but measuring the workload is still the only way to size it.

## Verification checklist with pass criteria

Verify the admitted object, not the source manifest. The commands below read resources and QoS from the API server, compare live usage, and look for the two failure signatures that matter. Pipe the JSON through the [JSON formatter](/tools/json-formatter) when a nested path is easier to inspect by hand.

```bash
# 1. Read admitted resources and the derived QoS class
kubectl get pod -n prod -l app=checkout -o json | jq '.items[] | {name: .metadata.name, qos: .status.qosClass, containers: [.spec.containers[] | {name, resources}]}'

# 2. Compare live usage with requests and limits
kubectl top pod -n prod -l app=checkout --containers

# 3. Find restarts and OOMKilled evidence
kubectl get pod -n prod -l app=checkout -o jsonpath='{range .items[*]}{.metadata.name}{" restarts="}{.status.containerStatuses[*].restartCount}{"\n"}{end}'
kubectl describe pod -n prod -l app=checkout | grep -E 'QoS Class|Limits|Requests|OOMKilled|Last State'
```

Treat a check as passed only when every row below holds:

| Check | How to verify | Pass criterion |
| --- | --- | --- |
| Requests declared | Admitted pod spec | CPU and memory requests on every container, including sidecars |
| Memory headroom | Peak working set over two weeks | Limit at least 20% above peak; zero OOMKilled |
| CPU behavior | cAdvisor throttling metrics at peak | Throttled-period ratio below 10%, or no CPU limit by design |
| QoS class | `status.qosClass` | Matches the intended class for the workload |
| Autoscaler health | `kubectl get hpa` conditions | CPU target computable; no missing-request or metric errors |
| Quota headroom | `kubectl describe resourcequota` | Enough room for `maxSurge` plus one failure |
| Ephemeral storage | Pod status and node disk metrics | No eviction from ephemeral storage; logs rotated and bounded |

Resource configuration is code, and it deserves the same review. A value without a measurement is a guess; a value without an owner will drift; a value never verified in production is not yet true.

## Frequently asked questions

### What happens when I set a limit but no request?

Kubernetes copies the limit into the request at admission when no LimitRange supplies a default. The pod is then scheduled as if it needed its full burst, which lowers density and hides the real requirement; a 2 CPU limit becomes a 2 CPU reservation even if the process uses 100m.

### Should production containers have CPU limits?

Only when isolation is worth the latency risk. A CPU limit is enforced per 100 ms CFS period, so bursty services get throttled even when average usage is low. Many teams keep CPU requests, rely on namespace quotas and node autoscaling, and omit CPU limits; if you keep one, leave at least 1.5-2x headroom over peak usage and watch throttling metrics.

### Why is a pod OOMKilled when memory usage looked below the limit?

Because the cgroup working set includes active page cache, runtime overhead, thread stacks, and off-heap allocations that RSS-based dashboards miss. Sampling can also miss a short spike during cache warm-up or a large request. Compare the peak working set over a full traffic cycle, add 20-30% headroom, and check JVM or Go runtime settings before raising the request.

### Can HPA and VPA run on the same workload?

Not on the same metric. VPA changes requests, HPA divides usage by requests, and the two feedback loops oscillate: higher requests lower reported utilization, HPA scales in, utilization rises, and the cycle repeats. Use VPA in recommendation mode to set requests, and run HPA on a different signal such as requests per second or queue depth.

### Does a Guaranteed QoS class prevent eviction?

No. It gives the pod the most favorable eviction order and OOM score, but a Guaranteed container with a limit below its real usage is still OOMKilled by its own cgroup, and node-level failures can still take it down. Guaranteed buys priority and a fixed reservation, not immunity; the limit still has to be correct.

## References

- [Kubernetes: Resource Management for Pods and Containers](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/)
- [Kubernetes: Pod Lifecycle](https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/)
- [Kubernetes: Pod Quality of Service Classes](https://kubernetes.io/docs/concepts/workloads/pods/pod-qos/)
- [Kubernetes: Horizontal Pod Autoscaling](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/)

---

- Canonical: https://www.jsonmind.com/guides/kubernetes-resource-limits
- Locale: en
- Published: 2026-11-17
- Updated: 2026-11-17
- Tools: kubernetes-yaml, yaml-formatter, json-formatter