kubernetes: kubelet fails to restart with CPUManager policy static when node's some CPU is offline
What happened?
I have a node with Configuration: a. 96 CPUS with one CPU(ID=95) disabled. b. kubelet CPUManager static policy enabled. c. kubeReserved: cpu: 2, systemReserved: cpu: 2
After start kubelet, the topology kubelet detected shows
"Detected CPU topoloogy" topology=&{NumCPUs:95 NumCores:48 NumSockets:2 NumNUMANodes:2 CPUDetails:......
Notes Core 25 contains CPU 25,73。 Core 47 contains CPU 47,95,but 95 is disabled and not shown in the log.
The static Policy process CPU reservation log below.
"takeFullCores: clainming core" core=47
"takeFullCores: clainming core" core=24
"takeRemainingCPUs: claiming CPU" cpu=25
"Reserved CPUs not available for exclusive assignment" reservedSize=4 reserved="24-25,47,72"
"Updated default CPUSet" cpuSet="0-94"
The weird thing is when the first Pod admits, the reserved CPU(ID=25) is reused.
"Topology Affinity" pod="xxx" containerName="xxx" affinity={NUMANodeAffinity:<nil> Prefered:false}
"AllocateCPUs" numCPUs=20 socket=<nil>
"takeFullCores: clainming core" core=25
"takeRemainingCPUs: claiming CPU" cpu=26
"takeRemainingCPUs: claiming CPU" cpu=74
…
"Updated default CPUSet" cpuSet="0-24,35-72,83-94"
"AllocateCPUs" result="25-34,73-82"
The confliction would further cause kubelet restart failure because of the static policy validation
"Static policy invalid state, please drain node and remove policy state file" err="not all reserved cpus: \"24-25,47,72\" are present in defaultCpuSet: \"0-24,35-72,83-94\""
What did you expect to happen?
Pod Cpuset Allocation should not share with Reserved CPUs
How can we reproduce it (as minimally and precisely as possible)?
- use
chcpu -dto disable one CPU in the node. Check/sys/devices/system/cpu/onlinefile to make sure it works. - change kubelet configuration a. cpuManagerPolicy: static b. kubeReserved: cpu: 2, systemReserved: cpu: 2
- restart kubelet
- create a guaranteed Pod with some CPU
- restart kubelet, expects it would fail to startup
Anything else we need to know?
it seems that kubelet CPUManager static Policy have not taken CPU offline senario into account.
- in the specific case above, this method would result in 1(95/48), not 2 https://github.com/kubernetes/kubernetes/blob/227c2e7c2b2c05a9c8b2885460e28e4da25cf558/pkg/kubelet/cm/cpumanager/topology/topology.go#L49-L54
- thus result in a Used Core as free (1==1) https://github.com/kubernetes/kubernetes/blob/227c2e7c2b2c05a9c8b2885460e28e4da25cf558/pkg/kubelet/cm/cpumanager/cpu_assignment.go#L259-L262
- all logic releated with CPUsPerCore, CPUsPerSocket is affected
Kubernetes version
Cloud provider
OS version
# On Linux:
$ cat /etc/os-release
# paste output here
$ uname -a
# paste output here
# On Windows:
C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture
# paste output here
Install tools
Container runtime (CRI) and version (if applicable)
Related plugins (CNI, CSI, …) and versions (if applicable)
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 19 (15 by maintainers)
Right. The critical flow is that we do trivial divisions in the cpu topology code (and in the surrounding code) rather than enumerating the CPUs and taking their relationship (and online/offline status) intou account.
This seems promising, I’ll have a look
/triage accepted
a bit more context on @AnishShah 's comment:
In the SIG-Node CI meeting today we talked about this and came to the conclusion that this is a feature request. In part because of the structured error that is clearly catching this problem, and in part because this is ultimately a hotplugged resource problem, even though the kubelet is restarting in between. How the kubelet responds to cpus being taken offline underneath it would be solved the same way if the kubelet was continuously running or if it was restarted before and after.
I thought there was an open KEP about hotplugging memory/cpu and having the kubelet respond, but I can’t find it.
We also talked a bit about what the kubelet should do in this case. We decided the kubelet should probably evict in this case, but that means making the eviction manager aware of the needs of the cpu manager.
All of this together informed the decision to mark this as a feature
/kind feature /remove-kind bug
kubelet does not respond well to dynamic changes to resources on the node. There is an open KEP-3953 to improve this with dynamic changes to resources.