You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Containers and pods are ephemeral. When a pod is deleted, any data written to its container filesystem is lost. For stateful applications — databases, file stores, message queues — you need persistent storage that survives pod restarts and rescheduling.
A Volume is a directory accessible to containers in a pod. Unlike a container's filesystem, a volume's lifetime is tied to the pod, not the container. Common volume types:
Kubernetes separates the provisioning of storage from its consumption:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: standard
spec:
containers:
- name: db
image: postgres:15
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: data
volumes:
- name: data
persistentVolumeClaim:
claimName: data-pvc
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: fast-ssd
provisioner: ebs.csi.aws.com
parameters:
type: gp3
reclaimPolicy: Retain
A StorageClass defines a type of storage. When a PVC references a StorageClass, a dynamic provisioner creates the PV automatically — no manual pre-provisioning required. Cloud-managed Kubernetes clusters ship with default StorageClasses for their native block storage.
# List PersistentVolumes
kubectl get pv
# List PersistentVolumeClaims
kubectl get pvc
# Describe a PVC to see binding status
kubectl describe pvc data-pvc
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.