记一次sealos部署k8s集群之delete了第一台master如何恢复
记一次sealos部署k8s集群之delete了第一台master如何恢复
一、背景描述
使用sealos部署了一套K8S集群
master信息:172.27.100.1、172.27.100.2、172.27.100.3
node信息:172.27.100.4、172.27.100.5
sealos安装在172.27.100.1节点,根目录下/root/.sealos/文件还在!
[root@k8s-master-172.27.100.1 .sealos]# pwd
/root/.sealos
[root@k8s-master-100642573 .sealos]# ls -l default
总用量 8
-rw-r--r-- 1 root root 2928 1月 9 16:04 Clusterfile
drwxr-xr-x 3 root root 252 1月 9 16:03 etc
drwxr--r-- 2 root root 24 1月 9 16:03 logs
drwxr-xr-x 3 root root 4096 1月 9 16:03 pki
drwxr-xr-x 2 root root 93 1月 9 16:03 tmp
现象描述:
因各种原因sealos 第一个节点被搞烂了(原集群中172.27.100.1被移除或其他原因),需要恢复172.27.100.1!
目的:
恢复172.27.100.1 到原K8S集群,并继续承担master角色。
二、恢复172.27.100.1到k8s集群
2.1、备份sealos文件
cp -r default/ default_20250107
2.2、使用sealos清理节点文件
sealos delete --masters 172.27.100.1
2.3、备份原K8S集群etcd
crictl exec -i `crictl ps |grep etcd |awk '{print $1}'` /bin/sh -c "ETCDCTL_API=3 etcdctl --endpoints https://172.27.100.1:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key snapshot save /var/lib/etcd/etcsnapshot_`date +%Y%m%d`.db"
三、重新加入集群
3.1、使用sealos加入集群
sealos add --masters 172.27.100.1
3.2、拉取镜像报错
INFO [2025-01-09 10:40:28] >> pull pause image sealos.hub:5000/pause:3.5
FATA[0000] pulling image: rpc error: code = Unknown desc = failed to pull and unpack image "sealos.hub:5000/pause:3.5": failed to resolve reference "sealos.hub:5000/pause:3.5": failed to do request: Head "http://sealos.hub:5000/v2/pause/manifests/3.5": dial tcp 100.64.25.74:5000: connect: connection refused
Created symlink /etc/systemd/system/multi-user.target.wants/kubelet.service → /etc/systemd/system/kubelet.service.INFO [2025-01-09 10:40:29] >> init kubelet success INFO [2025-01-09 10:40:29] >> init rootfs success
2025-01-09T10:40:29 info Executing pipeline Join in ScaleProcessor.
2025-01-09T10:40:29 info [100.64.25.73:22] will be added as master
2025-01-09T10:40:29 info start to init filesystem join masters...
2025-01-09T10:40:29 info start to copy static files to mast