mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
Set oom_score_adj for kubelet and kube-proxy to a low value to help them survive system memory pressure.
This commit is contained in:
parent
8824e46340
commit
6f53f33fda
@ -42,6 +42,7 @@ var (
|
|||||||
bindAddress = util.IP(net.ParseIP("0.0.0.0"))
|
bindAddress = util.IP(net.ParseIP("0.0.0.0"))
|
||||||
clientConfig = &client.Config{}
|
clientConfig = &client.Config{}
|
||||||
healthz_port = flag.Int("healthz_port", 10249, "The port to bind the health check server. Use 0 to disable.")
|
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() {
|
func init() {
|
||||||
@ -55,6 +56,10 @@ func main() {
|
|||||||
util.InitLogs()
|
util.InitLogs()
|
||||||
defer util.FlushLogs()
|
defer util.FlushLogs()
|
||||||
|
|
||||||
|
if err := util.ApplyOomScoreAdj(*oomScoreAdj); err != nil {
|
||||||
|
glog.Info(err)
|
||||||
|
}
|
||||||
|
|
||||||
verflag.PrintAndExitIfRequested()
|
verflag.PrintAndExitIfRequested()
|
||||||
|
|
||||||
serviceConfig := config.NewServiceConfig()
|
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.")
|
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.")
|
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")
|
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
|
apiServerList util.StringList
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -92,6 +93,10 @@ func main() {
|
|||||||
|
|
||||||
setupRunOnce()
|
setupRunOnce()
|
||||||
|
|
||||||
|
if err := util.ApplyOomScoreAdj(*oomScoreAdj); err != nil {
|
||||||
|
glog.Info(err)
|
||||||
|
}
|
||||||
|
|
||||||
kcfg := standalone.KubeletConfig{
|
kcfg := standalone.KubeletConfig{
|
||||||
Address: address,
|
Address: address,
|
||||||
AuthPath: *authPath,
|
AuthPath: *authPath,
|
||||||
|
@ -19,8 +19,10 @@ package util
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
@ -134,3 +136,16 @@ func CompileRegexps(regexpStrings []string) ([]*regexp.Regexp, error) {
|
|||||||
}
|
}
|
||||||
return regexps, nil
|
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
Block a user