k8s etcd 数据损坏处理方式
服务器非正常关机(意外掉电、强制拔电)后 ,etcd 数据损坏
无备份情况
master 报错:
kubectl get nodes
6443连接失败
排查:
查询:docker
docker logs (kube-apiserver)日志
报错如下:
SubChannel #4] grpc: addrConn.createTransport failed to connect to {Addr: "127.0.0.1:2379", ServerName: "127.0.
0.1:2379", }. Err: connection error: desc = "transport: Error while dialing: dial tcp 127.0.0.1:2379: connect: connection refused"
处理:
#1.不知道路径可以查找etcd数据目录
find / -type d -name member
cd /var/lib/etcd/member
mv * /root/member.back
# 注:在故障节点执行,删除或者移走备份都可以
#1.重启etcd
docker ps -a|grep etcd
docker rm -f etcd的ID # 所有节点执行
systemctl restart kubelet # 重启kubelet
#2.查看
kubectl get pods
# 注:此时没有报错了
# 然后重新初始化集群。(缺点就是什么数据都没了)
kubeadm init \
--apiserver-advertise-address=192.168.174.136 \
--image-repository=registry.aliyuncs.com/google_containers \
--kubernetes-version=v1.29.2 \
--service-cidr=10.10.0.0/12 \
--pod-network-cidr=10.244.0.0/16 \
--ignore-preflight-errors=all \
--cri-socket=unix:///var/run/cri-dockerd.sock
etcd版本查询
docker ps -a | grep etcd
829dbbfb08cf a0eed15eed44 "etcd --advertise-cl…" About an hour ago Up About an hour k8s_etcd_etcd-k8s-master_kube-system_ec1fb561c6d9370f8f5b368e02c0c08d_283
6ce9f09a3996 registry.aliyuncs.com/google_containers/pause:3.9 "/pause" About an hour ago Up About an hour k8s_POD_etcd-k8s-master_kube-system_ec1fb561c6d9370f8f5b368e02c0c08d_7
docker exec -it 829dbbfb08cf sh
sh-5.2# etcdctl version
etcdctl version: 3.5.10
API version: 3.5