最近验证了使用velero对k8s进行灾难恢复,操作验证步骤如下:

1. 下载verlero

解压:tar -xvf <RELEASE-TARBALL-NAME>.tar.gz

进入目录:cd <RELEASE-TARBALL-NAME>

2. 安装minio

创建minio凭证 (credentials-velero)

[default]
aws_access_key_id = minio
aws_secret_access_key = minio123

创建minio对象存储

kubectl apply -f examples/minio/00-minio-deployment.yaml

创建minio服务(nodeport)

 apiVersion: v1
 kind: Service
 metadata:
   labels:
     component: minio
   name: minio-node
   namespace: velero
 spec:
   ports:
   - port: 9000
     protocol: TCP
     targetPort: 9000
   selector:
     component: minio
   sessionAffinity: None
   type: NodePort

登录minio查看buckets(已创建名为velero的bucket)

142307edb5ce1bbe781d8e87bf4cfba7.png

3. 安装velero (使用本地集群minio作为备份存储)

./velero install 
    --provider aws 
    --bucket velero 
    --secret-file ./credentials-velero 
    --use-volume-snapshots=false 
    --backup-location-config region=minio,s3ForcePathStyle="true",s3Url=http://minio.velero.svc:9000

查看velero状态

kubectl get pod -n velero

NAME                      READY   STATUS      RESTARTS   AGE
minio-fdd868c5-45zb7      1/1     Running     0          103m
minio-setup-wqcmr         0/1     Completed   0          103m
velero-77565ddf45-srl2w   1/1     Running     0          71m

4. 创建待备份资源

kubectl apply -f examples/nginx-app/base.yaml

#查看创建的资源
kubectl get all -n nginx-example

NAME                                    READY   STATUS    RESTARTS   AGE
pod/nginx-deployment-5754944d6c-9vr2w   1/1     Running   0          115s
pod/nginx-deployment-5754944d6c-tczg9   1/1     Running   0          113s


NAME               TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
service/my-nginx   LoadBalancer   10.233.6.201   <pending>     80:32322/TCP   28m


NAME                               READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/nginx-deployment   2/2     2            2           28m

NAME                                          DESIRED   CURRENT   READY   AGE
replicaset.apps/nginx-deployment-5754944d6c   2         2         2       28m

5. 执行备份

./velero backup create nginx-backup --include-namespaces nginx-example

查看minio中的备份数据(已在minio中创建了对应备份名称的目录及备份文件)

b3e7164287b5cde449fdc4d07ab002b3.png

6. 备份恢复验证

删除之前创建的资源

   kubectl delete  -f examples/nginx-app/base.yaml

   #验证资源已完全删除

   kubectl get all -n nginx-example
   

执行恢复操作

./velero restore create --from-backup nginx-backup  #指定对应的备份名称

验证资源是否恢复

kubectl get all -n nginx-example

NAME                                    READY   STATUS    RESTARTS   AGE
pod/nginx-deployment-5754944d6c-9vr2w   1/1     Running   0          8s
pod/nginx-deployment-5754944d6c-tczg9   1/1     Running   0          8s


NAME               TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
service/my-nginx   LoadBalancer   10.233.33.109   <pending>     80:30734/TCP   7s


NAME                               READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/nginx-deployment   2/2     2            2           8s

NAME                                          DESIRED   CURRENT   READY   AGE
replicaset.apps/nginx-deployment-5754944d6c   2         2         2       8s

查看minio中内容变化(执行恢复后,minio中创建了对应恢复目录及文件)

6854203ba4402423526e6e2cf8d3e476.png

后续更新中……

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