Kubernetes: specify CPUs for cpumanager

11/30/2018

Is it possible to specify CPU ID list to the Kubernetes cpumanager? The goal is to make sure pods get CPUs from a single socket (0). I brought all the CPUs on the peer socket offline as mentioned here, for example:

$ echo 0 > /sys/devices/system/cpu/cpu5/online

After doing this, the Kubernetes master indeed sees the remaining online CPUs

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

However, cpumanager still seems to think there are 112 CPUs (socket0 + socket1).

cat /var/lib/kubelet/cpu_manager_state
{"policyName":"static","defaultCpuSet":"0-111"}

As a result, the kubelet system pods are throwing the following error:

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>
-- Ratiocinate
kubernetes
numa

1 Answer

12/3/2018

I was able to get this working. Posting this as an answer so that someone in need might benefit.

It appears the CPU set is read from /var/lib/kubelet/cpu_manager_state file and it is not updated across kubelet restarts. So this file needs to be removed before restarting kubelet.

The following worked for me:

# 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")

I have reported a bug here as I think the CPU set should be updated after kubelet restarts.

-- Ratiocinate
Source: StackOverflow