Amazon EFS CSI driver
The Amazon EFS Container
Storage Interface (CSI) driver
This topic shows you how to deploy the Amazon EFS CSI Driver to your Amazon EKS cluster and verify that it works.
Alpha features of the Amazon EFS CSI Driver are not supported on Amazon EKS clusters.
For detailed descriptions of the available parameters and complete examples that
demonstrate the driver's features, see the Amazon EFS Container Storage
Interface (CSI) driver
Considerations
-
You can't use dynamic persistent volume provisioning with Fargate nodes, but you can use static provisioning.
-
Dynamic provisioning requires 1.2 or later of the driver, which requires a 1.17 or later cluster. You can statically provision persistent volumes using 1.1 of the driver on any supported Amazon EKS cluster version.
-
You can use version 1.3.2 or later of the driver with Amazon EC2 Arm nodes.
Prerequisites
-
Existing cluster with an OIDC provider – If you don't have a cluster, you can create one using one of the Getting started with Amazon EKS guides. To determine whether you have an OIDC provider for an existing cluster, or to create one, see Create an IAM OIDC provider for your cluster.
-
AWS CLI – A command line tool for working with AWS services, including Amazon EKS. This guide requires that you use version 2.2.37 or later or 1.20.40 or later. For more information, see Installing, updating, and uninstalling the AWS CLI in the AWS Command Line Interface User Guide. After installing the AWS CLI, we recommend that you also configure it. For more information, see Quick configuration with
aws configurein the AWS Command Line Interface User Guide. -
kubectl– A command line tool for working with Kubernetes clusters. This guide requires that you use version 1.21 or later. For more information, see Installing kubectl.
Create an IAM policy and role
Create an IAM policy and assign it to an IAM role. The policy will allow the Amazon EFS driver to interact with your file system.
To deploy the Amazon EFS CSI driver to an Amazon EKS cluster
-
Create an IAM policy that allows the CSI driver's service account to make calls to AWS APIs on your behalf.
-
Download the IAM policy document from GitHub. You can also view the policy document
. curl -o iam-policy-example.json https://raw.githubusercontent.com/kubernetes-sigs/aws-efs-csi-driver/v1.3.2/docs/iam-policy-example.json -
Create the policy. You can change
to a different name, but if you do, make sure to change it in later steps too.AmazonEKS_EFS_CSI_Driver_Policyaws iam create-policy \ --policy-nameAmazonEKS_EFS_CSI_Driver_Policy\ --policy-document file://iam-policy-example.json
-
-
Create an IAM role and attach the IAM policy to it. Annotate the Kubernetes service account with the IAM role ARN and the IAM role with the Kubernetes service account name. You can create the role using
eksctlor the AWS CLI.
Install the Amazon EFS driver
Install the Amazon EFS CSI driver using Helm or a manifest.
-
The following steps install the 1.3.2 version of the driver, which requires a 1.17 or later cluster. If you're installing the driver on a cluster that is earlier than version 1.17, you need to install version 1.1 of the driver. For more information, see Amazon EFS CSI driver
on GitHub. -
Encryption of data in transit using TLS is enabled by default. Using encryption in transit
, data is encrypted during its transition over the network to the Amazon EFS service. To disable it and mount volumes using NFSv4, set the volumeAttributesfieldencryptInTransitto"false"in your persistent volume manifest. For an example manifest, see Encryption in Transit exampleon GitHub.
Create an Amazon EFS file system
The Amazon EFS CSI driver supports Amazon EFS access points, which are
application-specific entry points into an Amazon EFS file system that make it easier
to share
a file system between multiple pods. Access points can enforce a user identity for
all
file system requests that are made through the access point, and enforce a root
directory for each pod. For more information, see Amazon EFS access points
You must complete the following steps in the same terminal because variables are set and used across the steps.
To create an Amazon EFS file system for your Amazon EKS cluster
-
Retrieve the VPC ID that your cluster is in and store it in a variable for use in a later step. Replace
(including<cluster-name>) with your cluster name.<>vpc_id=$(aws eks describe-cluster \ --name<cluster-name>\ --query "cluster.resourcesVpcConfig.vpcId" \ --output text) -
Retrieve the CIDR range for your cluster's VPC and store it in a variable for use in a later step.
cidr_range=$(aws ec2 describe-vpcs \ --vpc-ids $vpc_id \ --query "Vpcs[].CidrBlock" \ --output text) -
Create a security group with an inbound rule that allows inbound NFS traffic for your Amazon EFS mount points.
-
Create a security group. Replace the
with your own.example valuessecurity_group_id=$(aws ec2 create-security-group \ --group-nameMyEfsSecurityGroup\ --description "My EFS security group" \ --vpc-id $vpc_id \ --output text) -
Create an inbound rule that allows inbound NFS traffic from the CIDR for your cluster's VPC.
aws ec2 authorize-security-group-ingress \ --group-id $security_group_id \ --protocol tcp \ --port 2049 \ --cidr $cidr_rangeImportant To further restrict access to your file system, you can use the CIDR for your subnet instead of the VPC.
-
-
Create an Amazon EFS file system for your Amazon EKS cluster.
-
Create a file system.
file_system_id=$(aws efs create-file-system \ --region us-west-2 \ --performance-mode generalPurpose \ --query 'FileSystemId' \ --output text) -
Create mount targets.
-
Determine the IP address of your cluster nodes.
kubectl get nodesOutput
NAME STATUS ROLES AGE VERSION ip-192-168-56-0.us-west-2.compute.internal Ready <none> 19m v1.19.6-eks-49a6c0 -
Determine the IDs of the subnets in your VPC and which Availability Zone the subnet is in.
aws ec2 describe-subnets \ --filters "Name=vpc-id,Values=$vpc_id" \ --query 'Subnets[*].{SubnetId: SubnetId,AvailabilityZone: AvailabilityZone,CidrBlock: CidrBlock}' \ --output tableOutput
| DescribeSubnets | +------------------+--------------------+----------------------------+ | AvailabilityZone | CidrBlock | SubnetId | +------------------+--------------------+----------------------------+ | us-west-2c | 192.168.128.0/19 | subnet-EXAMPLE6e421a0e97 | | us-west-2b | 192.168.96.0/19 | subnet-EXAMPLEd0503db0ec | | us-west-2c | 192.168.32.0/19 | subnet-EXAMPLEe2ba886490 | | us-west-2b | 192.168.0.0/19 | subnet-EXAMPLE123c7c5182 | | us-west-2a | 192.168.160.0/19 | subnet-EXAMPLE0416ce588p | | us-west-2a | 192.168.64.0/19 | subnet-EXAMPLE12c68ea7fb | +------------------+--------------------+----------------------------+ -
Add mount targets for the subnets that your nodes are in. From the output in the previous two steps, the cluster has one node with an IP address of
192.168.56.0. That IP address is within theCidrBlockof the subnet with the IDsubnet-EXAMPLEe2ba886490. As a result, the following command creates a mount target for the subnet the node is in. If there were more nodes in the cluster, you'd run the command once for a subnet in each AZ that you had a node in, replacingwith the appropriate subnet ID.subnet-EXAMPLEe2ba886490aws efs create-mount-target \ --file-system-id $file_system_id \ --subnet-id subnet-EXAMPLEe2ba886490\ --security-groups $security_group_id
-
-
(Optional) Deploy a sample application
You can deploy a sample app that dynamically creates a persistent volume, or you can manually create a persistent volume.

