Using AWS EBS Volumes in Kubernetes To Store Persistent Data for Kubernetes Versions < 1.23

Arnav Tripathy
2 min readApr 2, 2022
AWS EBS!

In kubernetes it is possible to dynamically provision persistent volume claims in AWS which means we can directly create persistent volume claims for a certain application without having to worry about a persistent volume configuration using something storage classes. You can read more about storage classes here. Since this blog is more of a speedrun of setting up the dynamic provisioning , we shall directly dive into the yaml file configs.

Storage Class yaml config example is as below. Values can be changed according to needs:

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: aws-ebs-k8
labels:
deploy: aws-ebs-k8
provisioner: kubernetes.io/aws-ebs
volumeBindingMode: Immediate
parameters:
type: gp2 # This configures SSDs (recommended).
allowVolumeExpansion: true
reclaimPolicy: Retain
allowedTopologies:
- matchLabelExpressions:
— key: failure-domain.beta.kubernetes.io/zone
values:
— us-west-2a

Now we can create a persistent volume claim directly by using the storage class name which we configured above:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
labels:
deploy: pvc-k8
name: pvc-k8
spec:
accessModes:
— ReadWriteOnce
resources:
requests:
storage: 20Gi
storageClassName: aws-ebs-k8

Applying this configuration would create a persistent volume claim as well as an EBS volume , and further the claim can be used to attach to a kubernetes application.

Please note that the above steps won’t work for kubernetes clusters above 1.23 . In order to use dynamic AWS provisioning for such clusters, you can refer this guide here.

--

--

Arnav Tripathy

Feline powered security engineer . Follow me for a wide variety of topics in the field of cyber security and dev(sec)ops. Travelling and Tennis❤️🎾🐈‍⬛.