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.
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
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.
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"
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?
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.
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
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%
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: https://docs.google.com/spreadsheets/d/1yhkuBJBY2iO2Ax5FcbDMdWD5QLTVO6Y_kYt_VumnEtI
You will see more CPU charts and comparisons coming soon in that doc.
That's it!
This thread is part of the @learnk8s research on Kubernetes Node sizing: https://docs.google.com/spreadsheets/d/1yhkuBJBY2iO2Ax5FcbDMdWD5QLTVO6Y_kYt_VumnEtI
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:
http://blog.kubecost.com/blog/requests-and-limits/
https://medium.com/@betz.mark/understanding-resource-limits-in-kubernetes-cpu-time-9eff74d3161b
https://nodramadevops.com/2019/10/docker-cpu-resource-limits/
Also if you want to dig in deeper here you can find a few relevant links:
http://blog.kubecost.com/blog/requests-and-limits/
https://medium.com/@betz.mark/understanding-resource-limits-in-kubernetes-cpu-time-9eff74d3161b
https://nodramadevops.com/2019/10/docker-cpu-resource-limits/