1.4.6 k8s 集群添加 node 节点

各需要加入到 k8s master 集群中的 node 节点都要安装 docker kubeadm kubelet,因此都要重新执行安装 docker kubeadm kubelet 的步骤,即配置 apt 仓库、配置 docker 加速器、安装命令、启动 kubelet 服务。

添加命令为 master 端 kubeadm init 初始化完成之后返回的添加命令

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 10.0.0.100:6443 --token abcdef.0123456789abcdef \
        --discovery-token-ca-cert-hash sha256:3a83a61437d3deb9fa80a5b5c9e1f50973833ce68f412814600f49ef7ce9919f 

注:Node 节点会自动加入到 master 节点,下载镜像并启动 flannel,直到最终在 master 看到 node 处于 Ready 状态。

kubeadm join 10.0.0.100:6443 --token abcdef.0123456789abcdef \
        --discovery-token-ca-cert-hash sha256:3a83a61437d3deb9fa80a5b5c9e1f50973833ce68f412814600f49ef7ce9919f

# 在10.0.0.69、10.0.0.79和10.0.0.89上分别执行上面命令
[root@node1 ~]# kubeadm join 10.0.0.100:6443 --token abcdef.0123456789abcdef \
>         --discovery-token-ca-cert-hash sha256:3a83a61437d3deb9fa80a5b5c9e1f50973833ce68f412814600f49ef7ce9919f
[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/
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Starting the kubelet
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...

This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.

Run 'kubectl get nodes' on the control-plane to see this node join the cluster.

[root@node1 ~]# 

1.4.7 验证 node 节点状态

等待一分钟左右会变成 Ready 状态

[root@k8s-master1 ~]# kubectl get nodes 
NAME                     STATUS   ROLES                  AGE   VERSION
k8s-master1.waluna.top   Ready    control-plane,master   32m   v1.21.1
k8s-master2.waluna.top   Ready    control-plane,master   13m   v1.21.1
k8s-master3.waluna.top   Ready    control-plane,master   12m   v1.21.1
node1.waluna.top         Ready    <none>                 58s   v1.21.1
node2.waluna.top         Ready    <none>                 57s   v1.21.1
node3.waluna.top         Ready    <none>                 55s   v1.21.1
[root@k8s-master1 ~]#