首页 > 其他分享 >K8s Etcd备份与恢复

K8s Etcd备份与恢复

时间:2023-01-17 23:34:30浏览次数:53  
标签:node k8s Etcd kubernetes -- 备份 etc etcd K8s

kubenetes使用Etcd数据库存储集群中的数据,安全起见,一定要备份.

kubeadm 方式部署:

备份

ETCDCTL_API=3 etcdctl snapshot save /opt/etcd.db \
--endpoints=https://127.0.0.1:2379 \
--cacert=/etc/kubernetes/pki/etcd/ca.crt \
--cert=/etc/kubernetes/pki/etcd/server.crt \
--key=/etc/kubernetes/pki/etcd/server.key

#### 演示:
[root@k8s-master-1 ~]# ETCDCTL_API=3 etcdctl snapshot save /opt/etcd.db \
> --endpoints=https://127.0.0.1:2379 \
> --cacert=/etc/kubernetes/pki/etcd/ca.crt \
> --cert=/etc/kubernetes/pki/etcd/server.crt \
> --key=/etc/kubernetes/pki/etcd/server.key
Snapshot saved at /opt/etcd.db

恢复

# 1 先暂停kube-apiserver和etcd容器:
mv /etc/kubernetes/manifests /etc/kubernetes/manifests.bak
mv /var/lib/etcd /var/lib/etcd.bak

# 2 恢复etcd数据
ETCDCTL_API=3 etcdctl snapshot restore \
/opt/etcd.db --data-dir=/var/lib/etcd 

# 3 启动kube-apiserver 和 etcd容器:
mv /etc/kubernetes/manifests.bak /etc/kubernetes/manifests


#### 演示:
[root@k8s-master-1 ~]# mv /etc/kubernetes/manifests /etc/kubernetes/manifests.bak
[root@k8s-master-1 ~]# mv /var/lib/etcd /var/lib/etcd.bak

[root@k8s-master-1 ~]# ETCDCTL_API=3 etcdctl snapshot restore /opt/etcd.db \
--data-dir=/var/lib/etcd 
2023-01-18 07:01:42.935583 I | mvcc: restore compact to 7026586
2023-01-18 07:01:42.942566 I | etcdserver/membership: added member 8e9e05c52164694d [http://localhost:2380] to cluster cdf818194e3a8c32

[root@k8s-master-1 ~]# mv /etc/kubernetes/manifests.bak /etc/kubernetes/manifests

验证

#### 验证(等待一会儿让容器启动):
[root@k8s-master-1 ~]# kubectl get node,deployment,svc,pod -o wide
NAME                STATUS   ROLES           AGE   VERSION   INTERNAL-IP     EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION           CONTAINER-RUNTIME
node/k8s-master-1   Ready    control-plane   55d   v1.25.1   192.168.3.101   <none>        CentOS Linux 7 (Core)   3.10.0-1160.el7.x86_64   docker://20.10.21
node/k8s-node-1     Ready    <none>          55d   v1.25.1   192.168.3.104   <none>        CentOS Linux 7 (Core)   3.10.0-1160.el7.x86_64   docker://20.10.21
node/k8s-node-2     Ready    <none>          55d   v1.25.1   192.168.3.105   <none>        CentOS Linux 7 (Core)   3.10.0-1160.el7.x86_64   docker://20.10.21
node/k8s-node-3     Ready    <none>          55d   v1.25.1   192.168.3.106   <none>        CentOS Linux 7 (Core)   3.10.0-1160.el7.x86_64   docker://20.10.21

NAME                      READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS                          IMAGES                                              SELECTOR
deployment.apps/counter   3/3     3            3           21d   count,count-log-1,count-log-2,ngs   busybox:1.28,busybox:1.28,busybox:1.28,nginx:1.17   app=ng
deployment.apps/www       1/1     1            1           43m   nginx                               nginx                                               app=www

NAME                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)           AGE   SELECTOR
service/counter      NodePort    10.104.53.36     <none>        80:31946/TCP      21d   app=ng
service/java-demo    NodePort    10.97.29.88      <none>        8080:32390/TCP    45d   app=java-demo
service/kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP           55d   <none>
service/memcached    NodePort    10.98.147.155    <none>        11211:32466/TCP   24d   app_env_stage=dev
service/nginx-d      NodePort    10.104.101.166   <none>        80:30280/TCP      24d   app_env_stage=dev
service/redis        NodePort    10.111.151.222   <none>        6379:32040/TCP    24d   app_env_stage=dev

