If your Kubernetes cluster is running in the cloud on Amazon Web Services (AWS), it comes with Elastic Block Storage (EBS). Alternatively, Elastic File System (EFS) can be used for storage. We know pods are ephemeral and in most cases, we need to persist the data in the pods. To facilitate this, we can mount folders into our pods that are backed by EBS volumes on AWS using AWSElasticBlockStore, a volume plugin provided by Kubernetes.
We can also use EFS as storage by using efs-provisioner. Efs-provisioner runs as a pod in the Kubernetes cluster that has access to an AWS EFS resource. In this blog, we will see how to use EBS or EFS as a persistent volume for our Kubernetes cluster in AWS. Before that, we will discuss some common terms and the difference between EBS and EFS.
Kubernetes is an open source for automating the scaling, deployment, and management of containerized software. There are multiple ways to create a Kubernetes cluster in AWS. The two most common ways are
- The traditional way of installing a master and worker nodes in the EC2 instances.
- Using the AWS-provided Amazon Elastic Container Service for Kubernetes (EKS), which is a managed service that makes it easy for you to run Kubernetes on AWS without needing to maintain your own Kubernetes control plane?
Why Storage Volumes in K8s??
Data in a container are transient, which shows issues for non-trivial software such as databases when running in containers. First, when a container crashes, Kubernetes will restart the container in a clean state where all the data is lost. Second, when running containers collected in a pod, it is frequently required to share files between those containers. The Kubernetes Volume abstraction solves these problems.
A storage class offers a way for administrators to elaborate on the “classes” of storage they provide.
Different classes might map to quality-of-service levels or to backup policies or arbitrary policies determined by the cluster administrators. Storage classes have a provisioned that regulates what load plugin is used for provisioning persistent volumes (PVs).
This field must be specified. In our case, for EBS, it will be “kubernetes.io/aws-ebs”— this storage provisioned will take care that a corresponding EBS volume with the correct parameters is created.
Data will persevere as long as the consistent PV resource exists. Deleting the resource will also delete the corresponding EBS volume, which means that all stored data will be lost at that point.
Read: DevOps key practices
For EFS, we will create an efs-provisioner pod, which manages the EFS resources. The efs-provisioner container reads a configure map, which contains the EFS file system ID, the AWS region and the name you want to use for your efs-provisioner. This name will be used later when you create a storage class.
EBS vs. EFS
|Amazon EFS provides shared file storage for use with compute instances in the AWS cloud and on-premise servers.||Amazon EBS is a cloud block storage service that provides direct access from a single EC2 instance to a dedicated storage volume.|
|Applications that require shared file access can use Amazon EFS for reliable file storage delivering high aggregate throughput to thousands of clients simultaneously.||The application that requires persistent dedicated block access for a single host can use EBS as a high available and low-latency block storage solution.|
|EFS PV provides ReadWriteMany access mode||EBS PV provide only ReadWriteOnce access mode|
|AN EFS file system can be accessed from multiple availability zones and it is the value for the multi-AZ cluster||EBS may be retrieved by the host it is linked within the zone. EBS volume is automatically simulated within its Availability Zone to defend you from component disappointment, providing high availability and durability.
|It is better to choose EFS when it is difficult to estimate the amount of storage the application will use because EFS is built to elastically scale.||Automatic scaling is not available in EBS but can be scaled up down based on the need.|
|Costly than EBS||Cost efficient|
|EFS is a file system hence it won’t support some application such as database which requires block storage.||Can support all type of application.|
|EFS doesn’t support any backup mechanism we need to set up backup manually||EBS, on the other hand, provides point-in-time snapshots of EBS volumes, which are backed up to Amazon S3 for long-term durability.|
|EFS doesn’t support snapshots.||Amazon EBS offers the capability to copy snapshots across AWS regions, enabling expansion, data center migration, and failure recovery offering flexibility for your business.