etcd 备份还原

etcd 备份还原

1. 查看 etcdctl 是否已经安装

shell 复制代码
# quick check if etcdctl is available or not
ETCDCTL_API=3 etcdctl --help | head

2. 安装 etcdctl

shell 复制代码
# 获取 etcd 版本信息
kubectl exec -it etcd-master -n kube-system -- /bin/sh -c 'ETCDCTL_API=3 /usr/local/bin/etcd --version' | head

# 下载
export RELEASE="3.4.3"
https://github.com/etcd-io/etcd/releases/download/v${RELEASE}/etcd-v${RELEASE}-linux-amd64.tar.gz

# 解压
tar -zxvf etcd-v${RELEASE}-linux-amd64.tar.gz

# 将 etcdctl 拷贝到 、usr/local/bin 目录
cd etcd-v${RELEASE}-linux-amd64
cp etcdctl /usr/local/bin

3. 备份

shell 复制代码
# create a secret
kubectl create secret generic test-secret \
 --from-literal=username='svcaccount' \
 --from-literal=password='password' 
 
 # Verify we are connecting to the right cluster ... define your endpoints and keys 
 ENDPOINT=https://127.0.0.1:2379
 ETCDCTL_API=3 etcdctl --endpoints=$ENDPOINT \
     --cacert=/etc/kubernetes/pki/etcd/ca.crt \
     --cert=/etc/kubernetes/pki/etcd/server.crt \
     --key=/etc/kubernetes/pki/etcd/server.key \
     member list

# Take the backup 
ETCDCTL_API=3 etcdctl --endpoints=$ENDPOINT \
     --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/dat-backup.db
 
 # Read the metadata from the backup/snapshot to print out the snapshot status 
 ETCDCTL_API=3 etcdctl --write-out=table snapshot status /var/lib/dat-backup.db

4. 还原

shell 复制代码
# Delete the secrets
 kubectl delete secret test-secret
 
 # Restore the backup 
  ETCDCTL_API=3 etcdctl snapshot restore /var/lib/dat-backup.db
  
  # Confirm our data is in the restore directory, you should see default.etcd 
  ls -l
  
  # Move the old etcd data to a safe location 
  mv /var/lib/etcd /var/lib/etcd.OLD
  
  # Restart the static pod for etcd 
  # if you use kubectl delete it will NOT restart the static pod as it is managed by the kubelet not a controller 
  docker ps | grep k8s_etcd
  CONTAINER_ID=$(docker ps | grep k8s_etcd | awk '{ print $1 }')
  echo $CONTAINER_ID
  
  # Stop the container from our etcd pod and move restored data into place
  docker stop $CONTAINER_ID
  rm -rf /var/lib/etcd/member
  mv ./default.etcd/member /var/lib/etcd
相关推荐
条纹布鲁斯41 分钟前
dockerdsktop修改安装路径/k8s部署wordpress和ubuntu
docker·kubernetes
登云时刻4 小时前
Kubernetes集群外连接redis集群和使用redis-shake工具迁移数据(一)
redis·kubernetes·bootstrap
吴半杯5 小时前
gateway漏洞(CVE-2022-22947)
docker·kubernetes·gateway
灼烧的疯狂9 小时前
K8S + Jenkins 做CICD
容器·kubernetes·jenkins
企鹅侠客9 小时前
ETCD调优
数据库·etcd
wenyue112110 小时前
Revolutionize Your Kubernetes Experience with Easegress: Kubernetes Gateway API
容器·kubernetes·gateway
gma99913 小时前
Etcd 框架
数据库·etcd
Python私教13 小时前
ubuntu搭建k8s环境详细教程
linux·ubuntu·kubernetes
O&REO14 小时前
单机部署kubernetes环境下Overleaf-基于MicroK8s的Overleaf应用部署指南
云原生·容器·kubernetes
politeboy14 小时前
k8s启动springboot容器的时候,显示找不到application.yml文件
java·spring boot·kubernetes