设为首页 收藏本站
查看: 1220|回复: 0

[经验分享] rke备份和恢复

[复制链接]

尚未签到

发表于 2019-1-31 12:29:51 | 显示全部楼层 |阅读模式

Backups and Disaster Recovery

  As of v0.1.7, you can configure a RKE cluster to automatically take snapshots of etcd. In a disaster scenario, you can restore these snapshots, which are stored on other nodes in the cluster.

One-Time Snapshots
  RKE can take a one-time snapshot of a running etcd node in a RKE cluster. The snapshot is automatically saved in /opt/rke/etcd-snapshots.
  

$ rke etcd snapshot-save --config cluster.yml  

  
WARN[0000] Name of the snapshot is not specified using [rke_etcd_snapshot_2018-05-17T23:32:08+02:00]
  
INFO[0000] Starting saving snapshot on etcd hosts
  
INFO[0000] [dialer] Setup tunnel for host [x.x.x.x]
  
INFO[0001] [dialer] Setup tunnel for host [y.y.y.y]
  
INFO[0002] [dialer] Setup tunnel for host [z.z.z.z]
  
INFO[0003] [etcd] Saving snapshot [rke_etcd_snapshot_2018-05-17T23:32:08+02:00] on host [x.x.x.x]
  
INFO[0004] [etcd] Successfully started [etcd-snapshot-once] container on host [x.x.x.x]
  
INFO[0004] [etcd] Saving snapshot [rke_etcd_snapshot_2018-05-17T23:32:08+02:00] on host [y.y.y.y]
  
INFO[0005] [etcd] Successfully started [etcd-snapshot-once] container on host [y.y.y.y]
  
INFO[0005] [etcd] Saving snapshot [rke_etcd_snapshot_2018-05-17T23:32:08+02:00] on host [z.z.z.z]
  
INFO[0006] [etcd] Successfully started [etcd-snapshot-once] container on host [z.z.z.z]
  
INFO[0006] Finished saving snapshot [rke_etcd_snapshot_2018-05-17T23:32:08+02:00] on all etcd hosts
  

  The command will save a snapshot of etcd from each etcd node in the cluster config file and will save it in /opt/rke/etcd-snapshots. When running the command, an additional container is created to take the snapshot. When the snapshot is completed, the container is automatically removed.

Etcd Recurring Snapshots
  To schedule a recurring automatic etcd snapshot save, you can enable the etcd-snapshot service. etcd-snapshot runs in a service container alongside the etcd container. etcd-snapshot automatically takes a snapshot of etcd and stores them to its local disk in /opt/rke/etcd-snapshots.
  In the cluster.yml, you need to turn enable snapshot as part of the etcd service. Additionally, you want to specify creation and retention for the snapshot service.
  

services:  etcd:
  snapshot: true
  creation: 5m0s
  retention: 24h
  

  When a cluster is launched with the etcd snapshot service enabled, you can view the etcd-snapshot logs to confirm backups are being created automatically.
  

$ docker logs etcd-snapshot  

  
time="2018-05-04T18:39:16Z" level=info msg="Initializing Rolling Backups" creation=1m0s retention=24h0m0s
  
time="2018-05-04T18:40:16Z" level=info msg="Created backup" name="2018-05-04T18:40:16Z_etcd" runtime=108.332814ms
  
time="2018-05-04T18:41:16Z" level=info msg="Created backup" name="2018-05-04T18:41:16Z_etcd" runtime=92.880112ms
  
time="2018-05-04T18:42:16Z" level=info msg="Created backup" name="2018-05-04T18:42:16Z_etcd" runtime=83.67642ms
  
time="2018-05-04T18:43:16Z" level=info msg="Created backup" name="2018-05-04T18:43:16Z_etcd" runtime=86.298499ms
  

  For every node that has the etcd role, these backups are saved to /opt/rke/etcd-snapshots/.

Snapshot Options
  Snapshot
  By default, the recurring snapshot service is disabled. To enable the service, you need to define it as part of etcd and set it to true.
  Creation
  By default, the snapshot service will take snapshots every 5 minutes (5m0s). You can change the time between snapshots as part of the creation directive for the etcd service.
  Retention
  By default, all snapshots are saved for 24 hours (24h) before being deleted and purged. You can change how long to store a snapshot as part of the retention directive for the etcd service.

Etcd Disaster recovery
  If there is a disaster with your Kubernetes cluster, you can use rke etcd snapshot-restore to recover your etcd. This command will revert to a specific snapshot stored in /opt/rke/etcd-snapshots that you explicitly define. During the restore process, RKE also removes the old etcd container before creating a new etcd cluster using the snapshot that you have chosen.

  Warning: Restoring an etcd snapshot deletes your current etcd cluster and replaces it with a new one. Before you run the rke etcd snapshot-restore command, you should back up any important data in your cluster.

  

$ rke etcd snapshot-restore --name mysnapshot --config cluster.yml  
INFO[0000] Starting restore on etcd hosts
  
INFO[0000] [dialer] Setup tunnel for host [x.x.x.x]
  
INFO[0002] [dialer] Setup tunnel for host [y.y.y.y]
  
INFO[0005] [dialer] Setup tunnel for host [z.z.z.z]
  
INFO[0007] [hosts] Cleaning up host [x.x.x.x]
  
INFO[0007] [hosts] Running cleaner container on host [x.x.x.x]
  
INFO[0008] [kube-cleaner] Successfully started [kube-cleaner] container on host [x.x.x.x]
  
INFO[0008] [hosts] Removing cleaner container on host [x.x.x.x]
  
INFO[0008] [hosts] Successfully cleaned up host [x.x.x.x]
  
