我在k8s (AKS, k8s版本1.19.7)上与cpu="6"
和memory=20G
创建了一个Pod(见下面的配置)。所以我希望Pod在CPU上有6个核心,因为我在k8s文档上读到
在Kubernetes中,一个cpu相当于1个vCPU/Core供应商
当我检查容器上的lscpu
时,我得到
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
此外,内存似乎是32G而不是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
lscpu
命令显示内核资源,特别是来自/proc/cpuinfo
的内核资源(请参阅文档)。现在,在主机系统(可以是物理机或VM)上运行的所有容器都共享相同的内核(这是容器与VM的区别特征)。因此,从lscpu
获得的信息对应于底层主机,而不是容器。
下面是讨论这个问题的参考文献列表:
- https://news.ycombinator.com/item?id=25213368
- https://github.com/lxc/lxcfs/issues/181
- https://github.com/kubernetes/kubernetes/issues/92904
- https://github.com/kubernetes/kubernetes/issues/53706
您的容器被c组限制为您在Pod定义中定义的资源使用情况。因此,即使lscpu
显示16个内核,您的容器仍然只能使用其中的6个。这同样适用于内存