k8s初始化失败
k8s初始化时报错root@k19m149 home]# kubeadm init --image-repository registry.aliyuncs.com/google_containers --apiserver-advertise-address=192.168.53.141 --kubernetes-version=v1.19.15 --pod-network-cidr=10.244.0.0/16 --service-cidr=10.1.0.0/16
W0409 15:49:29.348063 11700 configset.go:348] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io]
[init] Using Kubernetes version: v1.19.15
[preflight] Running pre-flight checks
error execution phase preflight: [preflight] Some fatal errors occurred:
[ERROR FileContent--proc-sys-net-ipv4-ip_forward]: /proc/sys/net/ipv4/ip_forward contents are not set to 1
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
To see the stack trace of this error execute with --v=5 or higher
在 Kubernetes 初始化时,出现了一个错误,提示 /proc/sys/net/ipv4/ip_forward 的值不是 1,这个参数控制的是内核是否允许 IP 转发。通常在集群中,IP 转发需要启用,因为容器之间需要跨主机通信。
解决步骤:
1.启用 IP 转发:
执行以下命令将 IP 转发设置为 1:
sudo sysctl -w net.ipv4.ip_forward=1
2.持久化配置:
为了在系统重启后仍然保留该设置,你需要将它写入配置文件中。编辑 /etc/sysctl.conf 文件:
sudo vim /etc/sysctl.conf
添加或确保以下行存在:
net.ipv4.ip_forward = 1
然后,应用更改:
sudo sysctl -p
3.重新运行 kubeadm init:
在启用 IP 转发并确保设置生效后,重新运行 kubeadm init 命令:
kubeadm init --image-repository registry.aliyuncs.com/google_containers --apiserver-advertise-address=192.168.53.141 --kubernetes-version=v1.19.15 --pod-network-cidr=10.244.0.0/16 --service-cidr=10.1.0.0/16
其他注意事项:
忽略该错误:如果你确定你知道你在做什么,并希望跳过这个检查,可以使用 --ignore-preflight-errors=FileContent--proc-sys-net-ipv4-ip_forward 来忽略这个错误:
kubeadm init --image-repository registry.aliyuncs.com/google_containers --apiserver-advertise-address=192.168.53.141 --kubernetes-version=v1.19.15 --pod-network-cidr=10.244.0.0/16 --service-cidr=10.1.0.0/16 --ignore-preflight-errors=FileContent--proc-sys-net-ipv4-ip_forward
但是,建议还是按上面的步骤启用 IP 转发,因为它是 Kubernetes 集群正常运行所必需的。
浙公网安备 33010602011771号