Velero 组件一共分两部分,分别是服务端和客户端。
服务端:运行在你 Kubernetes 的集群中
客户端:是一些运行在本地的命令行的工具,需要已配置好 kubectl 及集群 kubeconfig 的机器上
AWS S3 以及兼容 S3 的存储,比如:Minio
Azure BloB 存储
Google Cloud 存储
Aliyun OSS 存储(https://github.com/AliyunContainerService/velero-plugin)
Github项目地址:velero
灾备场景:提供备份恢复k8s集群的能力
迁移场景:提供拷贝集群资源到其他集群的能力(复制同步开发,测试,生产环境的集群配置,简化环境配置)
下面我以腾讯云COS为例安装:
k8s集群版本 :1.19.3
velero版本: 1.6.3
- velero:https://github.com/vmware-tanzu/velero/releases/download/v1.4.2/velero-v1.4.2-linux-amd64.tar.gz
-
- tar xf velero-v1.4.2-linux-amd64.tar.gz
-
- cd velero-v1.4.2-linux-amd64
-
- mv velero /bin/
-
- chmod +x /bin/velero
-
- 查看velero命令是否安装成功
- velero -h
AK和SK登录腾讯云,通过【访问管理】-【访问密钥】-【API密钥管理】进行查看
- vim credentials-velero
-
- [default]
- 3aws_access_key_id = xxx #ak
- 4aws_secret_access_key = xxx # sk
点击存储桶---基础配置---基本信息就可以看到
- velero install \
- --provider aws \
- --plugins ccr.ccs.tencentyun.com/public_images/velero-plugin-for-aws:v1.2.0 \
- --bucket velero-1258897006 \
- --secret-file ./credentials-velero \
- --use-volume-snapshots=false \
- --use-restic \
- --default-volumes-to-restic \
- --kubeconfig /root/.kube/config \
- --backup-location-config region="ap-nanjing",s3ForcePathStyle="false",s3ForcePathStyle="false",s3Url=http://cos.ap-nanjing.myqcloud.com
-
安装完成会看到
- Namespace/velero: attempting to create resource
- 26Namespace/velero: created
- 27ClusterRoleBinding/velero: attempting to create resource
- 28ClusterRoleBinding/velero: created
- 29ServiceAccount/velero: attempting to create resource
- 30ServiceAccount/velero: created
- 31Secret/cloud-credentials: attempting to create resource
- 32Secret/cloud-credentials: created
- 33BackupStorageLocation/default: attempting to create resource
- 34BackupStorageLocation/default: created
- 35Deployment/velero: attempting to create resource
- 36Deployment/velero: created
- 37DaemonSet/restic: attempting to create resource
- 38DaemonSet/restic: created
- 39Velero is installed! ⛵ Use 'kubectl logs deployment/velero -n velero' to view the status.
- ```
-
- 执行看日志是否有报错
- # kubectl logs deployment/velero -n velero
-
- 查看namespace velero命名空间是否创建
-
- kubectl get ns
-
-
- 查看命名空间velero pod服务是否运行正常
- [root@node01 ~]# kubectl get pods -n velero
- NAME READY STATUS RESTARTS AGE
- restic-fv4d2 1/1 Running 0 44h
- restic-pxrkg 1/1 Running 0 44h
- velero-5d75cc4c45-spx8q 1/1 Running 0 44h
- 安装失败或者从新安装执行
- 清理删除velero服务(如需删除重新安装时使用)
-
-
- kubectl delete namespace/velero clusterrolebinding/velero
-
-
- kubectl delete crds -l component=velero
velero-v1.4.2 文件加中有 base.yaml文件测试
- velero-v1.4.2/examples/nginx-app
-
- rw-r--r-- 1 501 dialout 1237 Mar 6 2020 base.yaml
- -rw-r--r-- 1 501 dialout 521 Dec 10 2019 README.md
- -rw-r--r-- 1 501 dialout 2375 Mar 6 2020 with-pv.yaml
- ```
-
- [root@master velero-v1.4.2-linux-amd64]# kubectl apply -f examples/nginx-app/base.yaml
-
- namespace/nginx-example created
- deployment.apps/nginx-deployment
- created service/my-nginx created
-
-
- [root@master velero-v1.4.2-linux-amd64]# 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
-
-
-
- 执行备份 后查看COS存储桶是否有备份文件
-
- velero backup create nginx-backup --include-namespaces nginx-example
-
-
- 删除之前创建的资源
-
-
- 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
- velero install \
- --provider aws \
- --plugins ccr.ccs.tencentyun.com/public_images/velero-plugin-for-aws:v1.2.0 \
- --bucket velero-1258897006 \ #存储桶名
- --secret-file ./credentials-velero \ #凭证
- --use-volume-snapshots=false \
- --use-restic \ #启用静态备份
- --default-volumes-to-restic \ #备份所有 pod 卷
- --kubeconfig /root/.kube/config \ #指定k8s集群配置文件;
-
- --backup-location-config region=minio,s3ForcePathStyle="true",s3Url=http://IP:9000 #这里是刚才部署minio存储的api接口,可以通过mino容器查看。
-
- --backup-location-config region="ap-nanjing",s3ForcePathStyle="false",s3ForcePathStyle="false",s3Url=http://cos.ap-nanjing.myqcloud.com #云存储接口
-
- #备份查看
- velero get backup
-
- #查看定时备份
- velero get schedule
-
- #查看已有的恢复
- velero get restore
-
- #查看插件
- velero get plugins
-
- #备份 namespace
- velero backup create NAMESPACE-backup --include-namespaces NAMESPACE
-
- ##查看备份
- velero backup describe NAMESPACE-backup .
-
- #指定对应的备份名称
- velero restore create --from-backup test-backup
-
- # 每日1点进行备份
- velero create schedule
--schedule="0 1 * * *" -
- # 每日1点进行备份,备份保留72小时
- velero create schedule
--schedule="0 1 * * *" --ttl 72h -
- # 每5小时进行一次备份
- velero create schedule
--schedule="@every 5h" -
- # 每日对 指定 namespace 进行一次备份 (如panshi-qtc-dev)
- velero create schedule
--schedule="@every 24h" --include-namespaces panshi-qtc-dev -
-
- #恢复
- velero restore create --from-backup pvc-backup --restore-volumes
-
-
- [root@master01 velero]# kubectl get po -n db
- NAME READY STATUS RESTARTS AGE
- retail-gitlab-54b9f56b6c-66h9w 1/1 Running 0 25d
- retail-mysql-6b7f8bdfb8-s4nct 1/1 Running 2 116d
- retail-redis-86bd9b5599-5tvlv 1/1 Running 0 21d
-
velero backup create db-backup --include-namespaces db #备份整个db名称空间
restic文件备份是数据
backup备份是yaml、pv、pvc配置文件,是以json为文本