Kubernetes:为 cpumanager 指定 CPU
Posted
技术标签:
【中文标题】Kubernetes:为 cpumanager 指定 CPU【英文标题】:Kubernetes: specify CPUs for cpumanager 【发布时间】:2018-11-30 20:50:55 【问题描述】:是否可以为 Kubernetes 的 cpumanager 指定 CPU ID 列表?目标是确保 pod 从单个插槽 (0) 获取 CPU。如here 所述,我使对等套接字上的所有 CPU 脱机,例如:
$ echo 0 > /sys/devices/system/cpu/cpu5/online
这样做之后,Kubernetes master 确实看到了剩余的在线 CPU
kubectl describe node foo
Capacity:
cpu: 56 <<< socket 0 CPU count
ephemeral-storage: 958774760Ki
hugepages-1Gi: 120Gi
memory: 197524872Ki
pods: 110
Allocatable:
cpu: 54 <<< 2 system reserved CPUs
ephemeral-storage: 958774760Ki
hugepages-1Gi: 120Gi
memory: 71490952Ki
pods: 110
System Info:
Machine ID: 1155420082478559980231ba5bc0f6f2
System UUID: 4C4C4544-0044-4210-8031-C8C04F584B32
Boot ID: 7fa18227-748f-496c-968c-9fc82e21ecd5
Kernel Version: 4.4.13
OS Image: Ubuntu 16.04.4 LTS
Operating System: linux
Architecture: amd64
Container Runtime Version: docker://17.3.3
Kubelet Version: v1.11.1
Kube-Proxy Version: v1.11.1
但是,cpumanager 似乎仍然认为有 112 个 CPU(socket0 + socket1)。
cat /var/lib/kubelet/cpu_manager_state
"policyName":"static","defaultCpuSet":"0-111"
因此,kubelet 系统 pod 抛出以下错误:
kube-system kube-proxy-nk7gc 0/1 rpc error: code = Unknown desc = failed to update container "eb455f81a61b877eccda0d35eea7834e30f59615346140180f08077f64896760": Error response from daemon: Requested CPUs are not available - requested 0-111, available: 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110 762 36d <IP address> foo <none>
【问题讨论】:
看起来像一个错误。如果重启 kubelet 会发生什么? 似乎没有任何效果。 kubelet重启后cpu_manager_state文件好像没有更新。我不得不手动删除文件,然后重新启动 kubelet。 之后有效果吗? 感谢您提出问题。 【参考方案1】:我能够得到这个工作。将此作为答案发布,以便有需要的人受益。
似乎 CPU 集是从 /var/lib/kubelet/cpu_manager_state
文件中读取的,并且不会在 kubelet 重新启动时更新。所以重启kubelet之前需要删除这个文件。
以下内容对我有用:
# On a running worker node, bring desired CPUs offline. (run as root)
$ cpu_list=`lscpu | grep "NUMA node1 CPU(s)" | awk 'print $4'`
$ chcpu -d $cpu_list
$ rm -f /var/lib/kubelet/cpu_manager_state
$ systemctl restart kubelet.service
# Check the CPU set seen by the CPU manager
$ cat /var/lib/kubelet/cpu_manager_state
# Try creating pods and check the syslog:
Dec 3 14:36:05 k8-2-w1 kubelet[8070]: I1203 14:36:05.122466 8070 state_mem.go:84] [cpumanager] updated default cpuset: "0,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110"
Dec 3 14:36:05 k8-2-w1 kubelet[8070]: I1203 14:36:05.122643 8070 policy_static.go:198] [cpumanager] allocateCPUs: returning "2,4,6,8,58,60,62,64"
Dec 3 14:36:05 k8-2-w1 kubelet[8070]: I1203 14:36:05.122660 8070 state_mem.go:76] [cpumanager] updated desired cpuset (container id: 356939cdf32d0f719e83b0029a018a2ca2c349fc0bdc1004da5d842e357c503a, cpuset: "2,4,6,8,58,60,62,64")
我报告了bug here,因为我认为 CPU 集应该在 kubelet 重启后更新。
【讨论】:
以上是关于Kubernetes:为 cpumanager 指定 CPU的主要内容,如果未能解决你的问题,请参考以下文章
“只做Kubernetes分发版没有前途” Rancher和阿里云的合作揭示容器下一步