Kubernetes resource requests and limits are not one-time numbers copied from a template. They are operating assumptions that affect scheduling, autoscaling, reliability, and infrastructure cost. This guide provides a repeatable workflow for sizing CPU and memory, interpreting usage and failure signals, reviewing workload examples, and deciding when to revise the configuration.
Overview
A resource request represents the amount of CPU or memory Kubernetes uses when making scheduling decisions. A resource limit sets a ceiling for a container's consumption, subject to the behavior of the resource and the runtime environment. CPU and memory therefore require different reasoning:
- CPU is compressible. When a container reaches its CPU limit, it may be throttled rather than terminated. Excessive throttling can increase latency and reduce throughput.
- Memory is not compressible in the same way. A container that exceeds its available memory can be terminated, producing an
OOMKilledresult or another memory-related failure. - Requests influence bin packing and capacity planning. Inflated requests can leave allocatable capacity unused; undersized requests can make nodes appear capable of hosting more work than they can reliably support.
- Limits protect a workload and its neighbors from unbounded consumption, but a limit is not automatically a performance target. Setting it too close to normal usage can create avoidable throttling or memory failures.
Start by treating each workload as a separate sizing problem. A stateless API, a batch worker, and a stateful database have different traffic patterns, startup behavior, failure costs, and tolerance for interruption. Kubernetes QoS classification also depends on how requests and limits are specified, so review the resulting class and its implications in the context of your cluster rather than selecting values in isolation.
How to estimate
Use observed behavior wherever possible, then validate the result under representative load. The following workflow works for both new and existing workloads.
- Define the workload boundary. Record the container image, number of replicas, startup tasks, sidecars, scheduled jobs, and any initialization or migration steps. Measure each container separately; a sidecar can consume enough memory to distort the application’s apparent profile.
- Choose representative scenarios. Include normal traffic, a realistic peak, cold startup, cache warm-up, background work, and expected concurrency. A short average test is not sufficient for memory sizing because leaks, queues, and large requests often appear over time.
- Collect usage distributions. Record CPU and memory over a sustained observation window. Capture typical usage, a high percentile selected by your team, and the maximum observed value. The exact percentile is a policy choice: latency-sensitive services generally need more protection from bursts than low-priority batch work.
- Set the request from sustained demand. The request should cover the workload’s expected consumption closely enough to support scheduling and autoscaling decisions, while leaving room for other containers and system overhead on the node.
- Set the limit from a deliberate risk decision. For CPU, decide whether occasional bursts should be allowed or constrained. For memory, include headroom for known peaks and leave room for runtime overhead, buffers, and temporary allocations. Do not use a limit to conceal a leak or an unbounded queue.
- Test and inspect outcomes. Apply the values in a representative environment, then examine pending pods, throttling, restarts, OOM events, latency, queue depth, and node pressure. Revise one variable at a time when possible so the effect is easier to attribute.
A simple review model is:
headroom = configured value - observed peak
For requests, also compare aggregate demand with node allocatable capacity:
request utilization = sum of pod requests / node allocatable capacity
These are decision aids, not universal formulas. A low request-utilization ratio can indicate conservative scheduling, but it does not prove that a workload is safe to reduce. Likewise, a high observed peak may be a legitimate burst, a measurement artifact, or evidence of a defect.
Inputs and assumptions
Keep a sizing worksheet with one row per container. At minimum, record:
| Input | What to record | Why it matters |
|---|---|---|
| Workload type | API, worker, batch job, daemon, or stateful service | Determines burst behavior and failure tolerance |
| Replica or job count | Typical and maximum parallel instances | Converts per-pod values into cluster demand |
| CPU usage | Typical, high-percentile, and peak millicores | Supports request sizing and throttling analysis |
| Memory usage | Steady state, high-percentile, and peak bytes | Helps avoid OOM events and excessive reservation |
| Startup profile | Initialization CPU, memory, and duration | Prevents steady-state values from hiding startup failures |
| Traffic or work volume | Requests per second, queue rate, or records per job | Connects resources to a repeatable operating condition |
| Reliability target | Latency, completion time, or recovery expectations | Defines acceptable throttling and burst behavior |
Write assumptions beside every recommendation. For example: “Based on a load test at 200 requests per second, with three replicas, a five-minute warm-up, and a memory peak below the proposed limit.” This makes a later review much faster than relying on unexplained YAML values.
Do not confuse container requests with the full cost of running a pod. Nodes also need capacity for the operating system, kubelet, networking, logging, monitoring, storage components, and other platform services. Your cluster’s admission policies, node allocatable values, autoscaler configuration, and managed-service defaults may also affect the result. Verify those assumptions in the target environment.
For cost analysis, use a consistent internal proxy rather than inventing a universal price. For example, compare requested vCPU-hours and requested GiB-hours before and after a change, then apply the rates used by your cloud or FinOps team. This exposes the cost trade-off without assuming that every cluster has the same pricing model.
Worked examples
Stateless API
Suppose a three-replica API uses about 180–260 millicores per pod during normal traffic and reaches 420 millicores during a tested peak. Memory is usually 300 MiB and reaches 470 MiB during cache warm-up. A reasonable first review might place the CPU request near sustained demand, provide CPU burst room through the limit, and set the memory request near stable working usage with a limit above the tested peak.
The decision is not “choose a round number.” Confirm that three replicas fit on the intended nodes with other platform workloads, that the deployment remains schedulable during a rolling update, and that the service does not experience latency increases from CPU throttling. If the API scales on CPU utilization, changing the request also changes the autoscaling signal, so review replica behavior after the change.
Batch worker
A batch worker may use little CPU while waiting for input, then consume several cores during transformation. Its completion-time objective may justify a higher CPU limit than its request. Memory needs should be based on the largest expected batch or chunk, not only on the average job. Track queue age, processing time, retries, and failed jobs alongside container metrics. A low request can improve packing, but an overly restrictive limit can make the job miss its completion window.
Stateful workload
For a stateful service, resource sizing is only one part of capacity planning. Include cache behavior, compaction or checkpoint work, replication, storage latency, backup activity, and recovery time. A memory increase may improve performance but reduce the number of replicas that fit on a node. Test failover and restart behavior, and document whether a resource change requires a rolling restart or another operational step.
When troubleshooting, separate symptoms:
- OOMKilled or repeated memory restarts: compare the limit with the memory curve, inspect recent workload changes, and check for leaks, unbounded queues, large payloads, or runtime configuration issues before simply raising the limit.
- CPU throttling: compare throttled time with latency and throughput. If service objectives are affected, test a higher limit, a different request, more replicas, or application optimization.
- Pending pods: inspect requests against node allocatable capacity, affinity rules, taints, topology constraints, and other scheduling requirements. Reducing a request is not the only possible solution; adding capacity or changing placement may be safer.
When to recalculate
Make resource review a recurring engineering practice rather than an incident-only task. Recalculate after load tests, traffic growth, a major release, a runtime or base-image change, a node-pool change, autoscaler tuning, or an incident involving latency, throttling, OOM events, evictions, or pending pods. Also revisit values when a team changes concurrency, cache size, batch size, sidecars, logging, or observability agents.
A quarterly review is a practical baseline for stable services, with more frequent checks for rapidly changing workloads. At each review, compare:
- Configured requests and limits with recent usage distributions
- Headroom during tested and real production peaks
- Replica counts, pending time, evictions, restarts, and OOM events
- CPU throttling alongside latency and throughput
- Requested capacity and actual usage for cost analysis
- Autoscaler decisions and whether they match service objectives
Record the date, evidence window, workload version, assumptions, proposed change, expected reliability effect, and cost effect. Apply changes progressively, observe them, and keep a rollback path. Pair this review with broader platform checks such as the Kubernetes upgrade readiness checklist and, when image changes are involved, the Dockerfile review checklist.
The goal is not to find a perfect number. It is to maintain a transparent, evidence-based balance between schedulability, performance, resilience, and capacity cost—and to make the next revision easier than the last.