Choosing Kubernetes CPU and memory requests and limits is a measurement problem, not a copy-and-paste exercise. This guide gives you a reusable workflow for sizing workloads, interpreting QoS behavior, investigating OOMKilled containers and CPU throttling, and revisiting values as traffic and application behavior change.
Overview
Kubernetes resource requests describe the amount of CPU or memory a container is expected to need. The scheduler uses requests when deciding whether a Pod can fit on a node. Requests therefore affect placement, bin packing, and the capacity your cluster must reserve for a workload.
Limits define an upper boundary enforced by the container runtime and Kubernetes. A CPU limit can cause a container to be throttled when it tries to use more CPU than the configured allowance. A memory limit is different: memory cannot be safely throttled in the same way, so a container that exceeds its memory limit may be terminated and reported as OOMKilled.
Start with observed behavior rather than guessing. For each workload, record its normal usage, startup behavior, steady-state usage, peak usage, latency target, restart impact, and scaling policy. A small web service, a batch job, a JVM application, and a memory-heavy cache should not all receive the same sizing strategy.
A simple sizing worksheet
- CPU request: baseline CPU needed to remain responsive during ordinary load.
- CPU limit: a deliberate ceiling, or no limit where your platform policy allows that choice and node-level protection is understood.
- Memory request: the working set needed for normal operation, including runtime overhead and expected cache use.
- Memory limit: a boundary above the expected working set that still protects node capacity and exposes runaway growth.
- Evidence: measurements from representative traffic, startup tests, load tests, and production observations.
- Review condition: the signal that will trigger a new sizing review, such as sustained throttling, memory growth, or a changed traffic profile.
CPU values are commonly expressed in cores or millicores; for example, 500m represents half a CPU. Memory should use an explicit unit such as Mi or Gi. Keep units consistent in manifests and reviews so that a value is not misread during an incident.
Checklist by scenario
For a stateless web or API service
- Measure CPU and memory during startup, warm-up, ordinary traffic, and a representative peak.
- Set the CPU request high enough to support the service's latency objective under normal load.
- Set the memory request above the stable working set, including framework, runtime, and connection-pool overhead.
- Check whether a CPU limit introduces throttling during short bursts. Compare throttling data with request latency before deciding whether the limit is useful.
- Set a memory limit only after testing the service's largest expected working set and understanding its failure behavior.
- If using an HPA based on CPU utilization, remember that utilization is evaluated relative to the CPU request. Changing the request changes the meaning of the target.
For a batch job or worker
- Size the request for the concurrency and throughput required by the job, not merely for its idle footprint.
- Decide whether completion time or cluster efficiency is the priority.
- Test the largest expected input, including temporary files, in-memory buffers, and parallel workers.
- Use a memory limit that prevents an abnormal input or leak from consuming node capacity, but leave enough room for legitimate peaks.
- Check retry behavior. A memory-related termination can repeatedly restart a job and create additional load.
For a memory-intensive service
- Separate application heap, native memory, buffers, caches, and sidecar usage when measuring.
- For managed runtimes, configure the runtime with awareness of the container's available memory rather than assuming the host has unlimited capacity.
- Compare the container's working set with its configured memory request and limit over a long enough period to expose gradual growth.
- Investigate whether a cache can be bounded or evicted before simply raising the limit.
- Check node allocatable memory and neighboring workloads before increasing requests across a fleet.
For a sidecar-heavy Pod
- Measure each container separately. A healthy application can still be evicted or terminated because a logging, proxy, or metrics sidecar is undersized.
- Include all container requests when evaluating the Pod's scheduling footprint.
- Give critical sidecars enough CPU for their own work, especially during log bursts or connection churn.
- Confirm that the sidecar's limits do not create a bottleneck or unexpected restarts.
What to double-check
QoS class
Kubernetes assigns a Pod a QoS class from its resource configuration. A Pod with no requests or limits is generally BestEffort. A Pod with some resource configuration but not the fully matching CPU and memory configuration across its containers is generally Burstable. A Pod is Guaranteed when every container has CPU and memory requests and limits set, with each request equal to its corresponding limit.
QoS is one input into resource-pressure behavior; it is not a substitute for correct sizing. Check the result with kubectl get pod <pod> -o jsonpath='{.status.qosClass}', and review the actual requests and limits in the rendered manifest rather than relying on a source template.
Observed usage versus allocation
kubectl top pod can provide a quick view when metrics are available, but a single observation is not a sizing study. Compare samples across deployment, quiet periods, normal traffic, peak traffic, and recovery after a dependency or node event. Look at percentiles and trends where your observability system supports them.
CPU throttling and memory pressure
High CPU usage is not automatically a problem. Investigate throttling, run-queue pressure, request latency, and saturation together. For memory, inspect container termination reasons, Pod events, node pressure, and application logs. An OOMKilled status may indicate that a container exceeded its limit, but it can also be part of a broader node-capacity or memory-growth problem.
Autoscaling interactions
Resource sizing and autoscaling are connected. A Horizontal Pod Autoscaler using resource utilization depends on requests, so an artificially low request can make utilization appear high and cause early scaling, while an overly high request can delay scaling. Validate scaling behavior with realistic load and review whether the selected metric represents user demand better than CPU or memory alone.
Common mistakes
- Copying values between services: Similar container images can have very different traffic, concurrency, and runtime behavior.
- Using limits as targets: A limit is a boundary, not a performance objective. A service that regularly approaches its memory limit needs investigation.
- Setting memory requests too low: This may improve apparent packing while increasing eviction risk or producing unstable placement decisions.
- Ignoring startup peaks: Compilation, cache warming, migrations, and connection establishment can temporarily require more resources than steady state.
- Assuming CPU limits are harmless: CPU throttling can show up as latency or timeout problems even when average CPU usage looks acceptable.
- Measuring only the application container: Sidecars, init containers, and runtime overhead also matter, especially in small nodes.
- Tuning during an incident without recording the baseline: An emergency increase may restore service but conceal the underlying leak, traffic change, or inefficient query.
- Changing requests without checking autoscaling: A resource change can alter HPA behavior and cluster capacity requirements at the same time.
For broader Kubernetes troubleshooting, pair resource checks with node conditions, events, scheduling failures, and dependency health. Resource configuration is only one part of a reliable container operations workflow. Network behavior may also need separate validation using a Kubernetes NetworkPolicy connectivity checklist.
When to revisit
Review resource sizing before seasonal planning cycles, after a major traffic or feature change, and whenever workflows or tools change. Revisit it after a Kubernetes version upgrade, a runtime upgrade, a new sidecar, a node-pool change, or a change to HPA or VPA policy. It is also worth reviewing after repeated OOMKilled events, sustained CPU throttling, unexpected evictions, slow scheduling, or a rising node count without corresponding workload growth.
Use this closing checklist before merging a resource change:
- Render the final manifest and verify every container's request and limit.
- Record the measurements and traffic conditions behind the proposed values.
- Check the Pod's QoS class and the effect on node bin packing.
- Test startup, normal load, peak load, and failure recovery.
- Review HPA, VPA, cluster autoscaler, and Pod disruption behavior together.
- Deploy gradually where possible, then compare latency, throttling, restarts, memory growth, and scheduling results.
- Write down the next review trigger so the values are treated as operating assumptions, not permanent constants.
Keeping this worksheet with the workload's deployment documentation makes Kubernetes resource sizing easier to repeat and safer to adjust as the application and its operating environment evolve.