mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
Add a preflight check that the control-plane node has at least 2GB RAM
Signed-off-by: Xianglin Gao <xianglin.gxl@alibaba-inc.com>
This commit is contained in:
parent
43fbe17dc6
commit
e5bb66f899
@ -350,6 +350,9 @@ const (
|
||||
// ControlPlaneNumCPU is the number of CPUs required on control-plane
|
||||
ControlPlaneNumCPU = 2
|
||||
|
||||
// ControlPlaneMem is the number of megabytes of memory required on the control-plane
|
||||
ControlPlaneMem = 2 * 1024
|
||||
|
||||
// KubeadmCertsSecret specifies in what Secret in the kube-system namespace the certificates should be stored
|
||||
KubeadmCertsSecret = "kubeadm-certs"
|
||||
|
||||
|
@ -28,6 +28,7 @@ go_library(
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/version:go_default_library",
|
||||
"//staging/src/k8s.io/component-base/version:go_default_library",
|
||||
"//vendor/github.com/PuerkitoBio/purell:go_default_library",
|
||||
"//vendor/github.com/pbnjay/memory:go_default_library",
|
||||
"//vendor/github.com/pkg/errors:go_default_library",
|
||||
"//vendor/k8s.io/klog/v2:go_default_library",
|
||||
"//vendor/k8s.io/system-validators/validators:go_default_library",
|
||||
|
@ -35,6 +35,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/PuerkitoBio/purell"
|
||||
"github.com/pbnjay/memory"
|
||||
"github.com/pkg/errors"
|
||||
netutil "k8s.io/apimachinery/pkg/util/net"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
@ -869,6 +870,25 @@ func (ncc NumCPUCheck) Check() (warnings, errorList []error) {
|
||||
return warnings, errorList
|
||||
}
|
||||
|
||||
// MemCheck checks if the number of megabytes of memory is not less than required
|
||||
type MemCheck struct {
|
||||
Mem uint64
|
||||
}
|
||||
|
||||
// Name returns the label for memory
|
||||
func (MemCheck) Name() string {
|
||||
return "Mem"
|
||||
}
|
||||
|
||||
// Check number of memory required by kubeadm
|
||||
func (mc MemCheck) Check() (warnings, errorList []error) {
|
||||
actual := memory.TotalMemory() / 1024 / 1024 // TotalMemory returns bytes; convert to MB
|
||||
if actual < mc.Mem {
|
||||
errorList = append(errorList, errors.Errorf("the system RAM (%d MB) is less than the minimum %d MB", actual, mc.Mem))
|
||||
}
|
||||
return warnings, errorList
|
||||
}
|
||||
|
||||
// RunInitNodeChecks executes all individual, applicable to control-plane node checks.
|
||||
// The boolean flag 'isSecondaryControlPlane' controls whether we are running checks in a --join-control-plane scenario.
|
||||
// The boolean flag 'downloadCerts' controls whether we should skip checks on certificates because we are downloading them.
|
||||
@ -884,6 +904,7 @@ func RunInitNodeChecks(execer utilsexec.Interface, cfg *kubeadmapi.InitConfigura
|
||||
manifestsDir := filepath.Join(kubeadmconstants.KubernetesDir, kubeadmconstants.ManifestsSubDirName)
|
||||
checks := []Checker{
|
||||
NumCPUCheck{NumCPU: kubeadmconstants.ControlPlaneNumCPU},
|
||||
MemCheck{Mem: kubeadmconstants.ControlPlaneMem},
|
||||
KubernetesVersionCheck{KubernetesVersion: cfg.KubernetesVersion, KubeadmVersion: kubeadmversion.Get().GitVersion},
|
||||
FirewalldCheck{ports: []int{int(cfg.LocalAPIEndpoint.BindPort), kubeadmconstants.KubeletPort}},
|
||||
PortOpenCheck{port: int(cfg.LocalAPIEndpoint.BindPort)},
|
||||
|
1
go.mod
1
go.mod
@ -79,6 +79,7 @@ require (
|
||||
github.com/opencontainers/go-digest v1.0.0-rc1
|
||||
github.com/opencontainers/runc v1.0.0-rc91.0.20200707015106-819fcc687efb
|
||||
github.com/opencontainers/selinux v1.5.2
|
||||
github.com/pbnjay/memory v0.0.0-20190104145345-974d429e7ae4
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/pmezard/go-difflib v1.0.0
|
||||
github.com/prometheus/client_golang v1.7.1
|
||||
|
2
go.sum
2
go.sum
@ -376,6 +376,8 @@ github.com/opencontainers/runtime-spec v1.0.3-0.20200520003142-237cc4f519e2 h1:9
|
||||
github.com/opencontainers/runtime-spec v1.0.3-0.20200520003142-237cc4f519e2/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
|
||||
github.com/opencontainers/selinux v1.5.2 h1:F6DgIsjgBIcDksLW4D5RG9bXok6oqZ3nvMwj4ZoFu/Q=
|
||||
github.com/opencontainers/selinux v1.5.2/go.mod h1:yTcKuYAh6R95iDpefGLQaPaRwJFwyzAJufJyiTt7s0g=
|
||||
github.com/pbnjay/memory v0.0.0-20190104145345-974d429e7ae4 h1:MfIUBZ1bz7TgvQLVa/yPJZOGeKEgs6eTKUjz3zB4B+U=
|
||||
github.com/pbnjay/memory v0.0.0-20190104145345-974d429e7ae4/go.mod h1:RMU2gJXhratVxBDTFeOdNhd540tG57lt9FIUV0YLvIQ=
|
||||
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
|
||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||
github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI=
|
||||
|
Loading…
Reference in New Issue
Block a user