THREAD:

In Kubernetes, what should I use as CPU requests and limits?

Popular non-answers:

- 100Mi
- Just use the VPA
- wait what? limits?

You can do better!

Let's start with CPU requests.
1/9

CPU requests specify:

1. the minimum CPU needed
2. if there's CPU available how much more can I use?

Example:

- in a single node with 1 CPU
- if you assign 100Mi to containerA and 200Mi containerB
- and they use 100% CPU

containerA uses 333Mi and the other 666Mi
2/9

Requests are good for:

- setting a baseline (give me at least X of CPU)
- setting relationships between pods (this pod A uses twice as much CPU as the other)

but are not useful for setting hard limits.

For that you need CPU limits.
3/9

When you set a CPU limit, you define a period and how much CPU you can have in that period (also called quota).

Example:

- period: 100000 microseconds
- quota: 10000 microseconds

I can only use the CPU for 10000/100000 seconds.

That's also abbreviated as "100Mi"
4/9

If your container has a hard limit and wants more CPU, it has to wait for the next period.

Your processed is throttled.

So what should you use as CPU requests and limits in your Pods?
5/9

For requests calculate the smallest CPU unit as:

REQUEST = NODE CORES * 1000 / MAX NUMBER OF PODS PER NODE

For a 1 vCPU node and max 10 Pods that's 1 * 1000 / 10 = 100Mi request

Assign the smallest unit or a multiplier of it to your containers.
6/9

Example

I don't know how much CPU I need for containerA but I know that it is twice as CPU intensive as containerB.

CPU request for B: 100Mi (1 unit) CPU request for A: 200Mi (2 units)

If the containers use more CPU, they will keep a ratio of 1:2 for all CPU available
7/9

What about limits?

- your app might have already "hard" limits. E.g. Node.js is single-threaded and uses up to 1 core
- you could have: limit = Node CPU - (CPU reserved)

If you need to be more specific, profiling is the way to go. Set the limits at 99th percentile + 50%
You can follow @danielepolencic.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled:

By continuing to use the site, you are consenting to the use of cookies as explained in our Cookie Policy to improve your experience.