• 欢迎访问运维搬运工网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站。
  • 本站一年会员:100元 ,两年会员:180元 ,永久会员:380元
  • 这世界就是,一些人总在昼夜不停地运转,而另外一些人,起床就发现世界已经变了。
  • 本博客推广的是知识付费,用赞助的方式实现博客维护,不以赚钱为目的的博客

kubernetes集群备份和恢复

例子

创建一个server做测试

[root@master ansible]# kubectl run mysql --image=mysql:5.6 --expose --port=3306
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
service/mysql created
deployment.apps/mysql created

查看是否已下载或者正在下载

[root@master ansible]# kubectl describe pod mysql
Name: mysql-9fb445d7-cgqpk
Namespace: default
Node: 192.168.1.211/192.168.1.211
Start Time: Sat, 09 Mar 2019 00:16:23 +0800
Labels: pod-template-hash=9fb445d7
run=mysql
Annotations: <none>
Status: Running
IP: 172.20.2.5
Controlled By: ReplicaSet/mysql-9fb445d7
Containers:
mysql:
Container ID: docker://723df88b9ed0e72c40029cf7780c2f4490bb65f592981a3587973f297b889862
Image: mysql:5.6
Image ID: docker-pullable://mysql@sha256:3ded8f4be8a6581c02abc3d0fa29e9806716acb2fd4190f65336e9d6e61f5b9c
Port: 3306/TCP
Host Port: 0/TCP
State: Waiting
Reason: CrashLoopBackOff
Last State: Terminated
Reason: Error
Exit Code: 1
Started: Sat, 09 Mar 2019 00:18:21 +0800
Finished: Sat, 09 Mar 2019 00:18:21 +0800
Ready: False
Restart Count: 4
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-r4xwg (ro)
Conditions:
Type Status
Initialized True 
Ready False 
ContainersReady False 
PodScheduled True 
Volumes:
default-token-r4xwg:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-r4xwg
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Pulling 2m19s kubelet, 192.168.1.211 pulling image "mysql:5.6"
Normal Scheduled 2m17s default-scheduler Successfully assigned default/mysql-9fb445d7-cgqpk to 192.168.1.211
Normal Pulled 112s kubelet, 192.168.1.211 Successfully pulled image "mysql:5.6"
Normal Created 21s (x5 over 112s) kubelet, 192.168.1.211 Created container
Normal Started 21s (x5 over 112s) kubelet, 192.168.1.211 Started container
Normal Pulled 21s (x4 over 112s) kubelet, 192.168.1.211 Container image "mysql:5.6" already present on machine
Warning BackOff 20s (x9 over 111s) kubelet, 192.168.1.211 Back-off restarting failed container

[root@master ansible]#

查看是否已经起来了

[root@master ansible]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.68.0.1 <none> 443/TCP 55m
mysql ClusterIP 10.68.51.213 <none> 3306/TCP 3m48s
nginx ClusterIP 10.68.242.35 <none> 80/TCP 39m
[root@master ansible]# kubectl get pod
NAME READY STATUS RESTARTS AGE
mysql-9fb445d7-cgqpk 0/1 CrashLoopBackOff 5 3m50s
nginx-57867cc648-bwzfq 1/1 Running 0 40m

查看在那一台机器上面

[root@master ansible]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
mysql-9fb445d7-fkjdh 0/1 CrashLoopBackOff 5 3m54s 172.20.2.4 192.168.1.211 <none> <none>

备份和恢复

备份恢复原理:
备份,从运行的etcd集群中备份数据到磁盘文件 恢复,把etcd的备份文件恢复到etcd集群中,然后据此重建整个集群。

一键备份

[root@master ansible]# ansible-playbook /etc/ansible/23.backup.yml

模拟故障

[root@master ansible]# ansible-playbook /etc/ansible/99.clean.yml

恢复

[root@master ansible]# ansible-playbook /etc/ansible/24.restore.yml

[root@master ansible]# ansible-playbook /etc/ansible/tools/change_k8s_network.yml

运维搬运工 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:kubernetes集群备份和恢复
喜欢 (0)
[扫描二维码]
分享 (0)
大自然搬运工
关于作者:
不是路不平,而是你不行。到底行不行,看你停不停。只要你不停,早晚都能行。
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址