k8s etcd备份与恢复

停止api-server(k8s的所有master节点)
   # 所有master节点执行:
   # 停api-server

   mkdir -p tpm_api_conf
   mv  /etc/kubernetes/manifests/kube-apiserver.yaml /root/tpm_api_conf/
etcd备份(集群中某一节点)
   # etcd备份

   ETCDCTL_API=3;/usr/local/bin/etcdctl --endpoints='https://192.168.1.30:2379' --cacert="/etc/ssl/etcd/ssl/ca.pem" --cert="/etc/ssl/etcd/ssl/admin-ks-master01.pem" --key="/etc/ssl/etcd/ssl/admin-ks-master01-key.pem" snapshot save  snapshot_20230928.db 
查看备份数据状态
   # 查看备份数据状态

   ETCDCTL_API=3;/usr/local/bin/etcdctl --write-out=table snapshot status snapshot_20230928.db
停止etcd服务并备份数据目录(etcd所有节点)
   # 停etcd:

   systemctl stop etcd
   mv /var/lib/etcd/ /root/etcd_bak
各个etcd节点恢复数据
   # 节点30:

   ETCDCTL_API=3;/usr/local/bin/etcdctl snapshot restore /root/snapshot_20230928.db \
    --name etcd-ks-master01  \
    --cert="/etc/ssl/etcd/ssl/admin-ks-master01.pem" \
    --key="/etc/ssl/etcd/ssl/admin-ks-master01-key.pem"  \
    --cacert="/etc/ssl/etcd/ssl/ca.pem"   \
    --endpoints="https://127.0.0.1:2379" \
    --initial-advertise-peer-urls="https://192.168.1.30:2380"  \
    --initial-cluster="etcd-ks-master01=https://192.168.1.30:2380,etcd-ks-master02=https://192.168.1.31:2380,etcd-ks-master03=https://192.168.1.32:2380" \
    --data-dir=/var/lib/etcd
    
   # 节点31:

   ETCDCTL_API=3;/usr/local/bin/etcdctl snapshot restore /root/snapshot_20230928.db \
    --name etcd-ks-master02  \
    --cert="/etc/ssl/etcd/ssl/admin-ks-master02.pem" \
    --key="/etc/ssl/etcd/ssl/admin-ks-master02-key.pem"  \
    --cacert="/etc/ssl/etcd/ssl/ca.pem"   \
    --endpoints="https://127.0.0.1:2379" \
    --initial-advertise-peer-urls="https://192.168.1.31:2380"  \
    --initial-cluster="etcd-ks-master01=https://192.168.1.30:2380,etcd-ks-master02=https://192.168.1.31:2380,etcd-ks-master03=https://192.168.1.32:2380" \
    --data-dir=/var/lib/etcd
    
   # 节点32:

   ETCDCTL_API=3;/usr/local/bin/etcdctl snapshot restore /root/snapshot_20230928.db \
    --name etcd-ks-master03  \
    --cert="/etc/ssl/etcd/ssl/admin-ks-master03.pem" \
    --key="/etc/ssl/etcd/ssl/admin-ks-master03-key.pem"  \
    --cacert="/etc/ssl/etcd/ssl/ca.pem"   \
    --endpoints="https://127.0.0.1:2379" \
    --initial-advertise-peer-urls="https://192.168.1.32:2380"  \
    --initial-cluster="etcd-ks-master01=https://192.168.1.30:2380,etcd-ks-master02=https://192.168.1.31:2380,etcd-ks-master03=https://192.168.1.32:2380" \
    --data-dir=/var/lib/etcd
etcd节点修改数据目录权限并启动etcd
   # 所有节点执行:
   # 修改属组
   chown -R etcd:root /var/lib/etcd/

   # 启动etcd
   systemctl start etcd
启动api-server(所有k8s master节点)
   # etcd启动完成后,恢复api配置
   mv  /root/tpm_api_conf/kube-apiserver.yaml   /etc/kubernetes/manifests/kube-apiserver.yaml 
相关推荐
让生命变得有价值2 小时前
k8s 启用 ValidatingAdmissionPolicy 特性
java·容器·kubernetes·kubelet
Allocator2 小时前
docker 容器访问宿主机器服务的最简单方法
运维·docker·容器
AlenTech2 小时前
如何设置docker的定时关闭和启动
docker·容器·eureka
我从不骗人4 小时前
Docker使用相关记录
运维·docker·容器
valkyrja1106 小时前
小白docker入门简介
docker·容器·小白·初学
君败红颜12 小时前
Docker 常用命令详解(详细版)
运维·docker·容器
想学习java初学者13 小时前
Docker Compose部署Rabbitmq(Dockerfile安装延迟队列)
docker·容器·rabbitmq
梦游钓鱼16 小时前
windows安装docker
运维·docker·容器
roman_日积跬步-终至千里17 小时前
【Docker】自定义网络:实现容器之间通过域名相互通讯
网络·docker·容器
AlenTech17 小时前
如何设置定时关闭或启动整个docker而不是某个容器
运维·docker·容器