Skip to content

Advertisement

DevOps Society

Kubernetes Requests and Limits Explained: How to Size Pods Without Wasting Money

Requests decide where a pod lands and what you pay for. Limits decide what happens when it gets greedy. A practical guide to setting both, with the CPU throttling and OOMKill traps that catch most teams.

Published your local timeupdated

Kubernetes Requests and Limits Explained: How to Size Pods Without Wasting Money

Ask ten teams how they picked the CPU and memory numbers in their deployment files and you will hear some version of "we copied them from another service". That is how clusters end up 30% utilised and still running out of room.

Requests and limits are two small fields that drive placement, performance and the size of your cloud bill. Here is how they actually work and a sane way to set them.

Requests: what the scheduler believes

A request is a promise you make to the scheduler: "this container needs at least this much." The scheduler adds up the requests of every pod on a node and will not place a new pod there if the total would go past what the node can offer.

Two things follow from that. First, requests are what you pay for. A pod that requests 2 CPUs and uses 0.2 still blocks 2 CPUs on the node. Multiply that across a few hundred pods and you have bought a lot of empty servers. Second, requests are not a ceiling. A container can use more than it requested if the node has spare capacity.

Autoscalers work from requests too. The Horizontal Pod Autoscaler's CPU target is a percentage of the request, and node autoscalers add nodes when pods cannot fit based on requests. Get requests wrong and every layer above makes decisions on bad numbers.

Limits: what the kernel enforces

A limit is a hard ceiling, and CPU and memory behave very differently when you hit it.

CPU limits throttle. CPU is compressible, so the kernel simply stops giving the container time once it has used its quota for the current period. The process does not crash. It gets slow, often in short bursts that show up as random latency spikes. A service with a 500m limit that briefly needs two cores to handle a burst of requests will be held back even if the node is idle.

Memory limits kill. Memory is not compressible. When a container goes past its memory limit, the kernel's OOM killer ends the process and Kubernetes reports OOMKilled. There is no slowing down first.

The QoS classes, briefly

Kubernetes sorts pods into three quality of service classes based on these settings, and uses them to decide what to evict first when a node runs short of memory. Guaranteed pods have requests equal to limits for CPU and memory on every container and are evicted last. Burstable pods have at least one request set; most services live here. BestEffort pods set nothing and are the first to go.

A practical way to set them

There is plenty of debate about CPU limits. Our view, and a common one among people who run large clusters, is this:

  1. Always set a CPU request, based on real usage. A good starting point is around the 90th percentile of CPU use over a normal week.

  2. Be careful with CPU limits. For latency-sensitive services, many teams leave the CPU limit off and rely on requests for fair sharing. If you need limits for multi-tenant fairness, set them well above the request.

  3. Always set a memory request and limit, and for most services set them to the same value. That makes memory behaviour predictable and stops a node overcommitting memory it does not have.

  4. Size memory from peaks, not averages. Use the maximum working set over a busy period, plus headroom. Garbage-collected runtimes such as Java need their heap settings to fit inside the limit.

Here is what that looks like in a deployment:

resources:
  requests:
    cpu: "300m"
    memory: "512Mi"
  limits:
    memory: "512Mi"

Finding the right numbers

You do not need a product to start. If you run Prometheus, two queries give you most of what you need:

# CPU used per container, 90th percentile over 7 days
quantile_over_time(0.9,
  rate(container_cpu_usage_seconds_total{container!=""}[5m])[7d:5m])

# Peak memory working set per container over 7 days
max_over_time(container_memory_working_set_bytes{container!=""}[7d])

Compare those with what each deployment requests. Anything requesting more than double its p90 is a candidate to shrink. Anything regularly near its memory limit is a candidate to grow before it starts getting killed.

The Vertical Pod Autoscaler can produce the same recommendations for you. Running it in recommendation-only mode for a couple of weeks is a low-risk way to get a second opinion.

Signs your settings are wrong

  • Pods stuck in Pending while nodes look half empty on dashboards: requests are too high.

  • Latency spikes with low average CPU: check throttling with the container_cpu_cfs_throttled_periods_total metric.

  • Restarts with reason OOMKilled: memory limit too low, or a leak.

  • Nodes running hot and pods evicted under memory pressure: requests too low compared with real use.

Right-sizing is one of the cheapest FinOps wins on Kubernetes. For the bigger picture on cost, start with our FinOps guide, and for how scheduling fits into the cluster as a whole, see Kubernetes architecture explained.

Advertisement

Follow DevOps Society on LinkedIn

Practical infrastructure engineering in your feed.

Follow

Written by

DevOpsSociety Editorial Team

Editorial Team

The DevOpsSociety Editorial Team covers DevOps, cloud infrastructure, Kubernetes, AI infrastructure, platform engineering, cybersecurity, FinOps, and modern engineering practices. We publish practical insights, technical guides, architecture analysis, and research for engineers and technology leaders.

More from DevOpsSociety →
The Infrastructure Briefing

Get the infrastructure briefing.

Practical DevOps, cloud, AI infrastructure and engineering insights, delivered weekly. Read by engineers and engineering leaders.

No spam. Unsubscribe anytime.

Kubernetes Requests and Limits Explained: How to Size Pods Without Wasting Money, DevOps Society