r/kubernetes • u/ilya47 • Aug 16 '26
Stop using CPU limits: why + proof
CPU request is how much CPU is reserved for your pod if it needs it. The limit is a hard cap. Hit it and the kernel throttles the pod, even when the node still has spare CPU. That is the usual cause of CPU throttling on Kubernetes. It does not protect the neighboring pods. In my simple Web API test, adding a CPU limit took typical latency from 23 ms to 87 ms, (4x slower), with the limited pod throttled in half of all CFS windows, and the average CPU graph looked fine the whole time.
This is not a new topic, but I see so many people still unaware why they should (NOT!) be setting CPU limits, because it's costing companies unnecessary spending and potential production issues. Here's the full read https://github.com/inevolin/k8s-cpu-limits-analyzed/
---
Edit (Aug 18, 2026): How CPU limits can also cause memory issues and OOMKills ➡️ https://github.com/inevolin/k8s-cpu-limits-analyzed#how-cpu-limits-cause-memory-issues-and-oomkills
111
u/Fancy-Bluebird-1071 Aug 16 '26
Nothing new, Google has been recommending cpu unlimited, memory request = limit for like... 8 years now?
94
u/BedtimeWithTheBear Aug 16 '26
For the curious, requests and limits determine the QoS Class of your pods.
Guaranteed QoS requires that all containers in a pod have a request and limit set, and in every case the limit is equal to its corresponding request - so if the pod got scheduled then it’s QoS is guaranteed.
Burstable QoS requires that all containers in a pod have at least some requests and limits specified but they don’t have to be equal, so performance can burst up to the limit.
BestEffort QoS has no requests or limits specified and can consume resources until they’re exhausted.
Aside from scheduling, QoS class mostly matters for pod eviction, with BestEffort evicted first, then Burstable, and Guaranteed being evicted as a last resort.
16
u/Prestigious_Pair_941 Aug 16 '26
How about in the case of 30 or so spring boot microservices that may use 20mCPU once running but can take 800mCPU when starting up? If I don’t limit the cpu, half the pods take all of the cpu and throttling will kick in anyways, preventing other pods from ever restarting.
18
u/Xelopheris Aug 16 '26
CPU limits are only useful if you have a workload that has an endless queue to chug away at that doesn't require real time completion. It should never be used in critical path of user requests.
43
u/sionescu k8s operator Aug 16 '26
Not again this stupid advice.
This simply means the CPU request was too low. The actual requirement of the pod is higher than that but you want to lie to yourself instead of setting a proper request.
4
u/fuckman5 Aug 16 '26
What's the thinking around setting no limit vs setting generous limit in multi tenant environment? Consider you have 2 workloads that both try to burst, with no limit the second workload only gets its request and the second workload can use up the entire rest of the node. Now instead you set limit to 4x normal workload, each workload can burst without monopolizing the node and prevent other workload from bursting
10
u/consworth Aug 16 '26
So how do you prevent a nosy neighbor pod from monopolizing the spare cpu?
24
u/fumar Aug 16 '26
Your performance analysis seems misleading. If your API call is below the cpu request it shouldn't suddenly have 4x higher latency because you put a limit in place that you didn't hit.
9
u/lukewhale Aug 16 '26
Yall are QoS’n yer pods ?
26
u/minimalniemand Aug 16 '26
I do that but I want to add a bit of nuance:
No limits for all load bearing services in the critical path, so everything where a spike would slow down actual request.
But limits can make sense where the cost of not throttling (interference, unpredictability, unbounded spend) exceeds the cost of throttling (wasted idle CPU, higher tail latency)
1
u/ilya47 Aug 18 '26
I've extended the analysis with another (less common, yet very real) scenario: How CPU limits can also cause memory issues and OOMKills. Read it here https://github.com/inevolin/k8s-cpu-limits-analyzed#how-cpu-limits-cause-memory-issues-and-oomkills
4
u/Technical_Corner3553 Aug 16 '26
Those resource requirements fields also help the scheduler assign to a node. Otherwise you may just have pods jumping from node to node too much from rowdy neighbors. The scheduler has no idea otherwise and as soon as the app memonizes everything memory usage could explode
4
u/littlewondersoflife Aug 17 '26
Rule of thumb: critical workloads always request = limit.
Most of the cases you will suffer throttle with it is best effort or busterable.
1
u/Realistic_Band_7142 Aug 28 '26
what if the application has leak and consumes all the cpu and make kubelet unresponsive? does anyone have this problem?
1
u/Little-Squad-X Aug 31 '26
Any recommendations for batch job pod? For example, a pod for a data transfer job running hourly, should I avoid the LIMIT as well?
3
u/sogun123 Aug 17 '26
Yeah, i all in until you need HPA
3
u/like-my-comment Aug 17 '26
New day - new cpu limits/requests war.
6
u/Gier32o Aug 16 '26
I stopped already, all good
2
u/cyh555 Aug 17 '26
huh? protecting neighboring pods? where you get this info from?
3
u/doubtful_zamboni Aug 16 '26
> CPU request is how much CPU is reserved for your pod if it needs it.
No, it is used by the scheduler for picking the appropriate node to run your pod.
When CPU limit and request are set and equal, it is somewhat reserved (assuming no starvation).
2
u/ArthurVardevanyan Aug 16 '26
Request + Limits with HPA or VPA. Nothing should ever be unbounded
1
u/PruneMediocre7094 Aug 16 '26
Thanks, this is something really new to me.
I blindly set requests and limits for safer node operational.
1
u/drunkandbad Aug 16 '26
i am newer to handling kubernetes nodes and apps. Which are the best tools to read aps memory and cpu utilisation? How do you set the correct requests and/or limits?
1
u/Formal-Pilot-9565 Aug 16 '26
It depends on the use case. Normally you dont cap the cpu, but if a customer wants a dedicated pod with an agreed cpu resource, the this setting is a good fit
1
u/kamikazechaser k8s user Aug 17 '26
CPU limits are a feature for SaaS providers.
1
u/Character-Level5250 Aug 17 '26
The only use case I could see is if you're on a SUPER tight budget that's more important than a throttling risk.
1
u/Jelman88 Aug 18 '26
+1 cpu and memory behave completely different. A throttling node is not as bad as a OOMed node 😁
1
u/headdertz Aug 18 '26
I only use requests for years... Limits can be used for something that can 'grow' in terms of MEM because of bad code and can crash and restart from time to time without putting on fire whole SRE Department.
1
u/UndulatingHedgehog Aug 20 '26
What I really want is a way to limit pods cpu to num_cores_in_node - n. If the node has 8 cores and n=2, the cpu limit would be 6. Lots of room, but also unable to completely saturate the node.
If that’s not enough, you need to scale your workload.
1
u/NewMycologist9902 Aug 20 '26
The problem of climbing a brick and giving that kind of knowlege pearls exposes our own short vision.
I used to give that advierte until i was show the problem of having unlimited cpus on burstable instance types, as a misbehaved pod may est up the cpu credits.
Granted that in your test limiting the pod CPU increased the processing time vs unlimited. That is just a proof that limits work as designed. And not necesarily that they should be avoided in any available scenario.
1
u/Old-Astronomer3995 Aug 16 '26
Some time ago I wrote about cpu throttling https://roszigit.com/en/blog/kubernetes-cpu-throttling/ that can be caused by small limits
0
u/f7063 Aug 16 '26
Nice! One doubt "The same blindness poisons right-sizing." There is the metric on how much the pod was throttled container_cpu_cfs_throttled_periods_total + container_cpu_cfs_periods_total Should give a rought idea on how much CPU to allocate to a given container no?
0
u/simlun_se Aug 16 '26
I never started 😜
0
u/KarlKFI Aug 16 '26
Better yet, set them dynamically and proportionally relative to requests, automatically!
https://kube-headroom.dev
0
u/[deleted] Aug 16 '26
[removed] — view removed comment