kill all processes in a container in the event of OOM

Set memory.oom.group if using cgroups v2 unified mode so all processes in
the container will be killed together in the event of an OOM kill.
This commit is contained in:
Todd Neal
2023-04-26 09:55:14 -05:00
parent bce37d089f
commit 4e20a8f52b
2 changed files with 61 additions and 11 deletions

View File

@@ -215,6 +215,15 @@ func (m *kubeGenericRuntimeManager) calculateLinuxResources(cpuRequest, cpuLimit
resources.CpuPeriod = cpuPeriod
}
// runc requires cgroupv2 for unified mode
if libcontainercgroups.IsCgroup2UnifiedMode() {
resources.Unified = map[string]string{
// Ask the kernel to kill all processes in the container cgroup in case of OOM.
// See memory.oom.group in https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html for
// more info.
"memory.oom.group": "1",
}
}
return &resources
}