Kubernetes resource requests and limits determine how workloads are scheduled, protected, throttled, and scaled. This practical checklist explains how to choose initial CPU and memory values, configure the Horizontal Pod Autoscaler (HPA), diagnose common failures, and validate changes safely in production.
Overview
Resource requests describe the amount of CPU and memory a container needs for scheduling purposes. Kubernetes uses requests when deciding whether a node has enough allocatable capacity for a Pod. Requests also provide the baseline used by HPA resource utilization calculations.
Resource limits define an upper boundary for a container. CPU is compressible: when a container reaches its CPU limit, it can be throttled rather than terminated. Memory is not compressible. If a container exceeds its memory limit, it may be terminated with an out-of-memory (OOM) result. Node-level memory pressure can also cause Kubernetes to evict Pods.
Requests and limits are independent settings. A request that is too low can make a workload appear efficient while creating contention or misleading autoscaling signals. A limit that is too low can cause throttling or OOM kills. A limit that is too high can reduce scheduling flexibility and leave capacity unused.
| Item | What it controls | Typical symptom when misconfigured |
|---|---|---|
| CPU request | Scheduling reservation and HPA utilization baseline | Pods remain Pending, or HPA scales unexpectedly because utilization is calculated against a small baseline |
| Memory request | Scheduling reservation and relative priority during memory pressure | Pods are packed too tightly or are evicted during node pressure |
| CPU limit | Maximum CPU entitlement enforced by the runtime | Latency increases, work queues grow, or CPU throttling appears |
| Memory limit | Maximum memory available to the container | Container restarts with an OOMKilled reason |
| QoS class | Relative treatment when a node is under resource pressure | Unexpected eviction order or lower resilience for BestEffort workloads |
Kubernetes assigns each Pod a quality-of-service (QoS) class. A Pod is Guaranteed when every container has CPU and memory requests and limits, and each request equals its corresponding limit. A Pod is BestEffort when no container has requests or limits. Other Pods are Burstable. QoS is useful context, but it does not replace measuring actual usage or setting appropriate priorities and disruption controls.
Checklist by scenario
For a new workload
- Identify the workload shape. Separate steady services, batch jobs, queues, APIs, and memory-heavy processes. A single policy rarely fits all of them.
- Measure before tuning. Run representative traffic and record CPU usage, working-set memory, restart counts, latency, queue depth, and throttling where available. Include startup, warm-up, cache growth, scheduled jobs, and traffic spikes.
- Set an initial request. Use a value that reflects sustained normal usage and leaves room for ordinary variation. The request should be large enough to support reliable scheduling, not merely the average from a quiet test.
- Set memory conservatively. Memory usage tends to be less forgiving than CPU. Account for runtime overhead, caches, native allocations, and startup peaks before choosing the limit.
- Choose CPU limits deliberately. If predictable CPU bursting matters, a strict CPU limit may create throttling during short peaks. Test the effect of a limit rather than copying a default value without evidence.
- Check all containers. Sidecars, agents, proxies, and init containers affect Pod resource accounting. Review their requests and limits as well as those of the main application.
A starting manifest might look like this:
apiVersion: apps/v1
kind: Deployment
metadata:
name: api
spec:
replicas: 2
selector:
matchLabels:
app: api
template:
metadata:
labels:
app: api
spec:
containers:
- name: api
image: example/api:1.0
resources:
requests:
cpu: "250m"
memory: "256Mi"
limits:
cpu: "1"
memory: "512Mi"
These values are examples, not universal recommendations. Replace them with measurements from your workload. Treat a manifest as a testable hypothesis and revise it as evidence improves.
For an HPA-controlled service
- Confirm that the cluster exposes the resource metrics required by your autoscaling configuration. A commonly used implementation is
metrics-server, but installation and compatibility depend on the cluster environment. - Use a current autoscaling API supported by your cluster, commonly
autoscaling/v2, and verify the API version before applying examples. - Define CPU or memory requests for every container whose resource utilization you intend to use. Utilization is calculated relative to the requested amount; without a meaningful request, the signal may be unavailable or misleading.
- Set sensible minimum and maximum replica counts. The minimum should cover normal availability and rollout needs; the maximum should reflect capacity, downstream limits, and cost constraints.
- Choose a target from observed behavior. A target that leaves no room for bursts may cause frequent scaling; one that is too high may allow latency or queue depth to deteriorate before new Pods arrive.
- Validate scale-up and scale-down separately. Scale-up tests should confirm that capacity arrives before the service becomes unhealthy. Scale-down tests should confirm that removing replicas does not create a recovery loop.
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: api
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: api
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
For a noisy-neighbor or capacity incident
- Check whether Pods are Pending because node allocatable capacity is smaller than their requests.
- Compare requested resources with actual usage at the namespace, workload, and node levels.
- Inspect Pod events, container termination reasons, node conditions, and memory pressure.
- Look for CPU throttling, memory growth, restart loops, and saturation in dependent services.
- Review whether a sidecar, daemon, batch job, or newly deployed version changed the resource profile.
- Adjust requests and limits through a controlled rollout; do not solve a capacity problem by removing all limits without understanding the blast radius.
What to double-check
Requests versus usage: A request is not a performance guarantee in every sense. It influences placement and accounting, while application performance also depends on node contention, CPU management, storage, network, and dependencies.
Memory measurement: Review the metric definition used by your monitoring system. Working-set memory, RSS, heap, page cache, and container limit usage are not interchangeable. Use the signal that best explains eviction and OOM behavior, and pair it with application-level memory metrics.
HPA signal quality: Resource-based HPA works best when requests represent a meaningful workload baseline. For queue workers or request-driven applications, custom or external metrics such as queue depth, request rate, or latency may better represent demand, subject to the metrics adapter and API configuration available in your cluster.
Cluster capacity: Sum requests across Pods, account for system and daemon overhead, and compare the result with node allocatable resources rather than raw node capacity. If you use cluster autoscaling, verify that its node groups can provide the requested CPU and memory shapes.
Policy and admission: Namespace-level policies may inject defaults or enforce minimum and maximum values. Check LimitRanges, ResourceQuotas, admission controllers, and deployment templates before concluding that the manifest is the only source of truth.
For broader operational context, pair this review with a Kubernetes cluster upgrade checklist and your cloud monitoring design. Monitoring choices across providers are discussed in this cloud monitoring comparison.
Common mistakes
- Copying values from another service. Two services with the same language or replica count can have very different memory and CPU profiles.
- Setting requests equal to tiny averages. This may improve apparent packing while increasing contention and causing HPA to react to an unhelpful baseline.
- Using memory limits as a leak strategy. A limit can contain damage, but repeated OOM kills should lead to investigation of heap growth, caches, traffic, and workload behavior.
- Assuming a CPU limit is harmless. CPU throttling can show up as latency or queue growth even when average CPU usage looks moderate.
- Testing only at steady state. Include deployments, cold starts, cache warm-up, failover, peak traffic, and downstream slowness.
- Watching only Pod CPU and memory. Correlate resource metrics with application latency, errors, throughput, restarts, evictions, and node conditions.
- Changing every workload at once. Use a canary or a limited rollout so that a bad resource profile is easy to identify and reverse.
When to revisit
Resource tuning is a recurring engineering task, not a one-time deployment step. Revisit requests, limits, and HPA settings before seasonal planning cycles, after significant traffic or data-volume changes, and whenever workflows or tools change. Also review them after a Kubernetes upgrade, a node-size change, a runtime upgrade, a sidecar or observability change, or a move to a different metrics implementation.
A practical review cycle is:
- Export a representative period of usage and failure data.
- Compare actual usage, configured requests, limits, and node allocatable capacity.
- Identify the largest gaps: Pending Pods, throttling, OOM kills, evictions, or excess reserved capacity.
- Change one class of workload at a time and record the expected outcome.
- Validate during normal traffic and a controlled peak, then keep or roll back the change.
- Document the reasoning, date, workload version, metrics used, and next review trigger.
Keep this checklist with the service’s deployment process. When a workload launches, a cluster changes, or an incident reveals a new resource pattern, repeat the measurement and validation steps rather than relying on inherited values.