<p>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 <a href="https://www.kernel.org/doc/html/latest/core-api/cpu_hotplug.html?highlight=cpuhotplug" rel="nofollow noreferrer">here</a>, for example:</p>

<pre><code>$ echo 0 &gt; /sys/devices/system/cpu/cpu5/online
</code></pre>

<p>After doing this, the Kubernetes master indeed sees the remaining online CPUs</p>

<pre><code>kubectl describe node foo
Capacity:
 cpu:                56   &lt;&lt;&lt; socket 0 CPU count
 ephemeral-storage:  958774760Ki
 hugepages-1Gi:      120Gi
 memory:             197524872Ki
 pods:               110
Allocatable:
 cpu:                54    &lt;&lt;&lt; 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
</code></pre>

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

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

<p>As a result, the kubelet system pods are throwing the following error:</p>

<pre><code>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       &lt;IP address&gt;   foo      &lt;none&gt;
</code></pre>

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

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

<p>The following worked for me:</p>

<pre><code># 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")
</code></pre>

<p>I have reported a <a href="https://github.com/kubernetes/kubernetes/issues/71622" rel="nofollow noreferrer">bug here</a> as I think the CPU set should be updated after kubelet restarts.</p>
