mirror of https://github.com/k3s-io/k3s
Set oom_score_adj for kubelet and kube-proxy to a low value to help them survive system memory pressure.
parent
8824e46340
commit
6f53f33fda
|
@ -42,6 +42,7 @@ var (
|
|||
bindAddress = util.IP(net.ParseIP("0.0.0.0"))
|
||||
clientConfig = &client.Config{}
|
||||
healthz_port = flag.Int("healthz_port", 10249, "The port to bind the health check server. Use 0 to disable.")
|
||||
oomScoreAdj = flag.Int("oom_score_adj", -899, "The oom_score_adj value for kube-proxy process. Values must be within the range [-1000, 1000]")
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -55,6 +56,10 @@ func main() {
|
|||
util.InitLogs()
|
||||
defer util.FlushLogs()
|
||||
|
||||
if err := util.ApplyOomScoreAdj(*oomScoreAdj); err != nil {
|
||||
glog.Info(err)
|
||||
}
|
||||
|
||||
verflag.PrintAndExitIfRequested()
|
||||
|
||||
serviceConfig := config.NewServiceConfig()
|
||||
|
|
|
@ -61,6 +61,7 @@ var (
|
|||
maxContainerCount = flag.Int("maximum_dead_containers_per_container", 5, "Maximum number of old instances of a container to retain per container. Each container takes up some disk space. Default: 5.")
|
||||
authPath = flag.String("auth_path", "", "Path to .kubernetes_auth file, specifying how to authenticate to API server.")
|
||||
cAdvisorPort = flag.Uint("cadvisor_port", 4194, "The port of the localhost cAdvisor endpoint")
|
||||
oomScoreAdj = flag.Int("oom_score_adj", -900, "The oom_score_adj value for kubelet process. Values must be within the range [-1000, 1000]")
|
||||
apiServerList util.StringList
|
||||
)
|
||||
|
||||
|
@ -92,6 +93,10 @@ func main() {
|
|||
|
||||
setupRunOnce()
|
||||
|
||||
if err := util.ApplyOomScoreAdj(*oomScoreAdj); err != nil {
|
||||
glog.Info(err)
|
||||
}
|
||||
|
||||
kcfg := standalone.KubeletConfig{
|
||||
Address: address,
|
||||
AuthPath: *authPath,
|
||||
|
|
|
@ -19,8 +19,10 @@ package util
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
@ -134,3 +136,16 @@ func CompileRegexps(regexpStrings []string) ([]*regexp.Regexp, error) {
|
|||
}
|
||||
return regexps, nil
|
||||
}
|
||||
|
||||
// Writes 'value' to /proc/self/oom_score_adj.
|
||||
func ApplyOomScoreAdj(value int) error {
|
||||
if value < -1000 || value > 1000 {
|
||||
return fmt.Errorf("invalid value(%d) specified for oom_score_adj. Values must be within the range [-1000, 1000]")
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile("/proc/self/oom_score_adj", []byte(strconv.Itoa(value)), 0700); err != nil {
|
||||
fmt.Errorf("failed to set oom_score_adj to %s - %q", value, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue