My Authors
Read all threads
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%
8/9

That's it!

This thread is part of the @learnk8s research on Kubernetes Node sizing: docs.google.com/spreadsheets/d…

You will see more CPU charts and comparisons coming soon in that doc.
9/9

Also if you want to dig in deeper here you can find a few relevant links:

blog.kubecost.com/blog/requests-…
medium.com/@betz.mark/und…
nodramadevops.com/2019/10/docker…
Missing some Tweet in this thread? You can try to force a refresh.

Enjoying this thread?

Keep Current with Daniele Polencic

Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!