mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-08 11:38:15 +00:00
Apply oom_score_adj (0) to PID of user containers by default.
This commit is contained in:
parent
1f952b05d3
commit
f6f9372d1a
@ -48,9 +48,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// The oom_score_adj of the POD infrastructure container. The default is 0, so
|
// The oom_score_adj of the POD infrastructure container. The default is 0 for
|
||||||
// any value below that makes it *less* likely to get OOM killed.
|
// any other docker containers, so any value below that makes it *less* likely
|
||||||
podOomScoreAdj = -100
|
// to get OOM killed.
|
||||||
|
podOomScoreAdj = -100
|
||||||
|
userContainerOomScoreAdj = 0
|
||||||
|
|
||||||
maxReasonCacheEntries = 200
|
maxReasonCacheEntries = 200
|
||||||
|
|
||||||
@ -1181,6 +1183,28 @@ func (dm *DockerManager) runContainerInPod(pod *api.Pod, container *api.Containe
|
|||||||
if err = dm.os.Symlink(containerLogFile, symlinkFile); err != nil {
|
if err = dm.os.Symlink(containerLogFile, symlinkFile); err != nil {
|
||||||
glog.Errorf("Failed to create symbolic link to the log file of pod %q container %q: %v", podFullName, container.Name, err)
|
glog.Errorf("Failed to create symbolic link to the log file of pod %q container %q: %v", podFullName, container.Name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set OOM score of POD container to lower than those of the other containers
|
||||||
|
// which have OOM score 0 by default in the pod. This ensures that it is
|
||||||
|
// killed only as a last resort.
|
||||||
|
containerInfo, err := dm.client.InspectContainer(string(id))
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure the PID actually exists, else we'll move ourselves.
|
||||||
|
if containerInfo.State.Pid == 0 {
|
||||||
|
return "", fmt.Errorf("failed to get init PID for Docker container %q", string(id))
|
||||||
|
}
|
||||||
|
if container.Name == PodInfraContainerName {
|
||||||
|
util.ApplyOomScoreAdj(containerInfo.State.Pid, podOomScoreAdj)
|
||||||
|
} else {
|
||||||
|
// Children processes of docker daemon will inheritant the OOM score from docker
|
||||||
|
// daemon process. We explicitly apply OOM score 0 by default to the user
|
||||||
|
// containers to avoid daemons or POD containers are killed by oom killer.
|
||||||
|
util.ApplyOomScoreAdj(containerInfo.State.Pid, userContainerOomScoreAdj)
|
||||||
|
}
|
||||||
|
|
||||||
return kubeletTypes.DockerID(id), err
|
return kubeletTypes.DockerID(id), err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1235,19 +1259,6 @@ func (dm *DockerManager) createPodInfraContainer(pod *api.Pod) (kubeletTypes.Doc
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set OOM score of POD container to lower than those of the other
|
|
||||||
// containers in the pod. This ensures that it is killed only as a last
|
|
||||||
// resort.
|
|
||||||
containerInfo, err := dm.client.InspectContainer(string(id))
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure the PID actually exists, else we'll move ourselves.
|
|
||||||
if containerInfo.State.Pid == 0 {
|
|
||||||
return "", fmt.Errorf("failed to get init PID for Docker pod infra container %q", string(id))
|
|
||||||
}
|
|
||||||
util.ApplyOomScoreAdj(containerInfo.State.Pid, podOomScoreAdj)
|
|
||||||
return id, nil
|
return id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user