4月 232020
为集群新增节点
172.31.3.209 k8s01
172.31.8.132 k8s02
172.31.10.229 k8s03
172.31.1.139 k8s04
172.31.15.1 k8s05
新节点加入集群
kubeadm join --token <token> <control-plane-host>:<control-plane-port> --discovery-token-ca-cert-hash sha256:<hash>
主节点生成token有效期为24小时,超过该有效期后需要另行生成。
查看现有token列表
[root@k8s01 ~]# kubeadm token list
TOKEN TTL EXPIRES USAGES DESCRIPTION EXTRA GROUPS
ca673s.97ektx8klpsjfovt 8h 2020-04-23T10:35:25Z authentication,signing <none> system:bootstrappers:kubeadm:default-node-token
qxycbf.ri8i2zygahp5je8m 8h 2020-04-23T10:35:43Z authentication,signing <none> system:bootstrappers:kubeadm:default-node-token
[root@k8s01 ~]#
重新生成token
[root@k8s01 ~]# kubeadm token create
W0423 02:26:28.166475 9469 configset.go:202] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io]
lf1qej.q4wq7xo23xigg672
[root@k8s01 ~]# kubeadm token list
TOKEN TTL EXPIRES USAGES DESCRIPTION EXTRA GROUPS
ca673s.97ektx8klpsjfovt 8h 2020-04-23T10:35:25Z authentication,signing <none> system:bootstrappers:kubeadm:default-node-token
lf1qej.q4wq7xo23xigg672 23h 2020-04-24T02:26:28Z authentication,signing <none> system:bootstrappers:kubeadm:default-node-token
qxycbf.ri8i2zygahp5je8m 8h 2020-04-23T10:35:43Z authentication,signing <none> system:bootstrappers:kubeadm:default-node-token
[root@k8s01 ~]#
重新生成hash值(该值不变)
openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | \
openssl dgst -sha256 -hex | sed 's/^.* //'
[root@k8s01 ~]# openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | \
> openssl dgst -sha256 -hex | sed 's/^.* //'
d435ee7f3795a10b58762be903a78a99c719e3520fb029d718505095b37e9859
[root@k8s01 ~]#
节点4加入
[root@k8s04 ~]# kubeadm join --token lf1qej.q4wq7xo23xigg672 172.31.14.12:6443 --discovery-token-ca-cert-hash sha256:d435ee7f3795a10b58762be903a78a99c719e3520fb029d718505095b37e9859
W0423 02:28:44.283472 19177 join.go:346] [preflight] WARNING: JoinControlPane.controlPlane settings will be ignored when control-plane flag is not set.
[preflight] Running pre-flight checks
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'
[kubelet-start] Downloading configuration for the kubelet from the "kubelet-config-1.18" ConfigMap in the kube-system namespace
[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@k8s04 ~]#
节点5加入
[root@k8s05 ~]# kubeadm join --token lf1qej.q4wq7xo23xigg672 172.31.14.12:6443 --discovery-token-ca-cert-hash sha256:d435ee7f3795a10b58762be903a78a99c719e3520fb029d718505095b37e9859
W0423 02:28:51.716851 19271 join.go:346] [preflight] WARNING: JoinControlPane.controlPlane settings will be ignored when control-plane flag is not set.
[preflight] Running pre-flight checks
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'
[kubelet-start] Downloading configuration for the kubelet from the "kubelet-config-1.18" ConfigMap in the kube-system namespace
[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@k8s05 ~]#
获取节点列表(加入成功)
[root@k8s01 ~]# kubectl get nodes -o wide NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME k8s01 Ready master 2d16h v1.18.2 172.31.14.12 <none> CentOS Linux 7 (Core) 3.10.0-1062.12.1.el7.x86_64 docker://19.3.8 k8s02 Ready <none> 2d16h v1.18.2 172.31.3.249 <none> CentOS Linux 7 (Core) 3.10.0-1062.12.1.el7.x86_64 docker://19.3.8 k8s03 Ready <none> 2d16h v1.18.2 172.31.6.113 <none> CentOS Linux 7 (Core) 3.10.0-1062.12.1.el7.x86_64 docker://19.3.8 k8s04 Ready <none> 78s v1.18.2 172.31.1.139 <none> CentOS Linux 7 (Core) 3.10.0-1062.12.1.el7.x86_64 docker://19.3.8 k8s05 Ready <none> 70s v1.18.2 172.31.15.1 <none> CentOS Linux 7 (Core) 3.10.0-1062.12.1.el7.x86_64 docker://19.3.8 [root@k8s01 ~]#
创建新token并生成完整节点加入命令(一次性)
[root@k8s01 ~]# kubeadm token list TOKEN TTL EXPIRES USAGES DESCRIPTION EXTRA GROUPS ca673s.97ektx8klpsjfovt 7h 2020-04-23T10:35:25Z authentication,signing <none> system:bootstrappers:kubeadm:default-node-token lf1qej.q4wq7xo23xigg672 23h 2020-04-24T02:26:28Z authentication,signing <none> system:bootstrappers:kubeadm:default-node-token qxycbf.ri8i2zygahp5je8m 7h 2020-04-23T10:35:43Z authentication,signing <none> system:bootstrappers:kubeadm:default-node-token [root@k8s01 ~]# kubeadm token create --print-join-command W0423 02:41:47.487117 15377 configset.go:202] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io] kubeadm join 172.31.14.12:6443 --token vc6toc.jhhp9jatexn4ed7m --discovery-token-ca-cert-hash sha256:d435ee7f3795a10b58762be903a78a99c719e3520fb029d718505095b37e9859 [root@k8s01 ~]# kubeadm token list TOKEN TTL EXPIRES USAGES DESCRIPTION EXTRA GROUPS ca673s.97ektx8klpsjfovt 7h 2020-04-23T10:35:25Z authentication,signing <none> system:bootstrappers:kubeadm:default-node-token lf1qej.q4wq7xo23xigg672 23h 2020-04-24T02:26:28Z authentication,signing <none> system:bootstrappers:kubeadm:default-node-token qxycbf.ri8i2zygahp5je8m 7h 2020-04-23T10:35:43Z authentication,signing <none> system:bootstrappers:kubeadm:default-node-token vc6toc.jhhp9jatexn4ed7m 23h 2020-04-24T02:41:47Z authentication,signing <none> system:bootstrappers:kubeadm:default-node-token [root@k8s01 ~]#