Persistent Volumes
A PersistentVolume (PV) is a cluster-level storage resource provisioned by an administrator or dynamically via a StorageClass. PVs have a lifecycle independent of any pod, meaning data persists even when pods are deleted.
Creating a Persistent Volume
apiVersion: v1
kind: PersistentVolume
metadata:
name: data-pv
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: standard
hostPath:
path: /mnt/data
kubectl apply -f pv.yaml
kubectl get pv data-pv
Access Modes
PVs support three access modes depending on the storage backend:
- ReadWriteOnce (RWO) -- mounted as read-write by a single node
- ReadOnlyMany (ROX) -- mounted as read-only by multiple nodes
- ReadWriteMany (RWX) -- mounted as read-write by multiple nodes
kubectl get pv -o custom-columns=NAME:.metadata.name,ACCESS:.spec.accessModes,CAPACITY:.spec.capacity.storage
Reclaim Policies
When a PVC releases a PV, the reclaim policy determines what happens:
- Retain -- keeps the PV and its data; requires manual cleanup
- Delete -- removes the PV and its underlying storage
- Recycle -- performs a basic scrub (deprecated in favor of dynamic provisioning)
Checking PV Status
kubectl get pv
kubectl describe pv data-pv
PV status progresses through: Available (not yet bound), Bound (claimed by a PVC), Released (PVC deleted but not yet reclaimed), and Failed (automatic reclamation failed). Understanding these states helps troubleshoot storage issues.