Skip to content

Commit

Permalink
Merge pull request #4282 from tstromberg/apiserver-no-oom
Browse files Browse the repository at this point in the history
Set apiserver oom_adj to -10 to avoid OOMing before other pods
  • Loading branch information
tstromberg authored May 20, 2019
2 parents 35dc6a2 + d97584a commit f74c62a
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,31 @@ func (k *Bootstrapper) StartCluster(k8s config.KubernetesConfig) error {
if err := util.RetryAfter(100, elevateKubeSystemPrivileges, time.Millisecond*500); err != nil {
return errors.Wrap(err, "timed out waiting to elevate kube-system RBAC privileges")
}

if err := k.adjustResourceLimits(); err != nil {
glog.Warningf("unable to adjust resource limits: %v", err)
}
return nil
}

// adjustResourceLimits makes fine adjustments to pod resources that aren't possible via kubeadm config.
func (k *Bootstrapper) adjustResourceLimits() error {
score, err := k.c.CombinedOutput("cat /proc/$(pgrep kube-apiserver)/oom_adj")
if err != nil {
return errors.Wrap(err, "oom_adj check")
}
glog.Infof("apiserver oom_adj: %s", score)
// oom_adj is already a negative number
if strings.HasPrefix(score, "-") {
return nil
}
glog.Infof("adjusting apiserver oom_adj to -10")

// Prevent the apiserver from OOM'ing before other pods, as it is our gateway into the cluster.
// It'd be preferable to do this via Kubernetes, but kubeadm doesn't have a way to set pod QoS.
if err := k.c.Run("echo -10 | sudo tee /proc/$(pgrep kube-apiserver)/oom_adj"); err != nil {
return errors.Wrap(err, "oom_adj adjust")
}
return nil
}

Expand Down Expand Up @@ -361,6 +386,10 @@ func (k *Bootstrapper) RestartCluster(k8s config.KubernetesConfig) error {
if err := k.c.Run(fmt.Sprintf("%s phase addon all --config %s", baseCmd, configPath)); err != nil {
return errors.Wrapf(err, "addon phase")
}

if err := k.adjustResourceLimits(); err != nil {
glog.Warningf("unable to adjust resource limits: %v", err)
}
return nil
}

Expand Down

0 comments on commit f74c62a

Please sign in to comment.