概述
- 通过Velero client发送Kubernetes API调用去创建备份对象
- BackupController校验Backup对象并执行Backup任务
- BackupController通过API收集服务资源信息
- BackupController通过远程存储API上传备份文件
环境
$ minikube version
minikube version: v1.15.1
部署minio
$ wget https://github.com/vmware-tanzu/velero/releases/download/v1.8.1/velero-v1.8.1-linux-amd64.tar.gz
$ tar zxvf velero-v1.8.1-linux-amd64.tar.gz
$ cd velero-v1.8.1-linux-amd64
$ kubectl apply -f examples/minio/00-minio-deployment.yaml
namespace/velero created
deployment.apps/minio created
service/minio created
job.batch/minio-setup created
$ kubectl get all -n velero
NAME READY STATUS RESTARTS AGE
pod/minio-5b84955bdd-ln68s 1/1 Running 0 4m34s
pod/minio-setup-5vjh5 0/1 Completed 1 7m47s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/minio ClusterIP 10.110.253.72 <none> 9000/TCP 53m
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/minio 1/1 1 1 53m
NAME DESIRED CURRENT READY AGE
replicaset.apps/minio-5b84955bdd 1 1 1 53m
NAME COMPLETIONS DURATION AGE
job.batch/minio-setup 1/1 49m 53m
开发minio服务:(由于系统LB服务,通过端口转发方式开放minio服务)
$ minikube service minio --namespace=velero --url
http://192.168.49.2:31418
$ kubectl edit backupstoragelocation default -n velero
...
在spec.config下面增加
publicUrl: http://192.168.49.2:31418
$ kubectl port-forward --address 0.0.0.0 service/minio -n velero 9000:9000
通过浏览器访问
http://节点IP:9000
即可访问minio服务
$ MINIO_POD=$(kubectl get pods -n velero -l component=minio -o jsonpath='{.items[0].metadata.name}')
$ echo $MINIO_POD
minio-5b84955bdd-hld95
$ kubectl port-forward $MINIO_POD -n velero --address 0.0.0.0 41017:41017
Forwarding from 0.0.0.0:41017 -> 41017
如果浏览器访问9000出现自动端口跳转,增加跳转端口的port-forward即可
用户默认是minio,密码默认是minio123
部署Velero
准备认证信息
$ cat credentials-velero
[default]
aws_access_key_id = minio
aws_secret_access_key = minio123
和minio服务用户信息保持一致
$ velero install \
--provider aws \
--plugins velero/velero-plugin-for-aws:v1.2.1 \
--bucket velero \
--secret-file ./credentials-velero \
--use-volume-snapshots=false \
--backup-location-config region=minio,s3ForcePathStyle="true",s3Url=http://minio.velero.svc:9000
$ kubectl get all -n velero
NAME READY STATUS RESTARTS AGE
pod/minio-5b84955bdd-hld95 1/1 Running 0 15h
pod/minio-setup-xq6bz 0/1 Completed 0 15h
pod/velero-78fbc48cf6-7gwq5 1/1 Running 0 15h
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/minio NodePort 10.98.37.161 <none> 9000:31418/TCP 15h
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/minio 1/1 1 1 15h
deployment.apps/velero 1/1 1 1 15h
NAME DESIRED CURRENT READY AGE
replicaset.apps/minio-5b84955bdd 1 1 1 15h
replicaset.apps/velero-78fbc48cf6 1 1 1 15h
NAME COMPLETIONS DURATION AGE
job.batch/minio-setup 1/1 4s 15h
$ kubectl get crd -n velero
NAME CREATED AT
authorizationpolicies.security.istio.io 2022-04-28T06:38:43Z
backups.velero.io 2022-05-18T08:51:41Z
backupstoragelocations.velero.io 2022-05-18T08:51:41Z
deletebackuprequests.velero.io 2022-05-18T08:51:41Z
destinationrules.networking.istio.io 2022-04-28T06:38:44Z
downloadrequests.velero.io 2022-05-18T08:51:41Z
envoyfilters.networking.istio.io 2022-04-28T06:38:44Z
gateways.networking.istio.io 2022-04-28T06:38:44Z
istiooperators.install.istio.io 2022-04-28T06:38:44Z
peerauthentications.security.istio.io 2022-04-28T06:38:44Z
podvolumebackups.velero.io 2022-05-18T08:51:41Z
podvolumerestores.velero.io 2022-05-18T08:51:41Z
proxyconfigs.networking.istio.io 2022-04-28T06:38:44Z
requestauthentications.security.istio.io 2022-04-28T06:38:44Z
resticrepositories.velero.io 2022-05-18T08:51:41Z
restores.velero.io 2022-05-18T08:51:41Z
schedules.velero.io 2022-05-18T08:51:41Z
serverstatusrequests.velero.io 2022-05-18T08:51:41Z
serviceentries.networking.istio.io 2022-04-28T06:38:45Z
sidecars.networking.istio.io 2022-04-28T06:38:45Z
telemetries.telemetry.istio.io 2022-04-28T06:38:45Z
virtualservices.networking.istio.io 2022-04-28T06:38:45Z
volumesnapshotlocations.velero.io 2022-05-18T08:51:41Z
wasmplugins.extensions.istio.io 2022-04-28T06:38:45Z
workloadentries.networking.istio.io 2022-04-28T06:38:45Z
workloadgroups.networking.istio.io 2022-04-28T06:38:46Z
样例
部署nginx
$ kubectl apply -f examples/nginx-app/base.yaml
namespace/nginx-example created
deployment.apps/nginx-deployment created
service/my-nginx created
$ kubectl get all -n nginx-example
NAME READY STATUS RESTARTS AGE
pod/nginx-deployment-57d5dcb68-2h7v9 1/1 Running 0 66s
pod/nginx-deployment-57d5dcb68-vv682 1/1 Running 0 66s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/my-nginx LoadBalancer 10.110.63.129 <pending> 80:31505/TCP 66s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/nginx-deployment 2/2 2 2 66s
NAME DESIRED CURRENT READY AGE
replicaset.apps/nginx-deployment-57d5dcb68 2 2 2 66s
备份
$ velero backup create nginx-backup --selector app=nginx
Backup request "nginx-backup" submitted successfully.
Run `velero backup describe nginx-backup` or `velero backup logs nginx-backup` for more details.
$ velero backup describe nginx-backup
Name: nginx-backup
Namespace: velero
Labels: velero.io/storage-location=default
Annotations: velero.io/source-cluster-k8s-gitversion=v1.19.4
velero.io/source-cluster-k8s-major-version=1
velero.io/source-cluster-k8s-minor-version=19
Phase: Completed
Errors: 0
Warnings: 0
Namespaces:
Included: *
Excluded: <none>
Resources:
Included: *
Excluded: <none>
Cluster-scoped: auto
Label selector: app=nginx
Storage Location: default
Velero-Native Snapshot PVs: auto
TTL: 720h0m0s
Hooks: <none>
Backup Format Version: 1.1.0
Started: 2022-05-18 17:39:19 +0800 CST
Completed: 2022-05-18 17:39:21 +0800 CST
Expiration: 2022-06-17 17:39:19 +0800 CST
Total items to be backed up: 6
Items backed up: 6
Velero-Native Snapshots: <none included>
$ velero backup get
NAME STATUS ERRORS WARNINGS CREATED EXPIRES STORAGE LOCATION SELECTOR
nginx-backup Completed 0 0 2022-05-18 17:39:19 +0800 CST 29d default app=nginx
恢复
$ velero restore create --from-backup nginx-backup
Restore request "nginx-backup-20220518192710" submitted successfully.
Run `velero restore describe nginx-backup-20220518192710` or `velero restore logs nginx-backup-20220518192710` for more details.
$ kubectl get all -n nginx-example
NAME READY STATUS RESTARTS AGE
pod/nginx-deployment-57d5dcb68-2h7v9 1/1 Running 0 60s
pod/nginx-deployment-57d5dcb68-vv682 1/1 Running 0 60s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/my-nginx LoadBalancer 10.107.71.159 <pending> 80:30708/TCP 60s
NAME DESIRED CURRENT READY AGE
replicaset.apps/nginx-deployment-57d5dcb68 2 2 2 60s
恢复前先删除nginx-example的ns
参考
- https://velero.io/docs/v1.8/contributions/minio/#expose-minio-outside-your-cluster-with-a-service