Backing up applications on AWS STS using OADP¶
Install the OpenShift API for Data Protection (OADP) with Amazon Web Services (AWS) by installing the OADP Operator. The Operator installs Velero 1.16.
You configure AWS for Velero, create a default Secret, and then install the Data Protection Application. For more details, see Installing the OADP Operator.
To install the OADP Operator in a restricted network environment, you must first disable the default software catalog sources and mirror the Operator catalog. See Using Operator Lifecycle Manager in disconnected environments.
You can install OADP on an AWS Security Token Service (STS) (AWS STS) cluster manually. Amazon AWS provides AWS STS as a web service that enables you to request temporary, limited-privilege credentials for users. You use STS to provide trusted users with temporary access to resources via API calls, your AWS console, or the AWS command-line interface (CLI).
Before installing OpenShift API for Data Protection (OADP), you must set up role and policy credentials for OADP so that it can use the Amazon Web Services API.
This process is performed in the following two stages:
- Prepare AWS credentials.
- Install the OADP Operator and give it an IAM role.
Preparing AWS STS credentials for OADP¶
Configure an Amazon Web Services account to install the OpenShift API for Data Protection (OADP). Prepare the AWS credentials by using the following procedure.
Procedure
-
Define the
cluster_nameenvironment variable by running the following command:Replace
<AWS_cluster_name>with the name of the cluster. -
Retrieve all of the details of the
clustersuch as theAWS_ACCOUNT_ID, OIDC_ENDPOINTby running the following command:$ export CLUSTER_VERSION=$(oc get clusterversion version -o jsonpath='{.status.desired.version}{"\n"}')$ export OIDC_ENDPOINT=$(oc get authentication.config.openshift.io cluster -o jsonpath='{.spec.serviceAccountIssuer}' | sed 's|^https://||') -
Create a temporary directory to store all of the files by running the following command:
-
Display all of the gathered details by running the following command:
-
On the AWS account, create an IAM policy to allow access to AWS S3:
-
Check to see if the policy exists by running the following commands:
POLICY_NAME: The variable can be set to any value.
-
Enter the following command to create the policy JSON file and then create the policy:
Note
If the policy ARN is not found, the command creates the policy. If the policy ARN already exists, the
ifstatement intentionally skips the policy creation.$ if [[ -z "${POLICY_ARN}" ]]; then cat << EOF > ${SCRATCH}/policy.json { "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 $POLICY_NAME \ --policy-document file:///${SCRATCH}/policy.json --query Policy.Arn \ --tags Key=openshift_version,Value=${CLUSTER_VERSION} Key=operator_namespace,Value=openshift-adp Key=operator_name,Value=oadp \ --output text) fiSCRATCH: The name for a temporary directory created for storing the files.
-
View the policy ARN by running the following command:
-
-
Create an IAM role trust policy for the cluster:
-
Create the trust policy file by running the following command:
$ 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 -
Create an IAM role trust policy for the cluster by running the following command:
$ ROLE_ARN=$(aws iam create-role --role-name \ "${ROLE_NAME}" \ --assume-role-policy-document file://${SCRATCH}/trust-policy.json \ --tags Key=cluster_id,Value=${AWS_CLUSTER_ID} Key=openshift_version,Value=${CLUSTER_VERSION} Key=operator_namespace,Value=openshift-adp Key=operator_name,Value=oadp --query Role.Arn --output text) -
View the role ARN by running the following command:
-
-
Attach the IAM policy to the IAM role by running the following command:
Installing the OADP Operator and providing the IAM role¶
Install OpenShift API for Data Protection (OADP) on an AWS STS cluster. AWS Security Token Service (AWS STS) is a global web service that provides short-term credentials for IAM or federated users.
Warning
Restic is unsupported.
Kopia file system backup (FSB) is supported when backing up file systems that do not support Container Storage Interface (CSI) snapshots.
Example file systems include the following:
- Amazon Elastic File System (EFS)
- Network File System (NFS)
emptyDirvolumes- Local volumes
For backing up volumes, OADP on AWS STS recommends native snapshots and Container Storage Interface (CSI) snapshots. Data Mover backups are supported, but can be slower than native snapshots.
In an AWS cluster that uses STS authentication, restoring backed-up data in a different AWS region is not supported.
Prerequisites
- An OpenShift Container Platform AWS STS cluster with the required access and tokens. For instructions, see the previous procedure Preparing AWS credentials for OADP. If you plan to use two different clusters for backing up and restoring, you must prepare AWS credentials, including
ROLE_ARN, for each cluster.
Procedure
-
Create an OpenShift Container Platform secret from your AWS token file by entering the following commands:
-
Create the credentials file:
$ cat <<EOF > ${SCRATCH}/credentials [default] role_arn = ${ROLE_ARN} web_identity_token_file = /var/run/secrets/openshift/serviceaccount/token region = <aws_region> EOFReplace
<aws_region>with the AWS region to use for the STS endpoint. -
Create a namespace for OADP:
-
Create the OpenShift Container Platform secret:
Note
In OpenShift Container Platform versions 4.14 and later, the OADP Operator supports a new standardized STS workflow through the Operator Lifecycle Manager (OLM) and Cloud Credentials Operator (CCO). In this workflow, you do not need to create the above secret, you only need to supply the role ARN during the installation of OLM-managed operators using the OpenShift Container Platform web console, for more information see Installing from the software catalog using the web console.
The preceding secret is created automatically by CCO.
-
-
Install the OADP Operator:
- In the OpenShift Container Platform web console, browse to Ecosystem → Software Catalog.
- Search for the OADP Operator.
- In the role_ARN field, paste the role_arn that you created previously and click Install.
-
Create AWS cloud storage using your AWS credentials by entering the following command:
-
Check your application’s storage default storage class by entering the following command:
-
Get the storage class by running the following command:
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 4d21hNote
The following storage classes will work:
- gp3-csi
- gp2-csi
- gp3
- gp2
If the application or applications that are being backed up are all using persistent volumes (PVs) with Container Storage Interface (CSI), it is advisable to include the CSI plugin in the OADP DPA configuration.
-
Create the
DataProtectionApplicationresource to configure the connection to the storage where the backups and volume snapshots are stored:-
If you are using only CSI volumes, deploy a Data Protection Application by entering the following command:
$ cat << EOF | oc create -f - apiVersion: oadp.openshift.io/v1alpha1 kind: DataProtectionApplication metadata: name: ${CLUSTER_NAME}-dpa namespace: openshift-adp spec: backupImages: true 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: enable: false uploaderType: kopia EOFwhere:
backupImages- Specifies whether to use image backup. Set to
falseif you do not want to use image backup. nodeAgent- Specifies the node agent configuration. See the important note regarding the
nodeAgentattribute at the end of this procedure. uploaderType- Specifies the type of uploader. The built-in Data Mover uses Kopia as the default uploader mechanism regardless of the value of the
uploaderTypefield.
-
If you are using CSI or non-CSI volumes, deploy a Data Protection Application by entering the following command:
$ cat << EOF | oc create -f - apiVersion: oadp.openshift.io/v1alpha1 kind: DataProtectionApplication metadata: name: ${CLUSTER_NAME}-dpa namespace: openshift-adp spec: backupImages: true 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 nodeAgent: enable: false uploaderType: restic snapshotLocations: - velero: config: credentialsFile: /tmp/credentials/openshift-adp/cloud-credentials-credentials enableSharedConfig: "true" profile: default region: ${REGION} provider: aws EOFwhere:
backupImages- Specifies whether to use image backup. Set to
falseif you do not want to use image backup. nodeAgent- Specifies the node agent configuration. See the important note regarding the
nodeAgentattribute at the end of this procedure. credentialsFile- Specifies the mounted location of the bucket credential on the pod.
enableSharedConfig- Specifies whether the
snapshotLocationscan share or reuse the credential defined for the bucket. profile- Specifies the profile name set in the AWS credentials file.
region- Specifies your AWS region. This must be the same as the cluster region. You are now ready to back up and restore OpenShift Container Platform applications, as described in Backing up applications.
-
Warning
If you use OADP 1.2, replace this configuration:
with the following configuration:
If you want to use two different clusters for backing up and restoring, the two clusters must have the same AWS S3 storage names in both the cloud storage CR and the OADP DataProtectionApplication configuration.
Additional resources
- Installing the OADP Operator
- Using Operator Lifecycle Manager in disconnected environments
- Installing from the software catalog using the web console
- Backing up applications
Performing a backup with OADP and AWS STS¶
Perform a backup by using OpenShift API for Data Protection (OADP) with Amazon Web Services (AWS) (AWS STS). The following hello-world example application has no persistent volumes (PVs) attached.
Either Data Protection Application (DPA) configuration will work.
Procedure
-
Create a workload to back up by running the following commands:
-
Expose the route by running the following command:
-
Check that the application is working by running the following command:
-
Back up the workload by running the following command:
-
Wait until the backup has completed and then run the following command:
-
Delete the demo workload by running the following command:
-
Restore the workload from the backup by running the following command:
-
Wait for the Restore to finish by running the following command:
-
Check that the workload is restored by running the following command:
-
Check the JSONPath by running the following command:
Note
For troubleshooting tips, see troubleshooting documentation.
Cleaning up a cluster after a backup with OADP and AWS STS¶
Uninstall the OpenShift API for Data Protection (OADP) Operator together with the backups and the S3 bucket from the hello-world example.
Procedure
-
Delete the workload by running the following command:
-
Delete the Data Protection Application (DPA) by running the following command:
-
Delete the cloud storage by running the following command:
-
If the Operator is no longer required, remove it by running the following command:
-
Remove the namespace from the Operator by running the following command:
-
If the backup and restore resources are no longer required, remove them from the cluster by running the following command:
-
To delete backup, restore and remote objects in AWS S3, run the following command:
-
If you no longer need the Custom Resource Definitions (CRD), remove them from the cluster by running the following command:
-
Delete the AWS S3 bucket by running the following commands:
-
Detach the policy from the role by running the following command:
-
Delete the role by running the following command: