K8s by Example: Persistent Volumes
| PersistentVolumes (PVs) are cluster-wide storage resources provisioned by admins or dynamically. They abstract underlying storage (cloud disks, NFS, local). Pods claim storage via PersistentVolumeClaims without knowing details. |
| pv.yaml | |
| PV defines a piece of storage in the cluster. | |
| pv-access-modes.yaml | |
| Access modes define how volumes can be mounted. RWO (ReadWriteOnce): single node read-write. ROX (ReadOnlyMany): multiple nodes read-only. RWX (ReadWriteMany): multiple nodes read-write. RWOP (ReadWriteOncePod, 1.22+): single Pod only. AWS EBS/Azure Disk: RWO only. NFS: RWO, ROX, RWX. | |
| pv-reclaim.yaml | |
| Reclaim policies control what happens when a PVC is deleted. | |
| pv-cloud.yaml | |
| Cloud provider volumes use specific volume sources. First example: AWS EBS. Second example: GCE Persistent Disk. Third example: NFS. For production, use dynamic provisioning via StorageClass instead of manually creating PVs. | |
| pv-local.yaml | |
| Node affinity constrains which nodes can access the PV. Required for local volumes and some storage types. The PV can only be used by Pods scheduled to matching nodes. | |
| pv-block.yaml | |
| Volume modes: | |
| terminal | |
| Debug PV issues by checking status and events. Common problems: wrong access mode, capacity mismatch, storage class mismatch, node affinity preventing binding. | |