Kubernetes Storage
Dynamic volume provisioning allows storage volumes to be created on-demand. Without dynamic provisioning, cluster administrators have to manually make calls to their cloud or storage provider to create new storage volumes, and then create PersistentVolume objects to represent them in Kubernetes. The dynamic provisioning feature eliminates the need for cluster administrators to pre-provision storage. Instead, it automatically provisions storage when users create PersistentVolumeClaim objects.
To enable this:
- need to have a
StorageClass
- create
PersistentVolumes
andPersistentVolumeClaims
- reference these in your Pods and Deployments
- for
StatefulSets
you can usespec.volumeClaimTemplates
EKS-specific stuff:
- ebs-csi-driver will provision ebs volumes to back
PersistentVolumes
-- limitation: there can only be one ebs volume attached to an ec2 instance at a time, so two pods running on different nodes cannot share the volume! - the efs-csi-driver creates an efs (network file system) volume that can be shared by pods running on different nodes because its over a network, not local disk
The Mountpoint for Amazon S3 Container Storage Interface (CSI) Driver enables Kubernetes applications to access Amazon S3 objects through a standard file system interface. Built on Mountpoint for Amazon S3, the Mountpoint CSI driver exposes an Amazon S3 bucket as a storage volume that containers in your Kubernetes cluster can seamlessly access.
There's a pattern...
- Notice a need for persistency of data/files
- Switch from an ephemeral volume (e.g.,
emptyDir
) to a PersistentVolume + PersistentVolumeClaim - Install the necessary drivers (ebs, efs, s3 mountpoint, etc)
- Configure your Deployments, StatefulSets, etc. by mounting the PVC
- profit. you now have persistent volumes that are dynamically provisioned.