K8S集群添加新節點


添加新的master節點

獲取token及token證書

root@k8s-master1:~# kubeadm token create --print-join-command 
kubeadm join 192.168.255.100:6443 --token peawzl.bwonk5nviow72m9g --discovery-token-ca-cert-hash sha256:43e1fe29b90eab70840d47a98f9f07dd4efb3b002df16ccfc7e252777d4104cb  

獲取control-plane證書

root@k8s-master1:~# kubeadm init phase upload-certs --upload-certs
[upload-certs] Storing the certificates in Secret "kubeadm-certs" in the "kube-system" Namespace
[upload-certs] Using certificate key:
e1adc057fd80060fa9c6789743480867ebd84973d6b4c1aff3d24393c7a94c1f

在新的master節點執行命令

kubeadm join 192.168.255.100:6443 --token peawzl.bwonk5nviow72m9g \
--discovery-token-ca-cert-hash sha256:43e1fe29b90eab70840d47a98f9f07dd4efb3b002df16ccfc7e252777d4104cb \
--control-plane --certificate-key e1adc057fd80060fa9c6789743480867ebd84973d6b4c1aff3d24393c7a94c1f

添加新的node節點

方法一:

獲取master的join token
kubeadm token create --print-join-command --ttl=0 (--ttl=0代表token永不過期,不加此參數默認24小時過期)
執行完成后,會自動生成以下命令

root@k8s-master1:~# kubeadm token create --print-join-command --ttl=0
kubeadm join 192.168.255.100:6443 --token a38r5e.29xc6zib3vqg2iv0 --discovery-token-ca-cert-hash sha256:43e1fe29b90eab70840d47a98f9f07dd4efb3b002df16ccfc7e252777d4104cb 

在node節點操作:

root@k8s-node1:~# kubeadm join 192.168.255.100:6443 --token a38r5e.29xc6zib3vqg2iv0 --discovery-token-ca-cert-hash sha256:43e1fe29b90eab70840d47a98f9f07dd4efb3b002df16ccfc7e252777d4104cb

方法二:

在master節點操作

root@k8s-master1:~# kubeadm token create
lojsfz.0901j0259yi9yk0a    #生成的token

再執行:

root@k8s-master1:~# openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null |  openssl dgst -sha256 -hex | sed 's/^.* //'
43e1fe29b90eab70840d47a98f9f07dd4efb3b002df16ccfc7e252777d4104cb   #生成的token-ca-cert-hash

在node節點操作:

root@k8s-node1:~# kubeadm join 192.168.255.100:6443 --token lojsfz.0901j0259yi9yk0a  --discovery-token-ca-cert-hash sha256:43e1fe29b90eab70840d47a98f9f07dd4efb3b002df16ccfc7e252777d4104cb


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM