Search⌘ K

Creating Kubernetes Persistent Volumes

Explore how to create Kubernetes PersistentVolumes that abstract AWS EBS storage, manage capacity and access modes, and enable persistent state in your cluster. This lesson teaches you to define, configure, and verify PersistentVolumes, preparing you to manage storage for stateful applications in Kubernetes.

Understanding PersistentVolumes

The fact that we have a few EBS volumes available does not mean that Kubernetes knows about their existence. We need to add PersistentVolumes that will act as a bridge between our Kubernetes cluster and AWS EBS volumes.

PersistentVolumes allow us to abstract details of how storage is provided (e.g., EBS) from how it is consumed. Just like volumes, PersistentVolumes are resources in a Kubernetes cluster. The main difference is that their lifecycle is independent of individual Pods that are using them.

Looking into the definition

Let’s look at a definition that will create a few PersistentVolumes:

Shell
cat pv/pv.yml

The output (limited to the first of the three volumes) is as follows:

YAML
kind: PersistentVolume
apiVersion: v1
metadata:
name: manual-ebs-01
labels:
type: ebs
spec:
storageClassName: manual-ebs
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
awsElasticBlockStore:
volumeID: REPLACE_ME_1
fsType: ext4
...

Exploring the spec section (Lines 7–15)

The spec section features a few interesting details:

Line 8: We set manual-ebs as the storage class ...