Creating a Storage Class in Amazon Web Services
Introduction
You can set up persistent storage in Amazon EKS using either of the following options:
This page includes the necessary steps for each of the two options listed above.
It's a best practice to make sure you install the latest version of the drivers. For more information, see in the GitHub repositories for the Amazon EBS CSI driver and Amazon EFS CSI driver.
If you receive errors when running AWS Command Line Interface (AWS CLI) commands, make sure you're using the most recent version of the AWS CLI.
Please be mindful that some CLIs are using the default AWS region set by yourself when installing and configuring them. This value is taken into consideration when using the CLIs and might create issues if the default region (set locally) and the cluster region are different.
Prerequisites
Before you complete the steps in either section, you must:
Make sure you're logged in to Amazon Management Console
Set AWS Identity and Access Management (IAM) permissions for creating and attaching a policy to the Amazon EKS worker node role CSI Driver Role.
Create your Amazon EKS cluster and join your worker nodes to the cluster.
For Amazon EBS CSI add-on, make sure you have an existing cluster that's version
1.18or later. To see the required platform version, run the following command.aws eks describe-addon-versions --addon-name aws-ebs-csi-driverHave an existing IAM OpenID Connect (OIDC) provider for your cluster. To determine if you already have a cluster, or to create one, see Create an IAM OIDC provider for your cluster.
To verify that your worker nodes are attached to your cluster, run the kubectl get nodes command.
Steps to create Disk and Network Volumes
The main focus of the next steps will be Deploying and testing the Amazon EBS CSI driver.
Adding the Amazon EBS CSI add-on
For this step, you need to follow the Amazon instructions presented in the article linked here.
The first thing you'll have to do is Create an IAM OIDC provider for your cluster.
Continue by Creating the Amazon EBS CSI driver IAM role for service accounts. We recommend following the steps from the AWS Management Console tab.
Next up, add the Amazon EBS CSI add-on. Instructions are available here, in the Adding the Amazon EBS CSI add-on section.
Setting the proper context
Starting here, you will work in the terminal. Make sure you're connected to the cluster and that the cluster is the current context. Use the command kubectl config --help to obtain the necessary information.
Creating the storage class spec.yaml file
Create a spec.yaml file with the following contents:
Applying the spec.yaml file
Apply the file using the command below. Line 2 contains the expected Output.
Verifying the presence of the bns-disk-sc storage class
Use the command below to verify the presence of the storage class:
Testing the EBS CSI driver
1. Create two files to test the CSI driver:
Create a
claim.yamlfile with the contents below. Later, theclaim.yamlfile will generate the test PVC.
Create a
pod.yamlfile with the contents below. Later, thepod.yamlfile will generate the test Pod.
2. Apply claim.yaml:
3. Apply pod.yaml:
4. Wait until the app pod reaches the status Running. To check that the pod reached the Running status, perform the following command:
5. Check for the presence of a persistent volume that has the following properties:
STORAGECLASS set to bns-disk-sc
CLAIM set to default/ebs-claim
6. Verify that the app pod is writing data to the volume:
7. If the your results are similar with the output displayed above, then you've completed the process successfully and you can delete the test resources.
Start by deleting the Pod:
Delete the PVC. This will also cause the PV to be deleted:
Check if the PV displayed at step 5 is no longer present:
The main focus of the next steps will be Installing the Amazon EFS CSI driver, Creating the Amazon EFS file system and testing them.
Setting the proper context
Starting here, you will work in the terminal. Make sure you're connected to the cluster and that the cluster is the current context. Use the command kubectl config --help to obtain the necessary information.
Creating an EFS instance
When creating the EFS instance, make sure you select the cluster VPC. Visit the AWS documentation platform for detailed instructions on how to create an EFS instance.
Go to the EFS instance Details page and access the Network tab. Wait until the platform displays the ID of the Security Group, then copy and save it for later use.
Adding the necessary Ingress Rule
Navigate to the AWS VPC (Virtual Private Cloud) listing.
Retrieve the IPv4 CIDR corresponding to the VPC where you created the EFS. You will need it at the next step.
Create an ingress rule using the details listed below.
NFS
TCP
2049
VPC IPv4 CIDR
Replace the VPC IPv4 CIDR with the IPv4 CIDR you retrieved at the previous step.
Creating the storage class using a Helm chart
Now it's time to create a storage class. Start with the command below:
Proceed with the following command.
Replace PRIVATE_IP_EFS_INSTANCE with the actual IP of your EFS instance.
You can retrieve the EFS DNS NAME from the Details page of your EFS instance.
Verifying the presence of the bns-network-sc storage class
Use the command below to verify the presence of the storage class:
Testing the EFS CSI driver
1. Create the test.yaml file with the contents below. Later, the test.yaml file will generate the test PVC and Pod.
2. Apply test.yaml:
3. Wait until the app pod reaches the status Running. To check that the pod reached the Running status, perform the following command:
4. Verify that the efs-app pod is writing data to the volume:
5. If your results are similar with the Output displayed above, then you've completed the process successfully and you can delete the test resources.
Delete the PVC and the Pod. This will also cause the PV to be deleted:
Last updated
Was this helpful?
