-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathconfig.go
More file actions
127 lines (108 loc) · 3.6 KB
/
Copy pathconfig.go
File metadata and controls
127 lines (108 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package kubelet
import (
"fmt"
"os"
"github.com/portainer/kubesolo/internal/runtime/filesystem"
"github.com/portainer/kubesolo/internal/runtime/network"
"github.com/portainer/kubesolo/types"
"github.com/rs/zerolog/log"
"gopkg.in/yaml.v2"
)
// cgroupDriver returns "systemd" only when systemd is the active init system,
// otherwise "cgroupfs". Alpine Linux uses OpenRC and has no systemd even when
// cgroupv2 is present, so the systemd cgroup manager must not be used there.
func cgroupDriver() string {
if _, err := os.Stat("/run/systemd/private"); err == nil {
return "systemd"
}
return "cgroupfs"
}
func (s *service) writeKubeletConfigFile() error {
if err := filesystem.EnsureDirectoryExists(s.kubeletConfigDir); err != nil {
return fmt.Errorf("failed to create kubelet directory: %v", err)
}
yamlConfig, err := yaml.Marshal(s.generateKubeletConfig())
if err != nil {
log.Error().Str("component", "kubelet").Msgf("failed to marshal kubelet config: %v", err)
return err
}
configFile, err := os.Create(s.kubeletConfigFile)
if err != nil {
log.Error().Str("component", "kubelet").Msgf("failed to create config file: %v", err)
return err
}
defer configFile.Close()
_, err = configFile.Write(yamlConfig)
if err != nil {
log.Error().Str("component", "kubelet").Msgf("failed to write config file: %v", err)
return err
}
log.Debug().Str("component", "kubelet").Msgf("wrote kubelet config to %s", s.kubeletConfigFile)
return nil
}
func (s *service) generateKubeletConfig() map[string]any {
config := map[string]any{
"kind": "KubeletConfiguration",
"apiVersion": "kubelet.config.k8s.io/v1beta1",
"containerRuntimeEndpoint": "unix://" + s.containerdSockFile,
"authentication": map[string]any{
"anonymous": map[string]any{
"enabled": false,
},
"webhook": map[string]any{
"enabled": true,
"cacheTTL": "5m0s",
},
"x509": map[string]any{
"clientCAFile": s.caFile,
},
},
"authorization": map[string]any{
"mode": "Webhook",
"webhook": map[string]any{
"cacheAuthorizedTTL": "10m0s",
"cacheUnauthorizedTTL": "1m0s",
},
},
"clusterDomain": "cluster.local",
"clusterDNS": []string{types.DefaultCoreDNSIP},
"resolvConf": network.GetHostResolvConf(s.kubeletDir),
"tlsCertFile": s.certFile,
"tlsPrivateKeyFile": s.keyFile,
"cgroupDriver": cgroupDriver(),
"readOnlyPort": 0,
"rotateCertificates": true,
"failSwapOn": false,
}
// Edge-optimised overrides — only applied when not in full mode.
// When full mode is enabled, upstream Kubernetes defaults are used instead.
if !s.fullMode {
config["enableProfilingHandler"] = false
config["enableDebugFlagsHandler"] = false
config["streamingConnectionIdleTimeout"] = "1h0s"
config["syncFrequency"] = "5m0s"
config["fileCheckFrequency"] = "2m0s"
config["httpCheckFrequency"] = "2m0s"
config["nodeStatusUpdateFrequency"] = "60s"
config["nodeStatusReportFrequency"] = "15m0s"
config["volumeStatsAggPeriod"] = "5m0s"
config["imageMinimumGCAge"] = "10m0s"
config["imageMaximumGCAge"] = "0s"
config["imageGCHighThresholdPercent"] = 95
config["runtimeRequestTimeout"] = "60s"
config["cpuManagerReconcilePeriod"] = "60s"
config["kubeAPIQPS"] = 10
config["kubeAPIBurst"] = 20
config["eventRecordQPS"] = 5
config["eventBurst"] = 10
config["containerLogMaxSize"] = "512Ki"
config["maxPods"] = 20
config["evictionHard"] = map[string]string{
"memory.available": "75Mi",
"nodefs.available": "50Mi",
}
config["systemReserved"] = map[string]string{"memory": "25Mi"}
config["kubeReserved"] = map[string]string{"memory": "25Mi"}
}
return config
}