Enabling cross account EFS mounting
This content is authored by Red Hat experts, but has not yet been tested on every supported configuration.
The Amazon Web Services Elastic File System (AWS EFS) is a Network File System (NFS) that can be provisioned on Red Hat OpenShift Service on AWS clusters. With the release of OpenShift 4.10 the EFS CSI Driver is now GA and available.
This is a guide to enable cross-account EFS mounting on ROSA.
Important: Cross Account EFS is considered an advanced topic, and this article makes various assumptions as to knowledge of AWS terms and techniques across VPCs, Networking, IAM permissions and more.
Prerequisites
- One AWS Account containing a Red Hat OpenShift on AWS (ROSA) 4.16 or later cluster, in a VPC
- One AWS Account containing (or which will contain) the EFS filesystem, containing a VPC
- The OC CLI
- The AWS CLI
jqcommandwatchcommand
Set up environment
export some environment variables
As we will be swapping back and forth between two AWS accounts, set up your AWS CLI profiles to avoid confusion now:
Prepare AWS Account A IAM Roles and Policies
IMPORTANT: Run these commands in AWS ACCOUNT A
Swap to your Account A profile
Create an IAM Policy for the EFS CSI Driver (Note, this has additional permissions compared to a single account EFS CSI policy)
Create the Policy
Create a Trust Policy
Create Role for the EFS CSI Driver Operator
Attach the Policies to the Role
At this stage, the Role that the EFS CSI Controller uses can now assume a role inside Account B, now we need to go to Account B and set up the correct permissions.
Prepare AWS Account B IAM Roles and Policies
IMPORTANT: Run these commands in AWS ACCOUNT B
In this account, we need to allow certain permissions to allow the EFS operator in AWS Account A to reach AWS Account B.
Swap to your Account B profile
Create an IAM Policy
Create the Policy
Create a Trust Policy
Create Role for the EFS CSI Driver Operator to assume
Attach the Policies to the Role
Set up VPC Peering
Set up Account A
Swap to your Account A profile
Start a peering request to Account B from Account A
Accept the peering request from Account B
Get the route table IDs for Account A and add route to Account B VPC
Get the route table IDS for Account B and add route to Account A VPC
Enable DNS resolution for Account A to read from Account B’s VPC
Deploy and test the AWS EFS Operator
Create a Secret to tell the AWS EFS Operator which IAM role to request.
Install the EFS Operator
Wait until the Operator is running
Install the AWS EFS CSI Driver
Wait until the CSI driver is running
Create a new secret that will tell the CSI Driver the role name in Account B to assume
Allow the EFS CSI Controller to read this secret
Prepare the security groups on Account A to allow NFS traffic to EFS
IMPORTANT: Run these commands on Account A
Swap to your Account A profile
Run this set of commands to update the VPC to allow EFS access
Update the Security Groups in Account A to allow NFS traffic to your nodes from EFS
At this point you can create either a single Zone EFS filesystem, or a Region wide EFS filesystem. To simplify this document, we’re going to give only an example of a Region wide EFS filesystem.
Creating a region-wide EFS filesystem in Account B
Swap to your Account B profile
Create a region-wide EFS File System
Configure a region-wide Mount Target for EFS (this will create a mount point in each subnet of your VPC by default)
Create a Storage Class for the EFS volume and verify a pod can access it.
Create a Storage Class for the EFS volume
Create a namespace
Create a PVC
Create a Pod to write to the EFS Volume
It may take a few minutes for the pod to be ready. If you see errors such as
Output: Failed to resolve "fs-XXXX.efs.us-east-2.amazonaws.com"it likely means its still setting up the EFS volume, just wait longer.Wait for the Pod to be ready
Create a Pod to read from the EFS Volume
Verify the second POD can read the EFS Volume
You should see a stream of “hello efs”
Cleanup
Delete the Pods
Delete the Volume
Delete the Namespace
Delete the storage class
Delete the EFS Shared Volume via AWS
Note: if you receive the error
An error occurred (FileSystemInUse)wait a few minutes and try again.Note: if you created additional mount points for a regional EFS filesystem, remember to delete all of them before removing the file system
Detach the Policies to the Role
Delete the Role
Delete the Policy
Detach the policies from the cross-account role
Delete the Role
Delete the Policy
Remove peering connection from account B
Remove peering connection from account A