1.6. 安装和配置 OADP
1.6.1. 安装 OADP
您可以使用 OpenShift API for Data Protection (OADP)与 Red Hat OpenShift Service on AWS (ROSA) 集群来备份和恢复应用程序数据。
在为数据保护(OADP)安装 OpenShift API 前,您必须为 OADP 设置角色和策略凭证,以便它可以使用 Amazon Web Services API。
这个过程在以下两个阶段执行:
- 准备 AWS 凭证
- 安装 OADP Operator 并为其提供 IAM 角色
1.6.1.1. 为 OADP 准备 AWS 凭证
必须准备 Amazon Web Services 帐户,并配置为接受 OpenShift API for Data Protection (OADP) 安装。
流程
运行以下命令来创建以下环境变量:
重要更改集群名称来匹配您的 ROSA 集群,并确保以管理员身份登录到集群。在继续操作前,确保所有字段被正常输出。
$ export CLUSTER_NAME=my-cluster 1 export ROSA_CLUSTER_ID=$(rosa describe cluster -c ${CLUSTER_NAME} --output json | jq -r .id) export REGION=$(rosa describe cluster -c ${CLUSTER_NAME} --output json | jq -r .region.id) export OIDC_ENDPOINT=$(oc get authentication.config.openshift.io cluster -o jsonpath='{.spec.serviceAccountIssuer}' | sed 's|^https://||') export AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text) export CLUSTER_VERSION=$(rosa describe cluster -c ${CLUSTER_NAME} -o json | jq -r .version.raw_id | cut -f -2 -d '.') export ROLE_NAME="${CLUSTER_NAME}-openshift-oadp-aws-cloud-credentials" export SCRATCH="/tmp/${CLUSTER_NAME}/oadp" mkdir -p ${SCRATCH} echo "Cluster ID: ${ROSA_CLUSTER_ID}, Region: ${REGION}, OIDC Endpoint: ${OIDC_ENDPOINT}, AWS Account ID: ${AWS_ACCOUNT_ID}"
- 1
- 将
my-cluster
替换为您的 ROSA 集群名称。
在 AWS 帐户中,创建一个 IAM 策略以允许访问 AWS S3:
运行以下命令,检查策略是否存在:
$ POLICY_ARN=$(aws iam list-policies --query "Policies[?PolicyName=='RosaOadpVer1'].{ARN:Arn}" --output text) 1
- 1
- 将
RosaOadp
替换为您的策略名称。
输入以下命令来创建策略 JSON 文件,然后在 ROSA 中创建策略:
注意如果没有找到策略 ARN,命令会创建策略。如果策略 ARN 已存在,则
if
语句会有意跳过策略创建。$ if [[ -z "${POLICY_ARN}" ]]; then cat << EOF > ${SCRATCH}/policy.json 1 { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:CreateBucket", "s3:DeleteBucket", "s3:PutBucketTagging", "s3:GetBucketTagging", "s3:PutEncryptionConfiguration", "s3:GetEncryptionConfiguration", "s3:PutLifecycleConfiguration", "s3:GetLifecycleConfiguration", "s3:GetBucketLocation", "s3:ListBucket", "s3:GetObject", "s3:PutObject", "s3:DeleteObject", "s3:ListBucketMultipartUploads", "s3:AbortMultipartUpload", "s3:ListMultipartUploadParts", "ec2:DescribeSnapshots", "ec2:DescribeVolumes", "ec2:DescribeVolumeAttribute", "ec2:DescribeVolumesModifications", "ec2:DescribeVolumeStatus", "ec2:CreateTags", "ec2:CreateVolume", "ec2:CreateSnapshot", "ec2:DeleteSnapshot" ], "Resource": "*" } ]} EOF POLICY_ARN=$(aws iam create-policy --policy-name "RosaOadpVer1" \ --policy-document file:///${SCRATCH}/policy.json --query Policy.Arn \ --tags Key=rosa_openshift_version,Value=${CLUSTER_VERSION} Key=rosa_role_prefix,Value=ManagedOpenShift Key=operator_namespace,Value=openshift-oadp Key=operator_name,Value=openshift-oadp \ --output text) fi
- 1
SCRATCH
是为环境变量创建的临时目录的名称。
运行以下命令来查看策略 ARN:
$ echo ${POLICY_ARN}
为集群创建 IAM 角色信任策略:
运行以下命令来创建信任策略文件:
$ cat <<EOF > ${SCRATCH}/trust-policy.json { "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Principal": { "Federated": "arn:aws:iam::${AWS_ACCOUNT_ID}:oidc-provider/${OIDC_ENDPOINT}" }, "Action": "sts:AssumeRoleWithWebIdentity", "Condition": { "StringEquals": { "${OIDC_ENDPOINT}:sub": [ "system:serviceaccount:openshift-adp:openshift-adp-controller-manager", "system:serviceaccount:openshift-adp:velero"] } } }] } EOF
运行以下命令来创建角色:
$ ROLE_ARN=$(aws iam create-role --role-name \ "${ROLE_NAME}" \ --assume-role-policy-document file://${SCRATCH}/trust-policy.json \ --tags Key=rosa_cluster_id,Value=${ROSA_CLUSTER_ID} \ Key=rosa_openshift_version,Value=${CLUSTER_VERSION} \ Key=rosa_role_prefix,Value=ManagedOpenShift \ Key=operator_namespace,Value=openshift-adp \ Key=operator_name,Value=openshift-oadp \ --query Role.Arn --output text)
运行以下命令来查看角色 ARN:
$ echo ${ROLE_ARN}
运行以下命令,将 IAM 策略附加到 IAM 角色:
$ aws iam attach-role-policy --role-name "${ROLE_NAME}" \ --policy-arn ${POLICY_ARN}
1.6.1.2. 安装 OADP Operator 并提供 IAM 角色
AWS 安全令牌服务 (AWS STS) 是一个全局 Web 服务,它为 IAM 或联邦用户提供简短凭证。使用 STS 的 Red Hat OpenShift Service on AWS (ROSA) 是 ROSA 集群的建议凭证模式。本文档论述了如何使用 AWS STS 在 ROSA 上安装 OpenShift API for Data Protection (OADP)。
不支持 Restic。
在备份没有 Container Storage Interface (CSI) 快照支持的文件系统时,支持 Kopia 文件系统备份(FSB)。
文件系统示例包括:
- Amazon Elastic File System (EFS)
- 网络文件系统 (NFS)
-
emptyDir
卷 - 本地卷
对于备份卷,使用 AWS STS 的 ROSA 上 OADP 仅支持原生快照和 Container Storage Interface (CSI) 快照。
在使用 STS 验证的 Amazon ROSA 集群中,不支持在不同的 AWS 区域中恢复备份数据。
目前,ROSA 集群不支持 Data Mover 功能。您可以使用原生 AWS S3 工具移动数据。
先决条件
-
具有所需访问和令牌的 Red Hat OpenShift Service on AWS ROSA 集群。具体步骤请查看为 OADP 准备 AWS 凭证。如果您计划使用两个不同的集群来备份和恢复,您必须为每个集群准备 AWS 凭证,包括
ROLE_ARN
。
流程
输入以下命令,从 AWS 令牌文件创建 Red Hat OpenShift Service on AWS secret:
创建凭证文件:
$ cat <<EOF > ${SCRATCH}/credentials [default] role_arn = ${ROLE_ARN} web_identity_token_file = /var/run/secrets/openshift/serviceaccount/token region = <aws_region> 1 EOF
- 1
- 将
<aws_region
> 替换为用于 STS 端点的 AWS 区域。
为 OADP 创建命名空间:
$ oc create namespace openshift-adp
创建 Red Hat OpenShift Service on AWS secret:
$ oc -n openshift-adp create secret generic cloud-credentials \ --from-file=${SCRATCH}/credentials
注意在 Red Hat OpenShift Service on AWS 4.15 及之后的版本中,OADP Operator 通过 Operator Lifecycle Manager (OLM)和 Cloud Credentials Operator (CCO)支持新的标准化 STS 工作流。在此工作流中,您不需要创建上述 secret,您只需要在使用 Red Hat OpenShift Service on AWS Web 控制台安装 OLM 管理的 Operator 的过程中提供角色 ARN,请参阅使用 Web 控制台从 OperatorHub 安装。
前面的 secret 由 CCO 自动创建。
安装 OADP Operator:
-
在 Red Hat OpenShift Service on AWS Web 控制台中浏览 Operators
OperatorHub。 - 搜索 OADP Operator。
- 在 role_ARN 字段中,粘贴之前创建的 role_arn,再点 Install。
-
在 Red Hat OpenShift Service on AWS Web 控制台中浏览 Operators
输入以下命令,使用 AWS 凭证创建 AWS 云存储:
$ cat << EOF | oc create -f - apiVersion: oadp.openshift.io/v1alpha1 kind: CloudStorage metadata: name: ${CLUSTER_NAME}-oadp namespace: openshift-adp spec: creationSecret: key: credentials name: cloud-credentials enableSharedConfig: true name: ${CLUSTER_NAME}-oadp provider: aws region: $REGION EOF
输入以下命令检查应用程序的存储默认存储类:
$ oc get pvc -n <namespace>
输出示例
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE applog Bound pvc-351791ae-b6ab-4e8b-88a4-30f73caf5ef8 1Gi RWO gp3-csi 4d19h mysql Bound pvc-16b8e009-a20a-4379-accc-bc81fedd0621 1Gi RWO gp3-csi 4d19h
运行以下命令来获取存储类:
$ oc get storageclass
输出示例
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE gp2 kubernetes.io/aws-ebs Delete WaitForFirstConsumer true 4d21h gp2-csi ebs.csi.aws.com Delete WaitForFirstConsumer true 4d21h gp3 ebs.csi.aws.com Delete WaitForFirstConsumer true 4d21h gp3-csi (default) ebs.csi.aws.com Delete WaitForFirstConsumer true 4d21h
注意以下存储类可以正常工作:
- gp3-csi
- gp2-csi
- gp3
- gp2
如果要备份的应用程序或应用程序都使用带有 Container Storage Interface (CSI) 的持久性卷 (PV),建议在 OADP DPA 配置中包含 CSI 插件。
创建
DataProtectionApplication
资源,以配置存储备份和卷快照的存储的连接:如果您只使用 CSI 卷,请输入以下命令部署数据保护应用程序:
$ cat << EOF | oc create -f - apiVersion: oadp.openshift.io/v1alpha1 kind: DataProtectionApplication metadata: name: ${CLUSTER_NAME}-dpa namespace: openshift-adp spec: backupImages: true 1 features: dataMover: enable: false backupLocations: - bucket: cloudStorageRef: name: ${CLUSTER_NAME}-oadp credential: key: credentials name: cloud-credentials prefix: velero default: true config: region: ${REGION} configuration: velero: defaultPlugins: - openshift - aws - csi nodeAgent: 2 enable: false uploaderType: kopia 3 EOF
如果使用 CSI 或非 CSI 卷,请输入以下命令来部署数据保护应用程序:
$ cat << EOF | oc create -f - apiVersion: oadp.openshift.io/v1alpha1 kind: DataProtectionApplication metadata: name: ${CLUSTER_NAME}-dpa namespace: openshift-adp spec: backupImages: true 1 backupLocations: - bucket: cloudStorageRef: name: ${CLUSTER_NAME}-oadp credential: key: credentials name: cloud-credentials prefix: velero default: true config: region: ${REGION} configuration: velero: defaultPlugins: - openshift - aws nodeAgent: 2 enable: false uploaderType: restic snapshotLocations: - velero: config: credentialsFile: /tmp/credentials/openshift-adp/cloud-credentials-credentials 3 enableSharedConfig: "true" 4 profile: default 5 region: ${REGION} 6 provider: aws EOF
现在,您可以备份和恢复 Red Hat OpenShift Service on AWS 应用程序,如 备份应用程序 中所述。
此配置中的 restic
的 enable
参数设置为 false
,因为 OADP 不支持 ROSA 环境中的 Restic。
如果使用 OADP 1.2,请替换此配置:
nodeAgent: enable: false uploaderType: restic
使用以下配置:
restic: enable: false
如果要使用两个不同的集群来备份和恢复,则两个集群必须在云存储 CR 和 OADP DataProtectionApplication
配置中具有相同的 AWS S3 存储名称。
1.6.1.3. 更新 OADP Operator 订阅中 IAM 角色 ARN
当在 ROSA 安全令牌服务(STS)集群中安装 OADP Operator 时,如果您提供不正确的 IAM 角色 Amazon Resource Name (ARN),openshift-adp-controller
pod 会出错。生成的凭证请求包含错误的 IAM 角色 ARN。要使用正确的 IAM 角色 ARN 更新凭证请求对象,您可以编辑 OADP Operator 订阅并使用正确的值修补 IAM 角色 ARN。通过编辑 OADP Operator 订阅,您不必卸载和重新安装 OADP 来更新 IAM 角色 ARN。
先决条件
- 您有一个带有所需访问和令牌的 Red Hat OpenShift Service on AWS STS 集群。
- 您已在 ROSA STS 集群中安装了 OADP。
流程
要验证 OADP 订阅是否有错误的 IAM 角色 ARN 环境变量设置,请运行以下命令:
$ oc get sub -o yaml redhat-oadp-operator
订阅示例
apiVersion: operators.coreos.com/v1alpha1 kind: Subscription metadata: annotations: creationTimestamp: "2025-01-15T07:18:31Z" generation: 1 labels: operators.coreos.com/redhat-oadp-operator.openshift-adp: "" name: redhat-oadp-operator namespace: openshift-adp resourceVersion: "77363" uid: 5ba00906-5ad2-4476-ae7b-ffa90986283d spec: channel: stable-1.4 config: env: - name: ROLEARN value: arn:aws:iam::11111111:role/wrong-role-arn 1 installPlanApproval: Manual name: redhat-oadp-operator source: prestage-operators sourceNamespace: openshift-marketplace startingCSV: oadp-operator.v1.4.2
- 1
- 验证您要更新的
ROLEARN
的值。
运行以下命令,使用正确的角色 ARN 更新订阅的
ROLEARN
字段:$ oc patch subscription redhat-oadp-operator -p '{"spec": {"config": {"env": [{"name": "ROLEARN", "value": "<role_arn>"}]}}}' --type='merge'
其中:
<role_arn>
-
指定要更新的 IAM 角色 ARN。例如,
arn:aws:iam::160…..6956:role/oadprosa….8wlf
.
运行以下命令,验证
secret
对象是否使用正确的角色 ARN 值更新:$ oc get secret cloud-credentials -o jsonpath='{.data.credentials}' | base64 -d
输出示例
[default] sts_regional_endpoints = regional role_arn = arn:aws:iam::160.....6956:role/oadprosa.....8wlf web_identity_token_file = /var/run/secrets/openshift/serviceaccount/token
配置
DataProtectionApplication
自定义资源(CR)清单文件,如下例所示:apiVersion: oadp.openshift.io/v1alpha1 kind: DataProtectionApplication metadata: name: test-rosa-dpa namespace: openshift-adp spec: backupLocations: - bucket: config: region: us-east-1 cloudStorageRef: name: <cloud_storage> 1 credential: name: cloud-credentials key: credentials prefix: velero default: true configuration: velero: defaultPlugins: - aws - openshift
- 1
- 指定
CloudStorage
CR。
运行以下命令来创建
DataProtectionApplication
CR:$ oc create -f <dpa_manifest_file>
运行以下命令,验证
DataProtectionApplication
CR 是否已协调,状态
是否已设置为"True"
:$ oc get dpa -n openshift-adp -o yaml
DataProtectionApplication
示例apiVersion: oadp.openshift.io/v1alpha1 kind: DataProtectionApplication ... status: conditions: - lastTransitionTime: "2023-07-31T04:48:12Z" message: Reconcile complete reason: Complete status: "True" type: Reconciled
运行以下命令,验证
BackupStorageLocation
CR 是否处于 available 状态:$ oc get backupstoragelocations.velero.io -n openshift-adp
BackupStorageLocation
示例NAME PHASE LAST VALIDATED AGE DEFAULT ts-dpa-1 Available 3s 6s true
其他资源