Pod has more resources than expected

7/28/2021

I created a Pod (see config below) on k8s (AKS, k8s version 1.19.7) with cpu="6" and memory=20G. So I expected the Pod to have 6 cores on the CPU as I read on the k8s docu

One cpu, in Kubernetes, is equivalent to 1 vCPU/Core for cloud providers

When I check lscpu on the container, I get

root@user-ubuntu:/# lscpu
Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Byte Order:                      Little Endian
Address sizes:                   46 bits physical, 48 bits virtual
CPU(s):                          16                                  <-- 2x 8 hyperthreading cores?
On-line CPU(s) list:             0-15
Thread(s) per core:              2
Core(s) per socket:              8                               <-- expected 6
Socket(s):                       1
NUMA node(s):                    1
Vendor ID:                       GenuineIntel
CPU family:                      6
Model:                           85
Model name:                      Intel(R) Xeon(R) Platinum 8168 CPU @ 2.70GHz 

Also, the memory seems to be 32G instead of 20G

root@user-ubuntu:/# vmstat -s -S M
        32114 M total memory
kind: Pod
apiVersion: v1
metadata:
  name: user-ubuntu
spec:
  containers:
  - name: user-ubuntu
    image: ubuntu:latest
    command: ["/bin/sleep", "3650d"]
    imagePullPolicy: IfNotPresent
    resources:
      requests:
        cpu: "6"
        memory: 20G
      limits:
        cpu: "6"
        memory: 20G
    volumeMounts:
    - mountPath: "/mnt/azure"
      name: volume
  restartPolicy: Always
  volumes:
    - name: volume
      persistentVolumeClaim:
        claimName: pvc-user-default
-- tenticon
kubernetes

1 Answer

7/28/2021

The lscpu command displays kernel resoures, in particular, from /proc/cpuinfo (see documentation). Now, all the containers running on host system (which can be a physical machine or a VM) share the same kernel (this is the distinguishing feature of containers vs. VMs). Thus, the information you get from lscpu corresponds to the underlying host and not the container.

Here's a list of references where this issue is discussed:

Your container is however restricted by a cgroup to the resource usage you defined in the Pod definition. So, even though lscpu displays 16 cores, your container can still only use 6 of them. The same applies for the memory.

-- weibeld
Source: StackOverflow