How to Right-Size Kubernetes CPU and Memory Requests
To right-size Kubernetes CPU and memory requests, start with measured usage instead of a guess copied from another service. A request tells the scheduler how much CPU and memory to reserve for a container. A limit sets the ceiling it may use. When requests are too high, pods sit unscheduled or nodes run half empty. When requests are too low, pods get throttled, evicted, or killed. The goal is a setting that matches how the workload behaves under real traffic, with enough headroom for normal peaks.
Right-sizing is not a one-time edit. Workloads change after a release or a traffic shift, so treat the first pass as a baseline and check it again after the next few deploys.
What Kubernetes Resource Requests and Limits Do
Kubernetes resource requests and limits control two different decisions. Requests drive scheduling: the scheduler only places a pod on a node that has enough unreserved capacity. Limits drive runtime enforcement: the kubelet throttles CPU past the limit and kills a container that passes its memory limit. That difference explains why the two values need separate reasoning. A request should reflect steady demand. A limit should reflect the highest usage you are willing to allow before the platform steps in.
| Setting | What it controls | If it is too low | If it is too high |
|---|---|---|---|
| CPU request | CPU reserved at scheduling time | Pods share too little CPU and contend under load | Nodes look full while CPU sits idle |
| CPU limit | Maximum CPU a container may use | CPU throttling slows responses under load | One pod can crowd out its neighbours |
| Memory request | Memory reserved at scheduling time | Pods get evicted when the node runs short | Fewer pods fit on each node than needed |
| Memory limit | Maximum memory a container may use | OOMKilled restarts when usage crosses the limit | A runaway container can starve the node before it is stopped |
CPU and memory also fail in different ways. CPU is compressible: throttling slows a container but keeps it alive. Memory is not compressible: once a container passes its memory limit, Kubernetes terminates it. That is why memory limits deserve more caution, especially for services that cache data in memory or hold large request payloads.
Measure Before You Change Anything
Do not edit requests until you can see current usage. Two sources cover most cases: live container metrics for a quick check, and a time-series store for trends across days and peaks. If you already monitor Kubernetes with Prometheus and Grafana, pull per-container CPU and memory usage over a window that includes a peak period and a quiet period. If you do not have that setup yet, kubectl top gives a point-in-time view, but it cannot show yesterday’s peak, so use it only as a starting point.
What to record for each container
- Typical CPU and memory usage during normal traffic, not just the average across idle nights.
- Peak CPU and memory usage during the busiest period in the window, plus what caused the peak.
- Restarts, throttling events, and OOMKilled events, with the time each one happened.
- Startup behaviour: some services use far more memory while warming a cache than they use once steady.
How long to observe
One quiet afternoon tells you little. Watch at least one full cycle of the workload: a weekday peak and a quiet period for a business service, or a full batch window for a job that runs on a schedule. Services with weekly traffic patterns need a week of data before you trust the peak. The Vertical Pod Autoscaler in recommendation mode can help here by suggesting values from observed history, but check its output against your own graphs before applying it.
How to Size Kubernetes CPU Requests
Kubernetes CPU requests use millicores, where 1000m equals one full CPU core. Start from observed usage: set the CPU request near the typical usage during normal traffic, not near the peak. The request reserves capacity, so tying it to the peak wastes node space for most of the day. Then set the CPU limit above the request to give the container room to burst during short spikes, and watch for throttling after the change. Sustained throttling under normal traffic means the limit is too tight or the request is too low for the node placement you get.
Watch node-level contention too. Two containers with generous limits can still contend when both spike at once. If latency rises under load without any container hitting its limit, spread pods across nodes or raise requests so the scheduler places them apart.
How to Size Kubernetes Memory Requests
Kubernetes memory requests work in bytes, usually written as Mi or Gi. Set the memory request near typical usage plus a margin for normal variation, and set the memory limit above the request to absorb peaks. The margin matters more than the exact number: a service that grows slowly over days because of a cache needs a limit that covers that growth, or it will restart on a schedule you did not plan.
When a container is OOMKilled, check the usage graph before raising the limit. A steady climb that never falls back points to a leak or an unbounded cache, and raising the limit only delays the restart. A sharp spike tied to a specific request type or batch points to a peak you should size for. Fix the cause where you can, and size the limit for the peak you cannot remove.
Memory sizing also interacts with probes. A container that is slow to start because it loads a large dataset can fail a readiness check before it is ready, which looks like a sizing problem but is a probe problem. If restarts cluster around startup, check your liveness and readiness probes before you change memory values.
How to Right-Size Kubernetes CPU and Memory Requests in Practice
- Pick one service and gather usage data across a full traffic cycle, including a peak.
- Note typical usage, peak usage, throttling events, and OOMKilled events for each container.
- Set the CPU request near typical CPU use and the memory request near typical memory use plus a margin for normal variation.
- Set CPU and memory limits above the requests, with a wider gap for memory where spikes are sharp.
- Apply the change to one deployment first, then watch latency, restarts, and throttling through the next peak.
- Adjust once based on what you see, then roll the same method out to the next service.
Common Mistakes That Waste Capacity or Cause Restarts
- Copying requests from another service with a different traffic shape or language runtime.
- Setting requests equal to limits for every container, which removes all burst room and makes scheduling stricter than it needs to be.
- Leaving requests unset, which lets the scheduler pack pods onto nodes until the node itself runs out of room.
- Sizing from a single quiet day, then hitting the first real peak with OOMKilled restarts.
- Treating a memory leak as a sizing problem and raising the limit at each incident instead of finding the growth.
- Forgetting init containers and sidecars: a logging or proxy sidecar has its own usage, and it counts toward the pod total.
Where Autoscaling Fits
Right-sizing and autoscaling answer different questions. Requests decide where a pod fits and how much it reserves. Autoscaling decides how many pods run. Once requests reflect real usage, a Horizontal Pod Autoscaler setup based on CPU or custom metrics behaves more predictably, because each replica reserves a realistic share of a node. If requests are far too high, the autoscaler adds replicas that cannot be scheduled. If requests are far too low, it adds replicas onto nodes that are already full.
The same discipline pays off outside Kubernetes. Requests that match real usage lower the node count a cluster needs, which feeds directly into cloud cost optimization: fewer wasted reservations, fewer nodes held for capacity that never gets used, and clearer data when you review the bill. Cost tools can point at the waste, but the fix still starts with the request values in your manifests.
A Review Routine That Keeps Settings Honest
Put sizing on a calendar, not on a wish list. After each sizing pass, record the old values, the new values, and the usage data behind them, so the next person can see why a number was chosen. Revisit services after a major release, after a traffic change, and at least once a quarter for stable services. Services that grow steadily, such as a cache-backed API, deserve a monthly check until their growth pattern is clear.
For each review, answer four questions: has typical usage moved, has the peak moved, have restarts or throttling events appeared, and does the node count still match demand? If all four answers are no, leave the values alone.