注:
- 此教程需要访问 Oracle Cloud。要注册免费账户,请参阅开始使用 Oracle Cloud Infrastructure Free Tier 。
- 它使用 Oracle Cloud Infrastructure 身份证明、租户和区间示例值。完成实验室时,请将这些值替换为特定于云环境的那些值。
使用 Velero 将 Azure Kubernetes 服务集群或 Amazon EKS 集群迁移到适用于 Kubernetes 的容器引擎
简介
Velero 是一种开源工具,可用于安全地备份和恢复、执行灾难恢复以及迁移 Kubernetes 集群资源和持久性卷。由于 Oracle Cloud Infrastructure (OCI) 对象存储为 S3-Compatible,因此我们可以使用 Velero 的 AWS 插件。在本教程中,我们将使用 Azure Kubernetes 服务 (AKS),但这些步骤也应在 Amazon Elastic Kubernetes 服务 (Amazon EKS) 中无缝运行。
下图概述了处理的工作方式。

在本教程中,我们准备了一个连接了持久卷声明的 NGINX Pod 以及一个定制 index.html 文件和一个虚拟密钥。
> kubectl get pods --n nginx
NAME READY STATUS RESTARTS AGE
task-pv-pod 1/1 Running 0 47h
> kubectl exec -it task-pv-pod --n nginx -- curl localhost
AKS to OKE Migration with PVC attached
>kubectl get secrets --namespace nginx
NAME TYPE DATA AGE
okemigration Opaque 1 2s
目标
- 创建要用于对象存储桶 S3 端点的客户密钥。
- 在 AKS 和 Oracle Cloud Infrastructure Container Engine for Kubernetes (OKE) 中设置 Velero。
- 执行备份和恢复以将 Kubernetes 名称空间迁移到 OKE。
先决条件
- 有关 Kubernetes 的中间知识。
- 将用作备份点的对象存储桶。
- 在对象存储桶中读取/写入用户权限。
- 用于连接到 Kubernetes 集群的计算机上的 Velero 二进制文件,或者在 Microsoft Azure 和 OCI 的 Cloud Shell 内。
任务 1:创建客户密钥所在的 velero-credentials 文件
-
如果您还没有客户密钥,可以按照这些步骤操作。
-
在用于访问 AKS/EKS 和 OKE 群集(或 Cloud Shell)的计算机上,使用以下内容创建文件
velero-credentials:[default] aws_access_key_id=<<Access Key ID>> aws_secret_access_key=<<Generated Key>>
任务 2:下载并安装 Velero
-
在将用于访问集群的计算机上安装 Velero,按照这些步骤操作,或者,如果使用 Cloud Shell,请从此处下载它。
-
使用以下命令继续在 AKS 和 OKE 群集中安装 Velero。
注:如果您下载了二进制文件,请在开头使用 ./ 执行 velero:
velero install \ --provider aws \ --bucket <<Bucket name>> \ --prefix <<Tenancy name>> \ --use-volume-snapshots=false \ --plugins velero/velero-plugin-for-aws:v1.6.0 \ --secret-file <<Location of the file created with the customer secret key>> \ --backup-location-config region=<<Region>>,s3ForcePathStyle="true",s3Url=https://<<tenancy name>>.compat.objectstorage.<<region>>.oraclecloud.com \ --use-node-agent -
通过运行以下命令验证 Velero 是否已安装在 AKS 和 OKE 中。
> kubectl get deployment -n velero NAME READY UP-TO-DATE AVAILABLE AGE velero 1/1 1 1 47h
任务 3:备份集群
-
在 AKS 集群中,运行以下命令。在本教程中,我们将 Azure CLI 与其中下载的 velero 二进制文件结合使用。
velero-v1.11.1-rc.1-linux-amd64> ./velero backup create nginxoke --include-namespaces nginx --default-volumes-to-fs-backup Backup request "nginxoke" submitted successfully. Run `velero backup describe nginxoke` or `velero backup logs nginxoke` for more details. -
验证群集是否已备份。
velero-v1.11.1-rc.1-linux-amd64> ./velero backup describe nginxoke Name: nginxoke Namespace: velero Labels: velero.io/storage-location=default Annotations: velero.io/source-cluster-k8s-gitversion=v1.24.10 velero.io/source-cluster-k8s-major-version=1 velero.io/source-cluster-k8s-minor-version=24 Phase: Completed Namespaces: Included: nginx Excluded: <none> ................. You can also check the Object Storage Bucket: 
任务 4:恢复或迁移到 OKE
-
也就是说,EKS 和 OKE 对持久性卷声明使用不同的
storageClassNames,我们需要创建一个 configMap,将源storageClassNames转换为与 OCI 兼容的类名。为此,我们将使用以下内容创建文件configMap.yaml。将其调整为源storageClassName。重要提示:您必须完成步骤 1,否则您的云池将保持待处理状态。
apiVersion: v1 kind: ConfigMap metadata: # any name can be used; Velero uses the labels (below) # to identify it rather than the name name: change-storage-class-config # must be in the velero namespace namespace: velero # the below labels should be used verbatim in your # ConfigMap. labels: # this value-less label identifies the ConfigMap as # config for a plugin (i.e. the built-in change storage # class restore item action plugin) velero.io/plugin-config: "" # this label identifies the name and kind of plugin # that this ConfigMap is for. velero.io/change-storage-class: RestoreItemAction data: # add 1+ key-value pairs here, where the key is the old # storage class name and the value is the new storage # class name. <old-storage-class>: oci-bv -
使用以下命令将 configMap 应用于 OKE 群集。
kubectl apply -f configMap.yaml -
验证 OKE 群集是否可以从对象存储访问备份。
$ velero get backup NAME STATUS ERRORS WARNINGS CREATED EXPIRES STORAGE LOCATION SELECTOR nginxoke Completed 0 0 2023-07-22 14:40:33 +0300 EEST 29d default <none> -
使用以下命令创建恢复。
$ velero restore create --from-backup nginxoke Restore request "nginxoke-20230722145553" submitted successfully. Run `velero restore describe nginxoke-20230722145553` or `velero restore logs nginxoke-20230722145553` for more details. -
验证恢复状态。
$ velero restore describe nginxoke-20230722145553 Name: nginxoke-20230722145553 Namespace: velero Labels: <none> Annotations: <none> Phase: Completed Total items to be restored: 7 Items restored: 7 Started: 2023-07-22 14:55:54 +0300 EEST Completed: 2023-07-22 14:56:45 +0300 EEST .......... -
验证集群是否已成功迁移。
$ kubectl get pod -n nginx NAME READY STATUS RESTARTS AGE task-pv-pod 1/1 Running 0 2m15s $ kubectl get secrets -n nginx NAME TYPE DATA AGE okemigration Opaque 1 2m21s $ kubectl get pvc -n nginx NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE task-pv-claim Bound csi-d03267f7-32cf-4068-8809-d29aa649dcba 50Gi RWO oci-bv 2m31s $ kubectl exec task-pv-pod -n nginx -- curl http://localhost AKS to OKE Migration with PVC attached
相关链接
确认
- Guido Alejandro Ferreyra(首席云架构师)
更多学习资源
探索 docs.oracle.com/learn 上的其他实验室,或者访问 Oracle Learning YouTube 频道上的更多免费学习内容。此外,请访问 education.oracle.com/learning-explorer 成为 Oracle Learning Explorer。
有关产品文档,请访问 Oracle 帮助中心。
Migrate your Azure Kubernetes Service Cluster or Amazon EKS Cluster to Container Engine for Kubernetes using Velero
F84712-01
August 2023
Copyright © 2023, Oracle and/or its affiliates.