当前位置:网站首页>备份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] ~]#
边栏推荐
- 数组、冒泡的认识
- HCIA静态综合实验
- The jstat command checks the GC status of the JVM
- Network layer transmission protocol (detailed)
- RHCE8学习指南 第6章 归档与压缩
- Leetcode buckle classic question - 42 Connect rainwater
- Regular and extended expressions, sed text processor and awk tool, changing IP address with script
- Interpretation of concurrent virtual users, RPS and TPS
- Shell脚本变量、脚本编写和执行(部署Apache与远程备份MySQL数据库)
- How to add software shortcuts to the right mouse button list
猜你喜欢

An example of C language callback function & sprinf practical application

静态路由综合实验

The JMeter BeanShell implementation writes the parameterized data generated by the request to the file

10.系统安全及应用

HCIA_RIP实验

PXE automated installation

Method of JMeter connecting to database

Shell programming specifications and variables

HCIA_NAT实验

FTP服务
随机推荐
PXE automated installation
echo -e用法
Let's learn about awk~
静态路由综合实验
Shell脚本case分支语句、扒匿名登录FTP的max地址
The difference between cookies and sessions
Various development tools
单片机之数码管秒表的动态显示
DNS域名解析
[unity Editor Extension] displays the memory size of all files in the resource directory
Interface (collection/map) - implementation and comparison of interfaces
InnoDB, MySQL structure, and the difference between the three kinds of deletion
了解网络命名空间
Traversal of binary tree
Dynamic display of digital tube stopwatch of single chip microcomputer
Bladex - a well-designed microservice architecture
Understand HTTP cache in 30 minutes
Convert string to integer
MySQL备份和恢复
shell脚本接收和返回参数