当前位置:网站首页>备份kubernetes 备份etcd数据
备份kubernetes 备份etcd数据
2022-07-17 00:16:00 【老段工作室】
1.练习目标
先在环境里准备一个pod1,然后备份etcd数据,然后删除pod1。备份数据里有pod1的,所以通过恢复etcd数据之后,仍然能看到pod1。
2.练习环境
本实验共2台机器,分别是vms71和vms72。
[[email protected] ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
vms71.rhce.cc Ready control-plane,master 2d6h v1.23.2
vms72.rhce.cc Ready <none> 2d6h v1.23.2
[[email protected] ~]#
3.在vms71上安装etcd软件包
[[email protected] ~]# yum install etcd -y
...输出...
完毕!
[[email protected] ~]#
4.实验前的准备
现在当前环境里有一个名字叫做的pod1的pod正在运行。
[[email protected] ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
pod1 1/1 Running 0 42h
[[email protected] ~]#
为了减少备份和恢复时命令的长度,这里先定义一些变量。
[[email protected] ~]# export ETCDCTL_API=3
[[email protected] ~]# cert=/etc/kubernetes/pki/etcd/server.crt
[[email protected] ~]# key=/etc/kubernetes/pki/etcd/server.key
[[email protected] ~]# cacert=/etc/kubernetes/pki/etcd/ca.crt
[[email protected] ~]#
5.备份数据
按照如下命令备份数据。
[[email protected] ~]# etcdctl --endpoints=https://192.168.26.71:2379 --cacert=$cacert --cert=$cert --key=$key snapshot save snap1.data
*Snapshot saved at snap1.data*
[[email protected] ~]#
此时在备份数据里是包括pod1这个pod的。
备份之后删除pod1。
[[email protected] ~]# kubectl delete pod pod1
pod "pod1" deleted
[[email protected] ~]# kubectl get pods
No resources found in default namespace.
[[email protected] ~]#
当前命名空间里不存在pod了,但是备份数据里有。
6.恢复数据
1.关闭kubernetes的核心组件包括etcd。
因为它们是以静态pod的方式运行的,且静态目录是 /etc/kubernetes/manifests/,所以只要把此目录剪切到其他位置即可,这里剪切到/下。
[[email protected] ~]# mv /etc/kubernetes/manifests/ /
[[email protected] ~]#
2.删除原有数据。
[[email protected] ~]# rm -rf /var/lib/etcd/
[[email protected] ~]#
3.恢复数据。
[[email protected] ~]# etcdctl --endpoints=https://192.168.26.71:2379 --cacert=$cacert --cert=$cert --key=$key snapshot restore snap1.data --data-dir=/var/lib/etcd/ --name=vms71.rhce.cc --initial-cluster=vms71.rhce.cc=https://192.168.26.71:2380 --initial-advertise-peer-urls https://192.168.26.71:2380
*2022-02-28 16:58:25.518748 I | mvcc: restore compact to 67960
2022-02-28 16:58:25.526988 I | etcdserver/membership: added member ec884fe58e76ba1a [https://192.168.26.71:2380] to cluster 6ba0775b22f7fb90*
[[email protected] ~]#
这样数据就恢复完成了,这条命令的大部分参数可以到原/etc/kubernetes/manifests/etcd.yaml现在的/manifests/etcd.yaml里找到。
修改所有者和所属组
[[email protected] ~]# chown -R etcd.etcd /var/lib/etcd/
[[email protected] ~]#
4.重启kubelet。
[[email protected] ~]# systemctl restart kubelet
[[email protected] ~]#
5.验证pod是否被恢复了。
[[email protected] ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
pod1 0/1 ContainerCreating 1 42h
[[email protected] ~]#
[[email protected] ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
pod1 1/1 Running 0 42h
[[email protected] ~]#
边栏推荐
- Uni app wechat applet ordering system [another order] page Jump
- Chapter 1 - multi agent system
- Getting to know Alibaba cloud environment construction for the first time: unable to connect remotely, and having been in the pit: the server Ping fails, FTP is built, the server builds the database,
- Longest ascending subsequence - Optimization
- Interface (collection/map) - implementation and comparison of interfaces
- WINRAR命令拷贝指定文件夹为压缩文件,调用计划任务进行备份。
- MySQL初探
- Shell programming specifications and variables
- Leetcode 198:House Robber
- DHCP服务
猜你喜欢
随机推荐
Make a simple record and check the set
Leetcode buckle classic question - 42 Connect rainwater
Bladex - a well-designed microservice architecture
静态路由综合实验
Zabbix6.0监控vCenter7.0
RHCE-ansible-第一次作业
时间管理方法的反思与探讨
PXE automated installation
Mysql database installation
正则表达式
描述DNS解析的工作过程
Image quality evaluation indicators: SNR, PSNR, MSE and SSIM
二进制安装kubernetes 1.24.1
Reprint: SQL injection common bypass
Dirty reading, unreal reading, non repeatable reading
Metersphere is based on JMeter distributed performance pressure testing platform
Subnet division (see details)
Sword finger offer 53 - I. find the number I in the sorted array
Leetcode buckle classic topic - 82 Maximum rectangle in column chart
Echo -e usage









