PersistentVolumes
A PersistentVolume is a piece of durable storage in the cluster, independent of any Pod.
For data that must outlive Pods — a database's files, uploaded images — Kubernetes separates storage into two objects that snap together.
PV and PVC
- A PersistentVolume (PV) is an actual piece of storage (a cloud disk, an NFS share). It is a cluster-wide resource, like a node.
- A PersistentVolumeClaim (PVC) is a Pod's request for storage: "I need 5Gi that I can read and write."
Kubernetes binds a PVC to a suitable PV. The Pod mounts the PVC and never has to know the underlying disk details.
Example
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-data
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /mnt/dataWhen to use it
- A database team creates PersistentVolumes backed by cloud SSD disks so that data persists even when the database pod is rescheduled to a different node.
- A platform engineer pre-provisions PVs from a NAS device and makes them available for claim by any namespace in the cluster.
- An operator checks a PV's reclaim policy to ensure it is set to Retain before deleting the associated PVC to prevent accidental data loss.
More examples
PersistentVolume manifest
Defines a 10 Gi PV with ReadWriteOnce access, Retain reclaim policy, and a hostPath backend for local testing.
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-ssd-10gi
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: ssd
hostPath:
path: /mnt/dataList and describe PVs
Lists all PVs showing capacity, access modes, and status, then describes a specific PV to check if it is bound or available.
kubectl get pv
# NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS
# pv-ssd-10gi 10Gi RWO Retain Available
kubectl describe pv pv-ssd-10gi | grep -E 'Capacity|Status|Claim'Check PV binding after claim
Shows the two-way binding relationship: after a PVC is created, both the PV and PVC show Bound status and reference each other.
kubectl apply -f pvc.yaml
kubectl get pv pv-ssd-10gi
# STATUS: Bound
# CLAIM: default/my-pvc
kubectl get pvc my-pvc
# STATUS: Bound VOLUME: pv-ssd-10gi
Discussion