使用 Oracle Cloud Object Storage 作为 Velero 备份存储:S3 兼容 API 完整配置指南
【免费下载链接】veleroBackup and migrate Kubernetes applications and their persistent volumes项目地址: https://gitcode.com/GitHub_Trending/ve/velero
导读
本文以 Velero 仓库中 oracle-config.md 为骨架,完整讲解如何把Oracle Cloud Object Storage(OCI Object Storage)配置为 Velero 的备份存储后端。核心思路是利用 Oracle 提供的Amazon S3 兼容 API,让 Velero 以awsprovider 身份接入 OCI 对象存储,从而在不开发专属插件的情况下完成 Kubernetes 应用与持久化数据的备份、灾难恢复与迁移。读完本文,你将掌握从下载 CLI、生成 Customer Secret Key、创建存储桶、执行velero install,到完成一次真实的备份/恢复演练与资源清理的完整链路,并理解--backup-location-config各参数在 Velero 源码与 CRD 层面的落地机制。
适用前提:本文配置命令与参数以仓库 site/content/docs/v1.0.0 文档体系所描述的 Velero v1.0.0 版本为准。新版 Velero 的
velero install已要求显式传入--plugins(见 pkg/cmd/cli/install/install.go 的校验逻辑),但 Oracle 场景的接入思路与 S3 兼容参数保持一致。
整体接入思路:为什么 Oracle 需要“S3 兼容”方案
Velero 通过BackupStorageLocation这一自定义资源描述备份存放位置,其provider字段决定了使用哪个对象存储插件。Velero 原生内置支持aws、gcp、azure三类 provider(见 api-types/backupstoragelocation.md 的参数表)。Oracle Cloud Object Storage 并未提供原生插件,但它的 Object Storage 服务对外暴露了Amazon S3 兼容 API,因此只需复用awsprovider 插件并配置 S3 风格的端点(s3Url)即可接入。
仓库源码也印证了这一机制:在 pkg/repository/config/config.go 中,GetBackendType函数在 provider 无法直接匹配内置后端类型时,会检查配置中是否存在s3Url——只要s3Url非空,就将其识别为AWSBackend(S3 兼容对象存储),注释明确写道:“If the provider doesn't indicate a known backend type, but the endpoint is specified, Velero regards it as a S3 compatible object store and return AWSBackend as the type.”
因此整个接入流程可以概括为四步:拿到 S3 兼容签名密钥 → 创建 OCI 存储桶 → 以 aws provider 安装 Velero 并注入 s3Url → 用标准 velero 命令备份/恢复。
下载 Velero CLI
1. 获取官方发布包
到 Velero 官方 GitHub Releases 页面下载对应版本的发布包,其中包含veleroCLI 工具与示例 Kubernetes 清单文件。例如 v1.0.0 的 Linux 版本:
wget https://github.com/velero-io/velero/releases/download/v1.0.0/velero-v1.0.0-linux-amd64.tar.gz强烈建议使用官方正式发布版本。每个版本的 tarball 内都带有 velero 命令行客户端;而仓库主分支(main)上的代码处于活跃开发状态,不保证稳定。
2. 解压并加入 PATH
tar -xzvf <RELEASE-TARBALL-NAME>.tar.gz为简便起见,可把解压出的目录重命名为velero:
mv velero-v1.0.0-linux-amd64 velero将其加入 PATH:
export PATH=/usr/local/bin/velero:$PATH3. 验证安装
直接运行velero,应看到类似下面的输出:
$ velero Velero is a tool for managing disaster recovery, specifically for Kubernetes cluster resources. It provides a simple, configurable, and operationally robust way to back up your application state and associated data. If you're familiar with kubectl, Velero supports a similar model, allowing you to execute commands such as 'velero get backup' and 'velero create schedule'. The same operations can also be performed as 'velero backup get' and 'velero schedule create'. Usage: velero [command]创建 Customer Secret Key(客户密钥)
Oracle Object Storage 提供了与 Amazon S3 互操作的 API。要使用这套 S3 兼容 API,需要生成用于身份认证的签名密钥——即一组Access Key / Secret Key对(在 OCI 控制台中称为 Customer Secret Key)。
创建步骤:登录 OCI 控制台,进入Identity(身份)→ Users(用户)→ 选择目标用户 → Customer Secret Keys(客户密钥),按 OCI 官方文档“To create a customer secret key”流程生成;更多细节可参考 OCI 官方“Working with Customer Secret Keys”文档(两篇均在 OCI Identity 管理文档的 managingcredentials 章节下)。
生成密钥后,创建 Velero 使用的凭据文件credentials-velero,格式与 AWS CLI 的共享凭据文件完全一致(因为 Velero 走的是 S3 兼容 API,见 pkg/credentials/file_store.go 对凭据文件的读取逻辑):
$ vi credentials-velero [default] aws_access_key_id=bae031188893d1eb83719648790ac850b76c9441 aws_secret_access_key=MmY9heKrWiNVCSZQ2Mf5XTJ6Ys93Bw2d2D6NMSTXZlk=上例中的 Key/Secret 仅为文档演示占位值,请替换为你自己生成的真实密钥,并妥善保管。该文件会在安装时由
--secret-file参数读入,最终以名为cloud-credentials的 Secret 落进集群(见 pkg/cmd/cli/install/install.go 中NewCommand的 Long 描述)。
创建 Oracle Object Storage 存储桶
在 Oracle Cloud tenancy(租户)的根 compartment(根区间)中创建一个名为velero的 Object Storage 存储桶。创建入口为 OCI 控制台的Object Storage → Buckets(存储桶),更详细的创建步骤参见 OCI 官方“Creating a Bucket”文档(managingbuckets 章节)。
桶名不是硬编码要求,
velero仅是本文示例名称,你可以按需命名,并在后续--bucket参数中保持一致。
安装 Velero
安装前先收集以下信息,然后执行velero install:
velero install \ --provider [provider name] \ --bucket [bucket name] \ --prefix [tenancy name] \ --use-volume-snapshots=false \ --secret-file [secret file location] \ --backup-location-config region=[region],s3ForcePathStyle="true",s3Url=[storage API endpoint]各参数含义如下:
| 参数 | 取值说明 |
|---|---|
--provider | 由于使用的是 S3 兼容 API,provider 取aws |
--bucket | 在 Oracle Object Storage 中创建的桶名,本例为velero |
--prefix | 你的 Oracle Cloud tenancy(租户)名称,本例为oracle-cloudnative,所有 Velero 数据将存放在桶内该前缀目录下 |
--use-volume-snapshots=false | Velero 目前没有 Oracle Cloud 的卷快照插件,因此关闭卷快照能力 |
--secret-file | 指向credentials-velero文件 |
--backup-location-config | 指向 Oracle Object Storage 桶的关键配置:region对应 Oracle Cloud 区域名(如us-phoenix-1,完整区域列表见 OCI 官方 Regions 文档);s3Url为该区域对应的 S3 兼容 API 端点,格式为https://<tenancy>.compat.objectstorage.<region name>.oraclecloud.com |
一个真实的示例命令:
velero install \ --provider aws \ --bucket velero \ --prefix oracle-cloudnative \ --use-volume-snapshots=false \ --secret-file /Users/mboxell/bin/velero/credentials-velero \ --backup-location-config region=us-phoenix-1,s3ForcePathStyle="true",s3Url=https://oracle-cloudnative.compat.objectstorage.us-phoenix-1.oraclecloud.com安装背后的源码细节:这些参数如何生效
velero install命令由 pkg/cmd/cli/install/install.go 实现,其中的关键点:
--backup-location-config参数解析:该参数类型为flag.Map,以key1=value1,key2=value2的逗号分隔格式解析,最终通过AsVeleroOptions转成BSLConfig,写入默认的BackupStorageLocation的spec.config(install.go 中BackupStorageConfig字段的定义与赋值)。- 参数校验:
Validate方法会校验--provider、--bucket为必填;当--use-volume-snapshots=false时要求--snapshot-location-config必须为空——这正解释了 Oracle 场景下必须显式传--use-volume-snapshots=false的原因:避免 Velero 尝试为awsprovider 创建默认的卷快照位置(VolumeSnapshotLocation),因为 OCI 场景根本没有可用的卷快照后端。 - 生成的资源:命令会创建
velero命名空间、一批 CRD、ClusterRoleBinding、ServiceAccount、Secret 以及 Velero Deployment。其中--secret-file读入的凭据被封装为名为cloud-credentials的 Secret(见 pkg/install/install.go 中 Secret 的构造逻辑)。 - 排障入口:安装后若 Pod 未能成功就绪,可用
kubectl logs [velero pod name]查看日志定位问题。
BackupStorageLocation 配置参数参考
如果你希望以 YAML 方式直接声明备份存储位置(例如在安装后用velero backup-location create创建),对应 CRD 的核心参数如下(完整表格见 api-types/backupstoragelocation.md):
| Key | 类型 | 默认值 | 含义 |
|---|---|---|---|
provider | string | 必填 | 实际存储备份的云厂商名(本文为aws) |
objectStorage/bucket | string | 必填 | 备份上传的目标桶 |
objectStorage/prefix | string | 可选 | 桶内存放备份数据的子目录(本文对应--prefix的 tenancy 名) |
config/region | string | 空 | 区域名,如us-east-1;不填时向 S3 API 查询 |
config/s3ForcePathStyle | bool | false | 使用本地或 S3 兼容存储(如 Minio、Oracle Object Storage)时置为true |
config/s3Url | string | 非 AWS 托管存储必填 | S3 兼容端点,如http://minio:9000或 Oracle 的.compat.objectstorage.<region>.oraclecloud.com |
config/publicUrl | string | 空 | 生成下载 URL(如日志)时优先使用的公网端点 |
config/signatureVersion | string | "4" | 签名算法版本(1或4),多数场景默认4 |
其中s3ForcePathStyle="true"对 Oracle 场景至关重要:它要求对象存储 SDK 使用“路径风格”访问(https://endpoint/bucket/key)而非虚拟主机风格(https://bucket.endpoint/key),这是 Oracle Object Storage 的 S3 兼容 API 所要求的寻址方式。region则用于 SDK 定位区域级端点与签名。
卸载与清理(Clean Up)
要彻底移除 Velero,删除命名空间、ClusterRoleBinding、ServiceAccount、Secret、Deployment 以及全部 CRD:
kubectl delete namespace/velero clusterrolebinding/velero kubectl delete crds -l component=velerovelero install创建的所有资源都会被这两条命令清理干净。
端到端演练:备份与恢复 nginx 示例应用
安装完成后,仓库提供了现成的示例应用清单 examples/nginx-app/base.yaml,其中包含一个带app: nginx标签的nginx-example命名空间、一个 2 副本的nginx-deploymentDeployment(镜像nginx:1.17.6,暴露 80 端口)以及一个 LoadBalancer 类型的my-nginxService。
1. 启动示例应用(不含持久卷的基础示例)
kubectl apply -f examples/nginx-app/base.yaml$ kubectl apply -f examples/nginx-app/base.yaml namespace/nginx-example created deployment.apps/nginx-deployment created service/my-nginx created用kubectl get all查看已创建的资源:
$ kubectl get all NAME READY STATUS RESTARTS AGE pod/nginx-deployment-67594d6bf6-4296p 1/1 Running 0 20s pod/nginx-deployment-67594d6bf6-f9r5s 1/1 Running 0 20s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/my-nginx LoadBalancer 10.96.69.166 <pending> 80:31859/TCP 21s NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE deployment.apps/nginx-deployment 2 2 2 2 21s NAME DESIRED CURRENT READY AGE replicaset.apps/nginx-deployment-67594d6bf6 2 2 2 21s2. 创建备份
velero backup create nginx-backup --include-namespaces nginx-example$ velero backup create nginx-backup --include-namespaces nginx-example Backup request "nginx-backup" submitted successfully. Run `velero backup describe nginx-backup` or `velero backup logs nginx-backup` for more details.此刻登录 Oracle Cloud Object Storage 控制台,打开我们命名为velero的桶,即可看到 Velero 备份上去的资源数据。
3. 模拟灾难:删除命名空间
kubectl delete namespaces nginx-example$ kubectl delete namespaces nginx-example namespace "nginx-example" deleted等待命名空间删除完成,然后验证 nginx 的 Deployment、Service 和命名空间都已消失:
kubectl get deployments --namespace=nginx-example kubectl get services --namespace=nginx-example kubectl get namespace/nginx-example应返回:No resources found.
4. 恢复丢失的资源
velero restore create --from-backup nginx-backup$ velero restore create --from-backup nginx-backup Restore request "nginx-backup-20190604102710" submitted successfully. Run `velero restore describe nginx-backup-20190604102710` or `velero restore logs nginx-backup-20190604102710` for more details.执行kubectl get namespaces,可以看到nginx-example命名空间连同其中的内容都已被恢复。
5. 查看恢复状态
velero restore get$ velero restore get NAME BACKUP STATUS WARNINGS ERRORS CREATED SELECTOR nginx-backup-20190604104249 nginx-backup Completed 0 0 2019-06-04 10:42:39 -0700 PDT <none>注意:恢复可能需要一些时间,期间STATUS列显示为InProgress。恢复成功后会变为Completed,且WARNINGS与ERRORS均为0——这意味着nginx-example命名空间中的所有对象都已恢复到删除前的状态。
如果出现错误或警告,例如STATUS列显示为FAILED而非InProgress,可用以下命令查看详细原因:
velero restore describe <RESTORE_NAME>6. 清理演练环境与备份
kubectl delete -f examples/nginx-app/base.yaml$ kubectl delete -f examples/nginx-app/base.yaml namespace "nginx-example" deleted deployment.apps "nginx-deployment" deleted service "my-nginx" deleted如需删除已创建的备份(包括对象存储中的备份数据),运行:
velero backup delete BACKUP_NAME$ velero backup delete nginx-backup Are you sure you want to continue (Y/N)? Y Request to delete backup "nginx-backup" submitted successfully. The backup will be fully deleted after all associated data (disk snapshots, backup files, restores) are removed.该命令请求 Velero 服务端删除与BACKUP_NAME关联的全部备份数据,需要为每个想彻底删除的备份各执行一次(文档版本中,未来的 Velero 版本将支持按名称或标签选择器批量删除)。删除完成后,velero backup get BACKUP_NAME将报错,而velero backup get将返回空列表:
$ velero backup get nginx-backup An error occurred: backups.velero.io "nginx-backup" not found$ velero backup get NAME STATUS CREATED EXPIRES STORAGE LOCATION SELECTOR故障排查与进阶参考
- 安装后 Pod 无法就绪:使用
kubectl logs deployment/velero -n velero(或kubectl logs [velero pod name])查看 Velero 服务端日志;常见的失败原因包括s3Url端点拼写错误、region与端点区域不一致、Customer Secret Key 无权限访问目标桶等。 - 备份/恢复失败:优先执行
velero backup describe <BACKUP_NAME>、velero restore describe <RESTORE_NAME>及对应的velero backup logs/velero restore logs查看详细错误。 - 多存储位置:Oracle 场景同样适用于 Velero 的多
BackupStorageLocation机制,可在备份创建时通过--storage-location指定使用哪个位置(见 locations.md);如需切换默认位置,可在velero server上设置--default-backup-storage-location。 - 后端类型识别:从源码 pkg/repository/config/config.go 可以看到,只要 BSL 配置中存在非空的
s3Url,Velero 就会将后端识别为 S3 兼容存储(AWSBackend),这是 Oracle 等一切 S3 兼容厂商接入 Velero 的通用原理。 - 更多 S3 兼容参数:
publicUrl(日志下载公网地址)、signatureVersion(签名版本)等可在 api-types/backupstoragelocation.md 中查阅,按需补充到--backup-location-config。
延伸阅读
- 官方 Velero 文档(仓库内对应 v1.0.0 文档目录为 site/content/docs/v1.0.0,包含 install-overview.md、get-started.md 等入门材料)
- Oracle Cloud Infrastructure 官方文档(Object Storage 概述、桶管理、Customer Secret Key 管理、区域列表均在 OCI 文档中心的对应章节)
【免费下载链接】veleroBackup and migrate Kubernetes applications and their persistent volumes项目地址: https://gitcode.com/GitHub_Trending/ve/velero
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考