Velero迁移
简介:
Velero 是一种云原生的 Kubernetes 容灾解决方案,支持标准的K8S集群,既可以是私有云平台也可以是公有云。除了灾备之外它还能做资源移转,支持把容器应用从一个集群迁移到另一个集群。它是一个开源的安全备份和恢复工具,执行灾难恢复,迁移 Kubernetes 集群资源和持久的卷。
该方案功能强大,但是操作稍微复杂些,需要安装相应的客户端和服务端。
Velero工作流程:
流程图


备份过程
本地 Velero 客户端发送备份指令。
Kubernetes 集群内就会创建一个 Backup 对象。
BackupController 监测 Backup 对象并开始备份过程。
BackupController 会向 API Server 查询相关数据。
BackupController 将查询到的数据备份到远端的对象存储。
从以上过程中能看出,使用velero备份k8s集群,需要一个store来存储备份数据,这就需要用到velero-plugin,
velero-plug中有aws以及阿里云的插件,但是没有华为云直接使用的,经过与华为云沟通,说obs也是s3协议的,可以直接用aws插件。
安装
1. 客户端安装
我们现在用的是1.7.0
1 | https://github.com/vmware-tanzu/velero/releases/download/v1.6.3/velero-v1.6.3-linux-amd64.tar.gz |
官方:Velero Docs - Basic Install
1 | tar -zxvf velero-v1.7.0-linux-amd64.tar.gz |
2. 服务端安装
直接安装
创建华为云credentials文件
1 | # vim /root/velero/velero-credentials |
1 | cat>/root/velero/velero-credentials<<EOF |
安装velero服务
1.6.3版本
1 | velero install \ |
1.7.0版本
1 | velero install \ |
- –use-volume-snapshots=true: 是否使用kubernetes的卷快照功能
- –use-restic: 使用开源免费备份工具 restic 备份和还原持久卷数据
使用私服镜像,【使用这个】
obs-zjjpt这个bucket是华为云分给我们的,不能换
1 | velero install \ |
在kubesphere平台上安装
【有报错,可能和华为obs的配置有关系,没有解决,不用这种方式】
我目前使用的是kubesphere平台。直接使用helm安装也很简单。
添加velero仓库
https://vmware-tanzu.github.io/helm-charts/

创建velero应用
使用应用模板部署velero

参数配置
values.yaml
1 | initContainers: |
1 | configuration: |
1 | credentials: |
备份
默认保存30天
一次性备份
1 | velero backup create test-backup --include-namespaces test |
备份名:nginx-backup
指定备份的namespace是test
1 | # 备份全部 |
定时任务
1 | # 创建一个定时任务 |
定时任务就是全量备份的
写17是因为时区问题。17 + 8 = 在1点备份
备份持久化卷
部署一个wordpress
1 | # helm install my-wordpress bitnami/wordpress -n wordpress |
备份
1 | velero backup create wordpress-backup --include-namespaces wordpress --default-volumes-to-restic -n velero |
恢复后数据还在

查看
查看备份
1 | velero get backups |
查看定时任务
1 | velero get schedules |
查看恢复
1 | velero get restore |
查看备份地址
1 | velero get backup-locations |
恢复
从backup恢复
最基本的操作
1 | velero restore create RESTORE_NAME --from-backup BACKUP_NAME |
从schedule恢复
1 | velero restore create restore-sch --from-schedule backup-all --preserve-nodeports --include-namespaces testvelero -n velero2 |
参数
–preserve-nodeports optionalBool[=true] 固定端口
–include-namespaces stringArray 选择性的从全部backup里恢复哪些ns
也可以恢复到其他ns,使用–namespace-mappings进行映射
1 | velero restore create RESTORE_NAME \ |
要在另一个集群B恢复集群A的backup,那就再建一个集群A相同的velero,只是指定一个新的namespace。(默认的ns是velero)
1 | velero install \ |
以后再restor的时候,加上-n velero2
1 | velero restore create RESTORE_NAME --from-backup BACKUP_NAME -n velero2 |
考虑过是不是增加一个backup-location就可以。
1 | # 新增一个backup-location |
尝试了下,不行。问题是找不到密钥。没看找出 传递密码进去的写法。
官方说以后或再resotre命令中增加指定backup-location的参数。
报错
这个报错是用helm安装报错
kubectl -n velero logs deployment/velero
1 | time="2021-12-14T06:32:45Z" level=error msg="No backup storage locations found, at least one is required" controller=backup-storage-location error="no backup storage locations found" error.file="/go/src/github.com/vmware-tanzu/velero/internal/storage/storagelocation.go:93" error.function=github.com/vmware-tanzu/velero/internal/storage.ListBackupStorageLocations logSource="pkg/controller/backup_storage_location_controller.go:62" |
换用Credential文件的形式安装
2, 存储的文件夹
time=”2021-12-14T09:04:30Z” level=info msg=”Backup storage location is invalid, marking as unavailable” backup-storage-location=default controller=backup-storage-location logSource=”pkg/controller/backup_storage_location_controller.go:117”
time=”2021-12-14T09:04:30Z” level=error msg=”Current backup storage locations available/unavailable/unknown: 0/1/0, Backup storage location "default" is unavailable: Backup store contains invalid top-level directories: [middleware pcloud-test])” controller=backup-storage-location logSource=”pkg/controller/backup_storage_location_controller.go:164”

说我提前建好的文件夹不合法
1 | velero backup create test-backup --include-namespaces test |

执行备份是可以成功的,会自动生成一个叫backups的文件夹
然后我用1.7.0的版本测试,发现prefix参数是可以的

会在middleware下产生备份的文件夹
dmz-sit
time=”2021-12-17T06:52:06Z” level=error msg=”Error listing backups in backup store” backupLocation=default controller=backup-sync error=”rpc error: code = Unknown desc = RequestError: send request failed\ncaused by: Get http://1x.xxx.0.3/obs-zjjpt?delimiter=%2F&list-type=2&prefix=dmz-sit%2Fbackups%2F: dial tcp 1x.xxx.0.3:80: i/o timeout” error.file=”/go/src/velero-plugin-for-aws/velero-plugin-for-aws/object_store.go:361” error.function=”main.(*ObjectStore).ListCommonPrefixes” logSource=”pkg/controller/backup_sync_controller.go:182”
备份一直卡住InProgress
describe的信息
1 | State: Running |