アプリケーションのバックアップおよび復元

Red Hat OpenShift Service on AWS 4

アプリケーションデータのバックアップおよび復元

Red Hat OpenShift Documentation Team

概要

本書では、アプリケーションのバックアップに関する情報を提供します。

第1章 アプリケーションのバックアップ

Red Hat OpenShift Service on AWS (ROSA) クラスターで OpenShift API for Data Protection (OADP) を使用して、アプリケーションデータをバックアップおよび復元できます。OADP をインストールする前に、AWS API を使用できるように OADP のロールとポリシー認証情報を設定する必要があります。

これは 2 段階のプロセスです。

  1. AWS 認証情報を準備します。
  2. OADP Operator をインストールし、IAM ロールを提供します。

1.1. AWS 認証情報の準備

AWS アカウントは、OADP インストールを受け入れる準備ができている必要があります。

手順

  1. 次のコマンドを実行して、以下の環境変数を作成します。

    注記

    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 | but -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 クラスター名に置き換えます。
  2. AWS アカウントで、S3 へのアクセスを許可する IAM ポリシーを作成します。

    1. 以下のコマンドを実行して、ポリシーが存在するかどうかを確認します。

      $ POLICY_ARN=$(aws iam list-policies --query "Policies[?PolicyName=='RosaOadpVer1'].{ARN:Arn}" -- output text) 1
      1
      RosaOadp は、実際のポリシー名に置き換えます。
    2. 以下のコマンドを使用してポリシー 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",$ echo ${POLICY_ARN}
            "s3:DeleteBucket",cd openshift-docs
            "s3:PutBucketTegging",
            "s3:GetBucketTegging",
            "s3:PutEncryptionConfiguration",
            "s3:GetEncryptionConfiguration",
            "s3:PutLifecycleConfiguration",
            "s3:GetLifecycleConfiguration",
            "s3:GetBucketLocation",
            "s3:ListBucket",
            "s3:GetObject",
            "s3:PutObject",
            "s3:DeleteOgject",
            "s3:ListBucketMultipartUpLoads",
            "s3:AbortMultipartUpLoads",
            "s3:ListMultipartUpLoadParts",
            "s3: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-mane "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 は、環境変数用に作成された一時ディレクトリーの名前です。
    3. 以下のコマンドを実行してポリシー ARN を表示します。

      $ echo ${POLICY_ARN}
  3. クラスターの IAM ロール信頼ポリシーを作成します。

    1. 次のコマンドを実行して、信頼ポリシーファイルを作成します。

      $ 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
    2. 以下のコマンドを実行してロールを作成します。

      $ 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_verson,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)
    3. 次のコマンドを実行して、ロール ARN を表示します。

      $ echo ${ROLE_ARN}
  4. 次のコマンドを実行して、IAM ポリシーを IAM ロールにアタッチします。

    $ aws iam attach-role-policy --role-name "${ROLE_NAME}" \
      --policy-arn ${POLICY_ARN}

次のステップ

  • OADP Operator のインストールを続行し、IAM ロールを提供し ます。

1.2. OADP Operator のインストールおよび IAM ロールの提供

AWS Security Token Service (AWS STS) は、IAM またはフェデレーションされたユーザーの短期認証情報を提供するグローバル Web サービスです。STS を使用した Red Hat OpenShift Service on AWS (ROSA) は、ROSA クラスターに推奨される認証情報モードです。このドキュメントでは、AWS STS を使用して (ROSA) に OpenShift API for Data Protection (OADP) をインストールする方法を説明します。

重要

Restic は、AWS STS 環境を使用した ROSA 上の OADP ではサポートされていません。Restic サービスが無効になっていることを確認します。ネイティブスナップショットを使用してボリュームをバックアップします。詳細は、既知の問題 を参照してください。

前提条件

  • 必要なアクセス権とトークンを備えた ROSA OpenShift クラスター。手順は、AWS 認証情報の準備 の手順を参照してください。

手順

  1. 次のコマンドを入力して、AWS トークンファイルから Openshift シークレットを作成します。

    1. 認証情報ファイルを作成します。

      $ cat <<EOF > ${SCRATCH}/credentials
      [default]
      role_arn = ${ROLE_ARN}
      web_identity_token_file = /var/run/secrets/openshift/serviceaccount/token
      EOF
    2. OpenShift シークレットを作成します。

      $ oc -n openshift-adp create secret generic cloud-credentials \
        --from-file=${SCRATCH}/credentials
  2. OADP Operator をインストールします。

    1. Red Hat OpenShift Service on AWS Web コンソールで、Operators OperatorHub に移動します。
    2. OADP Operator を検索し、インストール をクリックします。
  3. 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
  4. バックアップとボリュームスナップショットが保存されるストレージへの接続を設定するために使用される DataProtectionApplication リソース を作成します。

    $ cat << EOF | oc create -f -
    apiVersion: oadp.openshift.io/v1alpha1
    kind: DataProtectionApplication
    metadata:
      name: ${CLUSTER_NAME}-dpa
      namespace: openshift-adp
    spec:
      backupLocations:
      - bucket:
          cloudStorageRef:
            name: ${CLUSTER_NAME}-oadp
          credential:
            key: credentials
            name: cloud-credentials
          default: true
          config:
            region: ${REGION}
      configuration:
        velero:
          defaultPlugins:
          - openshift
          - aws
          restic:
            enable: false
      snapshotLocations:
      - velero:
          config:
            credentialsFile: /tmp/credentials/openshift-adp/cloud-credentials-credentials 1
            enableSharedConfig: "true" 2
            profile: default 3
            region: ${REGION} 4
          provider: aws
    EOF
    1
    credentialsFile は、Pod のバケット認証情報のマウントされた場所です。
    2
    enableSharedConfig を使用すると、snapshotLocations はバケットに定義された認証情報を共有または再利用できます。
    3
    プロファイルの Velero のデフォルトを default と想定し ます。
    4
    region を AWS リージョン として指定します。これはクラスターリージョンと同じである必要があります。
    注記

    OADP は ROSA 環境で Restic をサポートしていないため、resticenable パラメーターは false に設定されています。

    OADP ドキュメント に記載されているように、OpenShift アプリケーションをバックアップおよび復元する準備が整いました。

1.3. 既知の問題

1.4. 関連情報

法律上の通知

Copyright © 2023 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.