INFO[0009] [hosts] Cleaning up host [y.y.y.y]
  
INFO[0009] [hosts] Running cleaner container on host [y.y.y.y]
  
INFO[0010] [kube-cleaner] Successfully started [kube-cleaner] container on host [y.y.y.y]
  
INFO[0010] [hosts] Removing cleaner container on host [y.y.y.y]
  
INFO[0010] [hosts] Successfully cleaned up host [y.y.y.y]
  
INFO[0011] [hosts] Cleaning up host [z.z.z.z]
  
INFO[0011] [hosts] Running cleaner container on host [z.z.z.z]
  
INFO[0012] [kube-cleaner] Successfully started [kube-cleaner] container on host [z.z.z.z]
  
INFO[0012] [hosts] Removing cleaner container on host [z.z.z.z]
  
INFO[0012] [hosts] Successfully cleaned up host [z.z.z.z]
  
INFO[0012] [etcd] Restoring [snapshot] snapshot on etcd host [x.x.x.x]
  
INFO[0013] [etcd] Successfully started [etcd-restore] container on host [x.x.x.x]
  
INFO[0014] [etcd] Restoring [snapshot] snapshot on etcd host [y.y.y.y]
  
INFO[0015] [etcd] Successfully started [etcd-restore] container on host [y.y.y.y]
  
INFO[0015] [etcd] Restoring [snapshot] snapshot on etcd host [z.z.z.z]
  
INFO[0016] [etcd] Successfully started [etcd-restore] container on host [z.z.z.z]
  
INFO[0017] [etcd] Building up etcd plane..
  
INFO[0018] [etcd] Successfully started [etcd] container on host [x.x.x.x]
  
INFO[0020] [etcd] Successfully started [rke-log-linker] container on host [x.x.x.x]
  
INFO[0021] [remove/rke-log-linker] Successfully removed container on host [x.x.x.x]
  
INFO[0022] [etcd] Successfully started [etcd] container on host [y.y.y.y]
  
INFO[0023] [etcd] Successfully started [rke-log-linker] container on host [y.y.y.y]
  
INFO[0025] [remove/rke-log-linker] Successfully removed container on host [y.y.y.y]
  
INFO[0025] [etcd] Successfully started [etcd] container on host [z.z.z.z]
  
INFO[0027] [etcd] Successfully started [rke-log-linker] container on host [z.z.z.z]
  
INFO[0027] [remove/rke-log-linker] Successfully removed container on host [z.z.z.z]
  
INFO[0027] [etcd] Successfully started etcd plane..
  
INFO[0027] Finished restoring on all etcd hosts
  

Example
  In this example, the Kubernetes cluster was deployed on two AWS nodes.

Name
IP
Role
node1
10.0.0.1
[controlplane, worker]
node2
10.0.0.2
[etcd]
Back up the etcd cluster
  Take a snapshot of the Kubernetes cluster.
  

$ rke etcd snapshot-save --name snapshot.db --config cluster.yml  

  ![etcd snapshot]({{< baseurl >}}/img/rke/rke-etcd-backup.png)

Store the snapshot externally
  After taking the etcd snapshot on node2, we recommend saving this backup in a persistence place. One of the options is to save the backup on a S3 bucket or tape backup.
  

# If you're using an AWS host and have the ability to connect to S3  
root@node2:~# s3cmd mb s3://rke-etcd-backup
  
root@node2:~# s3cmd /opt/rke/etcdbackup/snapshot.db s3://rke-etcd-backup/
  

Place the backup on a new node
  To simulate the failure, let's power down node2.
  

root@node2:~# poweroff  

  Before restoring etcd and running rancher up, we need to retrieve the backup saved on S3 to a new node, e.g. node3.

Name
IP
Role
node1
10.0.0.1
[controlplane, worker]
node2
10.0.0.2
[etcd]
node3
10.0.0.3
[etcd]  

# Make a Directory  
root@node3:~# mkdir -p /opt/rke/etcdbackup
  
$ Get the Backup from S3
  
root@node3:~# s3cmd get s3://rke-etcd-backup/snapshot.db /opt/rke/etcdbackup/snapshot.db
  

Restore etcd on the new node from the backup
  Before updating and restoring etcd, you will need to add the new node into the Kubernetes cluster with the etcd role. In the cluster.yml, comment out the old node and add in the new node. `
  

nodes:  - address: 10.0.0.1
  hostname_override: node1
  user: ubuntu
  role:
  - controlplane
  - worker
  
#    - address: 10.0.0.2
  
#      hostname_override: node2
  
#      user: ubuntu
  
#      role:
  
#       - etcd
  - address: 10.0.0.3
  hostname_override: node3
  user: ubuntu
  role:
  - etcd
  

  After the new node is added to the cluster.yml, run rke etcd snapshot-restore to launch etcd from the backup.  ]
  

$ rke etcd snapshot-restore --name snapshot.db --config cluster.yml  

  Finally, we need to restore the operations on the cluster by making the Kubernetes API point to the new etcd  by running rke up again using the new cluster.yml.
  

$ rke up --config cluster.yml  

  Confirm that your Kubernetes cluster is functional by checking the pods on your cluster.
  

> kubectl get pods  
NAME                     READY     STATUS    RESTARTS   AGE
  
nginx-65899c769f-kcdpr   1/1       Running   0          17s
  
nginx-65899c769f-pc45c   1/1       Running   0          17s
  
nginx-65899c769f-qkhml   1/1       Running   0          17s



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-670048-1-1.html 上篇帖子: 快速部署kubernetes单master集群 下篇帖子: flannel安装
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表