Kubernetes resource requests and limits affect scheduling, autoscaling, cost, and reliability. This practical guide explains how to choose CPU and memory values from observed workload behavior, then provides scenario checklists for tuning, diagnosing throttling or OOMKilled events, and deciding when to revisit your settings.
Overview
A container resource request is the amount of CPU or memory Kubernetes uses when making scheduling and capacity decisions. A limit is the maximum amount a container is allowed to consume under the configured resource model. Resources are specified per container, so a pod with several containers needs a deliberate budget for each one.
Requests should represent normal demand with enough room for expected variation. If a request is too low, the scheduler may place too much work on a node, and autoscaling signals can understate the capacity required by the application. If it is too high, pods may remain pending despite available practical capacity, and the cluster may scale out unnecessarily.
CPU and memory behave differently. CPU is a compressible resource: a container can usually receive less CPU time or be throttled when contention occurs. Memory is not compressible in the same way. When a container reaches its memory limit, it may be terminated, commonly appearing as OOMKilled. A pod can also be evicted when a node is under memory pressure, even if the container has not reached its own limit.
There is no universal ratio between requests and limits. Start with measurements from representative traffic, load tests, and background activity. Treat the values as operational hypotheses, then validate them through dashboards, deployment tests, and incident reviews.
A practical starting table
| Workload pattern | Request guidance | Limit guidance | Watch closely |
|---|---|---|---|
| Steady web or API service | Typical sustained usage plus ordinary variation | Set a tested ceiling if CPU isolation or memory protection is required | Latency, CPU throttling, memory growth, restart rate |
| Burst-heavy worker | Baseline consumption, not the largest short spike | Allow tested bursts without risking node-wide contention | Queue depth, processing time, throttling, concurrency |
| Memory-sensitive service | Observed working set plus headroom for caches and traffic variation | Above the normal peak, but below a level that could destabilize the node | Working set, heap, cache, RSS, OOM events |
| Batch or scheduled job | Resource use during a representative run | Enough for the largest expected input and safe failure behavior | Runtime, retries, temporary files, input size |
| Sidecar or agent | Measure it separately from the application | Prevent noisy collection or proxy behavior from consuming the pod budget | Log volume, request rate, buffers, restarts |
Checklist by scenario
For a new deployment
- List every container, including proxies, exporters, init containers, and admission-injected sidecars.
- Record expected traffic, concurrency, input sizes, startup work, and background tasks.
- Run a representative test rather than sizing from an idle container or a single developer laptop.
- Set explicit CPU and memory requests for each production container. Add limits where a tested ceiling is useful, especially for memory-sensitive workloads.
- Check that the combined pod request fits the node sizes and namespace quotas available to the workload.
- Deploy gradually and compare latency, throughput, restarts, throttling, and memory trends with the test baseline.
For a service that is slow or CPU-throttled
- Confirm whether the problem is CPU saturation, CPU throttling, downstream latency, lock contention, or an application-level queue.
- Compare actual CPU usage with both the request and limit. A low request can make utilization-based autoscaling appear high; a restrictive limit can cap burst capacity.
- Inspect throttling over time, not just a single sample. Correlate it with tail latency and traffic volume.
- Test a higher CPU limit or a different request in a controlled rollout. Do not remove a limit solely because a dashboard shows brief spikes.
- Review replica count and autoscaling targets. More CPU per pod is not always preferable to more replicas.
For a container terminated with OOMKilled
- Identify which container was killed and distinguish a container memory-limit event from node-pressure eviction.
- Compare the limit with peak working set, heap or runtime settings, caches, buffers, and native memory.
- Check whether the workload changed: larger payloads, more concurrency, a new dependency, a longer queue, or a rollout with different configuration.
- Increase the limit only after checking node capacity and cluster quotas. A larger limit can allow one pod to consume more memory without fixing a leak.
- Set an appropriate request as well. A high limit with a very low request can produce misleading placement and capacity assumptions.
- Capture a heap profile, allocation profile, or application diagnostic where practical, then verify the fix with a repeatable workload.
For autoscaling
Check which signal your autoscaler uses and how resource requests influence that signal. CPU utilization is commonly interpreted relative to the CPU request, so changing the request can change scaling behavior even when the application has not changed. Validate scale-up delay, stabilization, pod startup time, and scale-down behavior together. For memory, determine whether usage reflects durable demand, a cache, or a leak before using it as a scaling signal.
What to double-check
- Units:
MiandGidescribe binary memory units, while CPU values can be expressed in cores or millicores, such as500mfor half a CPU. - Per-container totals: A pod's effective budget is affected by all of its containers. An injected proxy can materially change placement and utilization.
- Quality of Service: The relationship between requests and limits influences the pod's QoS classification and can affect eviction ordering. Confirm the result from the complete manifest, not one container in isolation.
- Node allocatable capacity: Nodes reserve resources for the operating system and Kubernetes components. Compare requests with allocatable capacity, not just the advertised machine size.
- Namespace policy: Resource quotas, limit ranges, and admission policies may add defaults or reject manifests. Inspect the applied object in the cluster.
- Probes: A liveness probe that is too aggressive can restart a CPU-starved or startup-heavy process. Use startup and readiness behavior to prevent slow initialization from being treated as failure.
- Rolling updates: During a rollout, old and new replicas can coexist. Verify that temporary capacity fits the cluster and that disruption settings do not conflict with the rollout plan.
- Observability: Collect container restarts, termination reasons, working set, CPU usage, throttling, pod pending time, node pressure, and application latency. A single CPU or memory graph is not enough.
For release safety, pair resource changes with a measured rollout strategy. The guidance in Blue-Green vs Canary Deployments can help structure that comparison, while an SLO and error budget review can connect performance changes to reliability decisions.
Common mistakes
- Copying values between services: Similar-looking applications can have very different heaps, concurrency, sidecars, and traffic patterns.
- Sizing from averages: Average usage hides startup bursts, scheduled work, and tail behavior. Use percentiles and inspect peak periods.
- Setting memory limits too close to normal usage: Small increases in payload size or cache occupancy can become repeated OOM events.
- Removing CPU limits as a first response: This may hide throttling while increasing contention for other workloads. Test the trade-off and protect node capacity.
- Confusing OOMKilled with node eviction: The remedy may be an application memory fix, a larger request, different placement, or more node capacity—not simply a higher limit.
- Ignoring init containers: Large migration or setup steps can require temporary resources that differ from the steady-state application.
- Changing requests without reviewing autoscaling: A new request can alter utilization percentages, replica decisions, and cluster autoscaler behavior.
- Editing live manifests without recording the reason: Keep the measurement, hypothesis, change, and result with the deployment configuration so the next review has context.
When to revisit
Review Kubernetes CPU and memory settings before seasonal planning cycles, major traffic events, and capacity reviews. Revisit them after a node-size change, a runtime or dependency upgrade, a new sidecar, a database or cache change, a concurrency adjustment, or a significant application release.
Also schedule a review after any incident involving pending pods, node pressure, throttling, repeated restarts, slow scaling, or OOMKilled containers. Start with the incident window, compare resource behavior before and after the event, and update the manifest only after identifying the likely constraint.
Use this short runbook each time:
- Export representative usage and reliability data for the relevant workload period.
- Write down the current request, limit, replica, probe, quota, and autoscaling configuration.
- Choose one change at a time where possible, and define success criteria such as lower tail latency or no memory termination.
- Roll out progressively and watch both the target service and neighboring workloads.
- Record the result, update the infrastructure configuration, and set the next review trigger.
Resource tuning is not a one-time calculation. It is a capacity-management loop: measure actual behavior, make the smallest defensible adjustment, validate it under realistic load, and revisit it when the workload or cluster changes.