Dynamic Database Storage with the Amazon EBS CSI Driver for Amazon EKS
How to implement dynamic provisioning of Amazon EBS volumes for your self-managed databases in Kubernetes with the EBS CSI Driver Add-On.
About | |
---|---|
✅ AWS experience | 200 - Intermediate |
⏱ Time to complete | 30 minutes |
🧩 Prerequisites | - AWS Account |
📢 Feedback | Any feedback, issues, or just a 👍 / 👎 ? |
⏰ Last Updated | 2023-08-30 |
- Install the latest version of kubectl. To check your version, run:
kubectl version --short
. - Install the latest version of eksctl. To check your version, run:
eksctl info
.
- Authentication: Utilize the pre-configured IAM Role for Service Account (IRSA) specifically designed for the EBS CSI Driver. This role, used within a designated AWS Availability Zone, works with the OpenID Connect (OIDC) endpoint to ensure secure communication between Kubernetes pods and AWS services.
- EBS CSI Driver Add-On Set-Up: Amazon EKS add-ons, such as the EBS CSI Driver Add-On, are curated software add-ons that include the latest security patches and bug fixes. The AWS Management Console notifies you of new versions for an Amazon EKS add-on. If you choose to install the EBS CSI driver manually, you are responsible for keeping it up to date. Note that EBS volumes are bound to a specific AWS Availability Zone and can only be accessed by nodes within the same zone, making it suitable for workloads running nodes within the same availability zone.
- Sample Application Deployment: Build and provision storage for self-managed databases using a sample MySQL database. Utilize custom annotations and parameters for the EBS CSI Driver, specifically the 'ReadWriteOnce' access mode, to instruct the EBS CSI Driver to handle storage provisioning for databases. For more examples, see Examples in the EBS CSI Driver GitHub repository.
Note that if you're still within your initial 12-month AWS Free Tier period, it's important to note that usage of EBS volumes beyond the free tier will result in additional AWS charges.
- First, confirm that you are operating within the correct cluster context. This ensures that any subsequent commands are sent to the intended Kubernetes cluster. You can verify the current context by executing the following command:
- Define the
CLUSTER_NAME
environment variable for your EKS cluster. Replace the sample value for clusterregion
.
- Define the
CLUSTER_REGION
environment variable for your EKS cluster. Replace the sample value for clusterregion
.
- Define the
CLUSTER_VPC
environment variable for your EKS cluster.
- Define the
ACCOUNT_ID
environment variable for the account associated with your EKS cluster.
ebs-csi-controller-sa
service account is crucial for managing EBS volumes in Kubernetes. Make sure it's correctly set up in the kube-system
namespace on your cluster.ebs-csi-controller-sa
. Note that you must have an OpenID Connect (OIDC) endpoint associated with your cluster before you run this command.- Create an
.env
file and paste the following contents.
- In the same directory as the
.env
file you just created, run the following command to create a Kubernetes secret with sensitive credentials.
ebs-sc
that sets up storage provisioning on AWS EBS, with a binding mode that waits for the first consumer; and a Pod named mysql-ebs
that runs a Linux OS container. It also specifies the EBS CSI Driver as the provisioner (i.e., ebs.csi.aws.com
). Together, these components provide a complete example of defining, claiming, and utilizing persistent storage within a Kubernetes cluster.- Create a Kubernetes manifest called mysql-ebs.yaml and paste the following contents into it.
- Deploy the Kubernetes resources in
mysql-ebs.yaml
:
StorageClass
to provision an EBS volume based on the specified configuration. The volumeClaimTemplates
in the StatefulSet
define the desired properties of the volume, such as accessModes
, storageClassName
, and resource requests. The EBS CSI driver then binds the volume to the StatefulSet
's Pod, allowing the MySQL container to utilize the persistent storage./var/lib/mysql
path. This verifies that the Pod has successfully created and attached the volume to the Linux OS. The expected output should look like this:Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.