集群增删节点

删除节点

子节点上 执行
kubeadm reset
master节点执行
kubectl delete node n1
删除master节点etcd:
kubectl get pods -n kube-system -o wide | grep etcd
kubectl delete pods etcd-n1 -n kube-system --force --grace-period=0
查看kubeadm配置
kubectl describe configmaps kubeadm-config -n kube-system

添加节点

主节点执行
kubeadm token create --ttl 0 --print-join-command #--ttl 0 不过期

# kubeadm join data.work:6443 --token lynvbe.uypapqbj3n3z7hcv     --discovery-token-ca-cert-hash sha256:f212e13eb8bf40a856aa4771e5049a5522f68bdf102b1c5d7bf0579f767641ff 
#!/bin/bash
if` `[ $EUID -ne ``0` `];then
echo ``"You must be root (or sudo) to run this script"
exit ``1
fi
if` `[ $# != ``1` `] ; then
echo ``"Usage: $0 [master-hostname | master-ip-address]"
echo ``" e.g.: $0 api.k8s.hiko.im"
exit ``1``;
fi

token=`kubeadm token create`
cert_hash=`openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der ``2``>/dev/``null` `| openssl dgst -sha256 -hex | sed ``'s/^.* //'```
echo ``"Refer the following command to join kubernetes cluster:"
echo ``"kubeadm join $1:6443 --token ${token} --discovery-token-ca-cert-hash sha256:${cert_hash}"

添加worker节点

kubeadm join data.work:6443 --token lynvbe.uypapqbj3n3z7hcv --discovery-token-ca-cert-hash sha256:f212e13eb8bf40a856aa4771e5049a5522f68bdf102b1c5d7bf0579f767641ff

添加master节点

kubeadm init phase upload-certs --upload-certs #生成--control-plane --certificate-key
执行结果:

kubeadm join data.work:``6443` `--token lynvbe.uypapqbj3n3z7hcv     --discovery-token-ca-cert-hash sha256:f212e13eb8bf40a856aa4771e5049a5522f68bdf102b1c5d7bf0579f7 --control-plane --certificate-key   363ef80c71f5fcb506f9365fb34cfc1f1c8960fe32ecd1ca20e7d59cca90f66d

参考:
https://blog.51cto.com/juestnow/2435061
https://www.yinyubo.cn/?p=542

你可能感兴趣的:(集群增删节点)