Archive · Kubernetes

Persistent Volumes and Claims

Give pods storage that survives restarts, using PVCs and storage classes.

1 min read

  • Kubernetes 1.22
  • CSI
  • StorageClass

Container storage disappears with the pod. A PersistentVolumeClaim (PVC) requests storage; a StorageClass provisions it dynamically.

apiVersion: v1
kind: PersistentVolumeClaim
metadata: { name: data }
spec:
  accessModes: [ReadWriteOnce]
  resources:
    requests: { storage: 10Gi }
  storageClassName: gp2
volumes:
  - name: data
    persistentVolumeClaim: { claimName: data }
kubectl get pvc,pv
kubectl get storageclass

ReadWriteOnce means one node at a time; sharing across nodes needs ReadWriteMany (NFS, EFS). Check the reclaim policy: Delete removes the disk when the claim is deleted, Retain keeps it. Cloud volumes live in one Availability Zone, so a pod must run in the same zone as its disk. Back up important volumes with snapshots (the CSI snapshot API reached GA in 1.20).