NAME                           READY   STATUS    RESTARTS   AGE     IP               NODE         NOMINATED NODE   READINESS GATES
pod/counter-765fd887f9-4m9ml   4/4     Running   0          12d     10.244.140.104   k8s-node-2   <none>           <none>
pod/counter-765fd887f9-5qkz2   4/4     Running   0          7d22h   10.244.140.110   k8s-node-2   <none>           <none>
pod/counter-765fd887f9-qjlwz   4/4     Running   0          12d     10.244.140.106   k8s-node-2   <none>           <none>
pod/www-7d6cb45fbb-9zk2r       1/1     Running   0          43m     10.244.109.115   k8s-node-1   <none>           <none>

标签:node,k8s,Etcd,kubernetes,--,备份,etc,etcd,K8s
From: https://www.cnblogs.com/zhenxing06/p/17058937.html

相关文章

  • K8s Etcd备份与恢复
    kubenetes使用Etcd数据库存储集群中的数据,安全起见,一定要备份.kubeadm方式部署:1备份ETCDCTL_API=3etcdctlsnapshotsave/opt/etcd.db\--endpoints=https://127.0.0.1......
  • PostgreSQL备份恢复
    一、PostgreSQL备份方案 一)PostgreSQL两种备份方案方案一:逻辑备份——使用pg_dump方案二:物理备份——使用pg_rman二、PostgreSQL逻辑备份恢复 一)逻辑备份:pg_dum......
  • k8s master高可用
    每台master都要部署haproxy,keepalived keepalived配置文件:!ConfigurationFileforkeepalivedglobal_defs{router_idLVS_DEVELscript_userrootenable_s......
  • k8s查看公开的端口
    1、kbgetsvc2,kbdescribesvcdf-kudu-master-service  3,以上kuduweb公开的是31603端口http://192.168.0.69:31603/#/......
  • k8s pod 抓包
    首先安装tcpdump:yuminstalltcpdumpkubectlgetpod-owide查看pod在哪个节点上dockerps查看container的id查看pid:dockerinspect-f{{.State.Pid}}$containeri......
  • mysql定时备份并删除30天前的备份
    backupmysqldatariqi=$(date+%Y-%m-%d)mysqldump-h50.100.13.2-uroot-ptenx#cloud999-P3306-A--lock-tables=0|gzip>/opt/mysql-data-backup/all-data-$ri......
  • 【云原生】k8s 一键部署(ansible)
    目录一、概述二、Ansible部署1)开启记录日志2)去掉第一次连接sshask确认3)配置hosts三、开始编排ansibleplaybook1)创建目录2)节点初始化3)安装docker4)安装k8s相关组件5)k8......
  • 每天一点基础K8S--使用基础ingress进行灰度发布
    利用ingress实现灰度发布1、背景ingress可以实现七层负载,可以根据请求header不同将流量代理到后端不同的service服务。比如:后端网站进行了更新,为了不全网更换,可以利用i......
  • postgresql物理备份工具及lightdb支持情况
    因为postgresql自带的pg_basebackup比较原始,所以有很多三方备份工具,主要有:WAL-E。早期实现的物理备份工具,使用python编写,基于basebackup+wal持续归档,目前已经不维护......
  • 为什么要虚拟化,为什么要容器,为什么要Docker,为什么要K8S?
    前言如标题中的问题所提到的虚拟化,容器,Docker和K8s那样,我们不妨这样问:这些技术到底适用于哪些场景,有没有别的技术可以替代?这些技术的优劣在哪里?下面我将针对性地从以上几......