Kubernetes resource requests, limits, and Horizontal Pod Autoscaler (HPA) settings work together, but they solve different problems. This guide shows how to size CPU and memory from observed workload behavior, configure practical defaults, and tune autoscaling without creating throttling, OOMKilled containers, or unstable replica counts.
Overview
A Kubernetes request is the amount of CPU or memory a container asks the scheduler to reserve when placing a Pod. A limit is the maximum resource usage Kubernetes allows for that container. Requests influence scheduling and are also used by utilization-based HPA calculations. Limits influence runtime enforcement.
CPU and memory behave differently:
| Setting | CPU behavior | Memory behavior | Main operational purpose |
|---|---|---|---|
| Request | Used for scheduling and utilization calculations | Used for scheduling and utilization calculations | Reserve realistic capacity and give autoscaling a meaningful baseline |
| Limit | Can restrict CPU through throttling when usage reaches the limit | When exceeded, the container may be terminated with an OOMKilled result | Set an intentional upper boundary, not an arbitrary safety number |
| No request | Placement and HPA behavior may not match workload needs | Placement and eviction risk are harder to reason about | Generally unsuitable for production workloads |
The goal is not to maximize or minimize every value. The goal is to give the scheduler, kubelet, and HPA enough accurate information to make safe decisions. A request that is too high can leave capacity stranded and cause unnecessary scale-out. A request that is too low can make HPA utilization appear high, trigger extra replicas, or allow Pods to compete for node resources. A memory limit that is too low can cause avoidable container restarts, while no meaningful limit can make node-level pressure more difficult to contain.
For broader operational context, pair this work with a Kubernetes production deployment checklist and review whether a managed or self-managed operating model fits your team in this managed Kubernetes comparison.
How to estimate
Use measurements from representative traffic rather than choosing familiar round numbers. Collect at least these signals for each container:
- CPU usage over normal, busy, and peak periods.
- Working-set memory and, where available, the container's restart and OOM history.
- Request rate, queue depth, latency, error rate, and batch duration.
- Current replica count and the amount of unused capacity at the node and cluster levels.
- Startup behavior, including initialization spikes and cache-warming requirements.
A practical first estimate is:
CPU request: choose a value that covers sustained normal usage while leaving room for ordinary variation. If a service normally uses 180 millicores and regularly reaches 300 millicores during expected traffic, a request near the sustained operating range may be reasonable, but validate it against latency and HPA behavior rather than treating the peak as an automatic request.
Memory request: start from the observed working set during representative load and add room for expected application variation, caches, runtime behavior, and short-lived bursts. Memory should not be sized from an average alone. A workload with a low average and occasional large peaks can still be unstable if its request or limit ignores those peaks.
Memory limit: set it above the expected working set and test the application near that boundary. The limit should be high enough to avoid normal traffic causing OOMKilled events, but low enough that a runaway process is contained before it threatens the node. If the application legitimately needs more memory, increasing the limit without checking node capacity only moves the failure elsewhere.
For HPA, the common resource-utilization target is calculated as actual usage relative to the configured request. That means changing a CPU request changes the meaning of the same HPA target. For example, a Pod using 400 millicores with a 500-millicore request is at roughly 80% CPU utilization; with a 1,000-millicore request, it is roughly 40%. Do not retune the HPA target independently from requests without checking the resulting behavior.
Inputs and assumptions
Before changing a Deployment, record the assumptions behind the recommendation. A useful sizing worksheet includes:
| Input | What to record | Why it matters |
|---|---|---|
| Workload type | API, worker, batch job, consumer, or scheduled task | Different workloads have different latency and burst patterns |
| Traffic window | Normal, busy, and peak observation periods | A short test can miss daily or weekly variation |
| CPU profile | Sustained use, bursts, throttling, and latency correlation | Helps distinguish genuine demand from an unsuitable CPU limit |
| Memory profile | Working set, peak use, restarts, and OOMKilled events | Memory pressure is not corrected by CPU autoscaling |
| Scaling signal | CPU, memory, custom, or external metric | Choose a signal that reflects the workload's bottleneck |
| Capacity constraints | Node size, allocatable resources, quotas, and disruption rules | More replicas require schedulable cluster capacity |
Requests and limits apply at the container level, while scheduling decisions consider the Pod's combined requests. Include sidecars such as proxies, log shippers, and monitoring agents in the capacity calculation. A main application can appear correctly sized while the Pod remains unschedulable because an overlooked sidecar has a large request.
Also check whether the metrics pipeline is healthy. HPA decisions depend on metrics being available and timely. Missing or delayed metrics, a target that does not represent user demand, or a scale-up workload with long startup times can produce behavior that looks like a resource-sizing problem. Confirm observability before repeatedly changing values.
Worked examples
A baseline Deployment
The following example is a starting point, not a universal recommendation. The values should be replaced after observing the application under representative load.
apiVersion: apps/v1
kind: Deployment
metadata:
name: checkout-api
spec:
replicas: 3
selector:
matchLabels:
app: checkout-api
template:
metadata:
labels:
app: checkout-api
spec:
containers:
- name: app
image: example/checkout-api:1.0.0
resources:
requests:
cpu: "250m"
memory: "512Mi"
limits:
cpu: "1000m"
memory: "1Gi"
This configuration reserves 250 millicores and 512 MiB per container for scheduling. CPU can use more than its request when node capacity allows, up to the configured limit. Memory is given a defined boundary, but the limit should be validated with load testing and production observations. If the application reaches 1 GiB during ordinary operation, raising the limit alone is not sufficient; review the request, node capacity, application memory behavior, and replica strategy together.
An HPA using CPU and memory
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: checkout-api
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: checkout-api
minReplicas: 3
maxReplicas: 12
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 75
Multiple resource metrics should be selected deliberately. CPU may represent request pressure for a compute-heavy API, while memory may reflect a leak or cache-growth problem that adding replicas does not solve. If either signal causes sustained scale-out, investigate the cause rather than assuming the HPA needs a higher target. For some services, a request-rate, queue-depth, or latency-based metric is more useful than CPU or memory alone.
When tuning this example, examine four outcomes:
- Throttling: CPU usage reaches the limit and application latency rises. Test whether the limit is unnecessarily restrictive, whether the code is CPU-bound, or whether more replicas are needed.
- OOMKilled: memory usage reaches the limit and the container restarts. Check for leaks, cache growth, traffic changes, and runtime configuration before increasing the limit.
- Underutilization: requests remain far above observed use. Lower them cautiously after checking peak periods, disruption requirements, and scheduling headroom.
- Replica instability: the HPA repeatedly scales up and down. Look for noisy metrics, long startup times, insufficient stabilization settings, changing traffic, or requests that make utilization overly sensitive.
Make one controlled change at a time where possible. Compare resource use with service-level indicators such as latency, availability, queue age, and error rate. A lower CPU graph is not an improvement if requests time out, and a higher replica count is not a fix if every Pod is waiting on the same database.
When to recalculate
Revisit resource sizing and HPA settings after a major deployment, traffic-pattern change, runtime upgrade, dependency change, or capacity review. Also review them after any OOMKilled event, sustained throttling, unexpected replica growth, scheduling failure, or notable latency regression.
As a routine practice, compare recommendations with observed usage during monthly resource and cost reviews. Recalculate after adding a sidecar, changing log volume, enabling a cache, modifying concurrency, or moving to different node types. A new container image can change memory behavior even when application functionality appears unchanged.
Use this action plan:
- Export a representative observation window covering normal and busy traffic.
- Separate application containers from sidecars and inspect Pod-level scheduling requirements.
- Check CPU throttling, memory peaks, restarts, OOMKilled status, pending Pods, and HPA events.
- Update requests first when the scheduling or utilization baseline is wrong.
- Adjust limits only after testing the failure boundary and confirming node capacity.
- Change HPA targets, minimums, maximums, or metrics only after validating the new resource baseline.
- Observe the result through both infrastructure metrics and user-facing service indicators.
Keep the measured assumptions with the Deployment or its infrastructure-as-code definition so the next review has context. Resource tuning is not a one-time optimization: it is a reliability control that should be revisited whenever workload behavior, traffic, or cluster capacity changes.