Memory is kind of trivial to understand. requests
is guaranteed and limits
is something that can not be exceeded. This also means that when you issue kubectl describe nodes | tail -10
for example, you could see a phrase like:
"Total limits may be over 100 percent, i.e., overcommitted".
This means that the total sum of requests.memory
is <= 100%
(otherwise pods could not be scheduled and this is the meaning of guaranteed memory). At the same time if you see a value that is higher then 100%
, it means that the total sum of limits.memory
can go above 100% (and this is the overcommitted part in the message). So when a node tries to schedule a pod, it will only check requests.memory
to see if it has enough memory.
The cpu part if more complicated.
requests.cpu
translates to cpu shares, and without looking at all pods on the node, it might make little to no sense to be honest. imho, the easiest way to understand this property is by looking at an example.
Suppose you have 100 cores available on a node, you deploy a single pod and set requests.cpu = 1000m
. In such a case, your pod can use 100 cpus, bot min and max.
You have the same machine (100 cores), but you deploy two pods with requests.cpu = 1000m
. In such a case, your pods can use 50 cores each minimum, and 100 max.
Same node, 4 pods (requests.cpu = 1000m
). Each pod can use 25 cpu min, and 100 max.
You get the picture, it matters what all pods set for requests.cpu
to get an overall picture.
limits.cpu
is a lot more interesting and it translated to two properties on the cgroup : cpu period
and cpu quota
. It means how much time (quota) can you get in a certain timeframe (period). An example should make things more simple here aswell.
- Suppose
period=100ms
and quota=20ms
and you get a request that will finish in 50ms
on your pod.
This is how it will look like:
| 100ms || 100ms || 100ms |
| 20 ms ......|| 20 ms ......|| 10 ms ......|
Because it takes 50ms
to process a request, and we have only 20ms
available for every 100ms
, it will take 300ms
in total, to process our request.
That being said, there are quite a lot of people that recommend not setting the cpu, at all. google engineers, zalando, monzo, etc - including us. We do not do that, and there are strong reasons for that (that go beyond this question).