使用kubeadm重新初始化kubernetes集群V1.10.0
不说了反正各种原因会让你的集群失败,尤其在高可用模式下机器特别多比较烦。
失败以后各种坑,想重装总不能让我重装操作系统吧。
cat /etc/redhat-releaseCentOS Linux release 7.4.1708 (Core)
uname -sr
Linux 4.4.127-1.el7.elrepo.x86_64
kubeadm version: &version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.0", GitCommit:"fc32d2f3698e36b93322a3465f63a14e9f0eaead", GitTreeState:"clean", BuildDate:"2018-03-26T16:44:10Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
集群
10.0.19.71 master-etcd-1
10.0.19.72 master-etcd-2
10.0.19.73 master-etcd-3
10.0.19.74 docker-repository
10.0.23.11 k8s-nodes-1
10.0.23.12 k8s-nodes-2
10.0.23.13 k8s-nodes-3
10.0.23.14 k8s-nodes-4
在master-etcd-X 节点执行下面的脚本
#!/bin/bash
# reset.sh
kubeadm reset
# 停止相关服务
systemctl stop docker kubelet etcd
#删除所有容器
docker rm -f $(sudo docker ps -qa)
# 删除/var/lib/kubelet/目录,删除前先卸载,否则会删除不干净
for m in $(sudo tac /proc/mounts | sudo awk '{print $2}'|sudo grep /var/lib/kubelet);do
sudo umount $m||true
done
rm -rf /var/lib/kubelet/
#删除/var/lib/rancher/目录,删除前先卸载
for m in $(sudo tac /proc/mounts | sudo awk '{print $2}'|sudo grep /var/lib/rancher);do
sudo umount $m||true
done
rm -rf /var/lib/rancher/
#删除/run/kubernetes/ 目录
rm -rf /run/kubernetes/
#删除所有的数据卷
docker volume rm $(sudo docker volume ls -q)
#再次显示所有的容器和数据卷,确保没有残留
docker ps -a
docker volume ls
#
yum remove -y docker* kubelet kubectl
rm -rf /var/lib/docker
rm -rf /var/lib/etcd
rm -rf /var/lib/kubelet
rm -rf /var/lib/calico
rm -rf /data/etcd
rm -rf /opt/cni
rm -rf /var/etcd/calico-data
rm -rf /usr/local/bin/Documentation
rm -rf /root/.kube
# 这边有个坑,转发规则如果不清除,导致新的网络不通
iptables -F
iptables -X
iptables -L
find / -type f -name docker*
find / -type f -name calico*
find / -type f -name etcd*
shutdown -r now
重装
#!/bin/bash
# init.sh
yum install -y docker kubelet kubeadm kubectl
systemctl daemon-reload
mkdir -p /data/etcd
# 因为生成的证书都有备份,重新弄的时候就不需要在生成了
mkdir -p /etc/kubernetes/pki/etcd
cp /etc/etcd/ssl/etcd.pem /etc/kubernetes/pki/etcd/client.pem
cp /etc/etcd/ssl/etcd-key.pem /etc/kubernetes/pki/etcd/client-key.pem
cp /etc/etcd/ssl/etcd-root-ca.pem /etc/kubernetes/pki/etcd/ca.pem
cp /etc/etcd/ssl/etcd.pem /etc/kubernetes/pki/etcd/server.pem
cp /etc/etcd/ssl/etcd-key.pem /etc/kubernetes/pki/etcd/server-key.pem
cp /etc/etcd/ssl/etcd.pem /etc/kubernetes/pki/etcd/peer.pem
cp /etc/etcd/ssl/etcd-key.pem /etc/kubernetes/pki/etcd/peer-key.pem
mv -f /etc/docker/daemon.json.rpmsave /etc/docker/daemon.json
systemctl restart docker etcd
sh /etc/kubernetes/downImage.sh
docker ps -a
docker volume ls
# 这一部分 只在主节点72、73节点执行
# scp root@10.0.19.71:/etc/kubernetes/pki/* /etc/kubernetes/pki
rm -rf /etc/kubernetes/pki/api*
systemctl restart kubelet
kubeadm init --config=/etc/kubernetes/config.yaml
更多推荐
所有评论(0)