安装 

#!/bin/bash
# Author: WeiyiGeek
# Description: etcd 与 etcdctl 下载安装
ETCD_VER=v3.5.5
ETCD_DIR=etcd-download
DOWNLOAD_URL=https://github.com/coreos/etcd/releases/download
mkdir ${ETCD_DIR}
cd ${ETCD_DIR}
wget ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz 
tar -xzvf etcd-${ETCD_VER}-linux-amd64.tar.gz
cd etcd-${ETCD_VER}-linux-amd64
cp etcdctl /usr/local/bin/

备份

etcdctl --endpoints 127.0.0.1:2379  \
--cert="/etc/kubernetes/pki/etcd/server.crt"  \
--key="/etc/kubernetes/pki/etcd/server.key"  \
--cacert="/etc/kubernetes/pki/etcd/ca.crt"   \
snapshot save etcd_snap_save.db

还原

1.移除且备份 /etc/kubernetes/manifests/

mv /etc/kubernetes/manifests /etc/kubernetes/manifests.bak

查看 kube-apiserver、etcd镜像是否停止或者直接用kubectl命令 查看是否还能使用,不能使用说明操作成功。

 2.备份现有的etcd数据

rm -rf  /var/lib/etcd.bak

mv /var/lib/etcd /var/lib/etcd.bak


 

####移除配置和删除数据
rm -rf  /var/lib/etcd.bak

mv /var/lib/etcd /var/lib/etcd.bak


####移除配置和删除数据
#mkdir -p /opt/
#mv /etc/kubernetes/manifests/etcd.yaml /opt/
if [[ -d /var/lib/etcd ]];then

rm -rf /var/lib/etcd/
fi

####通过命令恢复
etcdctl snapshot restore etcd_snap_save.db  \
--cacert=/etc/kubernetes/pki/etcd/ca.crt  \
--cert=/etc/kubernetes/pki/etcd/server.crt \
--key=/etc/kubernetes/pki/etcd/server.key  \
--data-dir=/var/lib/etcd/   \
--endpoints=https://127.0.0.1:2379

####配置还原
mv /opt/etcd.yaml /etc/kubernetes/manifests/

4.恢复kube-apiserver与etcd

mv /etc/kubernetes/manifests.bak /etc/kubernetes/manifests

参考:k8s etcd 备份和恢复_etcd备份_liudongyang123的博客-CSDN博客

03-27 16:41