kubeadm join 命令无法加入node节点,ip_forward 内核参数没有被正确设置
在kubeadm init后,使用给出的命令加入node节点
遇到问题:
[preflight] Running pre-flight checks[WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/[WARNING SystemVerification]: this Docker version is not on the list of validated versions: 26.1.4. Latest validated version: 19.03[WARNING Hostname]: hostname "k8s-node2" could not be reached[WARNING Hostname]: hostname "k8s-node2": lookup k8s-node2 on 114.114.114.114:53: no such host
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
最关键的错误是:
[ERROR FileContent--proc-sys-net-ipv4-ip_forward]: /proc/sys/net/ipv4/ip_forward contents are not set to 1
这个错误表示 ip_forward 参数的值不是 1。ip_forward 允许系统充当路由器,将数据包从一个网络接口转发到另一个,这对于 Kubernetes 中 Pod 之间的跨节点通信至关重要
解决这个问题,需要编辑 /etc/sysctl.d/kubernetes.conf
文件(如果不存在就新建一个)。
-
编辑配置文件:
vi /etc/sysctl.d/kubernetes.conf
-
添加以下内容:
net.ipv4.ip_forward = 1
-
使配置生效:
sysctl --system
完成上述步骤后,重新运行 kubeadm join 命令,应该就能成功将节点加入集群了