k8s节点的删除与添加
1、删除节点操作如下:
在k8s-master节点进行
kubectl get node -o wide
驱逐该node节点的pod
kubectl drain nodes NODE-NAME --delete-local-data --force --ignore-daemonsets
删除节点
kubectl delete node NODE-NAME
2、将已删除的节点新增到集群
A.需要在k8s-master节点创建token,默认token是24小时内有效,
# kubeadm token create
usdfsdd.ipw2wfdssdfrwgsdf
获取ca证书sha256编码hash值
# openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^ .* //'
(stdin)=9c61607c11aac0a533345bacf6eca697b45bf9f0bf502df2fe243d9db20e9290
kubeadm token create --ttl 0 --print-join-command
B.然后在要加入的node节点执行:
删除的节点重新初始化
kubeadm reset
再执行加入命令
kubeadm join kubeadm.sy.com:6443 --token usdfsdd.ipw2wfdssdfrwgsdf --discovery-token-ca-cert-hash sha256:9c61607c11aac0a533345bacf6eca697b45bf9f0bf502df2fe243d9db20e9290
3、将新主机接入到k8s集群
系统配置:
swap=0,
net.ipv4.conf.all.forwarding=1
装包:docker/kubeadm/kubelet/kubectl
yum install -y kubeadm-1.20.1-0.x86_64 kubelet-1.20.1-0.x86_64 kubectl-1.20.1-0.x86_64 docker-ce-cli.x86_64 docker-ce.x86_64
配置:
/etc/sysctl.d/k8s.conf
/etc/systemd/system/docker.service.d/docker.conf
启动docker服务:
systemctl daemon-reload;systemctl restart docker ;systemctl enable docker"
加入k8s集群:
kubeadm reset
kubeadm join kubeadm.sy.com:6443 --token usdfsdd.ipw2wfdssdfrwgsdf --discovery-token-ca-cert-hash sha256:9c61607c11aac0a533345bacf6eca697b45bf9f0bf502df2fe243d9db20e9290
验证:
master节点:kubectl get nodes
如果有帮到你,请点个赞,谢谢。