Kubernetes CPU/Memory Resource Allocation on Pod not correct

3/11/2021

I have a deployment template which has below resources settings:

    Limits:
      cpu:     2
      memory:  8Gi
    Requests:
      cpu:     500m
      memory:  2Gi

I believe the Kubernetes will allocate my pod with CPU between 500m ~ 2 core, and memory between 2Gi ~ 8Gi.

However, when I ssh into the pod, when I run below command to get the CPU/Memory, seems the resource allocation is not correct:

[root@xxx /]# cat /proc/meminfo
MemTotal:       15950120 kB
MemFree:         6629072 kB
MemAvailable:   12728888 kB

15950120 kB is around 15.9 Gi.

grep 'cpu cores' /proc/cpuinfo | uniq
cpu cores	: 2

The CPU on the pod is 2 core.

So my question is why I set the limit for the memory is 8Gi, but I got 16Gi in total?

Also for the CPU, I just request 500m core but why it shows 2cores?

-- Tianbing Leng
cpu
kubernetes
kubernetes-pod
memory

1 Answer

3/21/2021

You know, there is an explanation from the official Managing Resources for Containers kubernetes documentation, why there are 2 cores instead of 500m, but it is hard to understand how happend 16Gi instead of 8Gi..

SO basically, documentation sais,

If the node where a Pod is running has enough of a resource available, it's POSSIBLE (and ALLOWED) for a container TO USE MORE RESOURCES than its request for that resource specifies. However, a container is not allowed to use more than its resource limit.

For example, if you set a memory request of 256 MiB for a container, and that container is in a Pod scheduled to a Node with 8GiB of memory and no other Pods, then the container can try to use more RAM.

-- Vit
Source: StackOverflow