Cheat sheets
Storage
Volume types, access modes, reclaim policies, binding rules, StorageClass fields and the manifests for PVs, PVCs and classes.
Pick the volume
| Need | Use | Lifetime |
|---|---|---|
| Scratch space shared in a Pod | emptyDir (medium: Memory for tmpfs) | The Pod |
| Config or credentials as files | configMap, secret, projected | Follows the object |
| A file or socket on the node | hostPath | The node |
| Data that outlives Pods | persistentVolumeClaim | Set by the reclaim policy |
| Per-replica disks | StatefulSet volumeClaimTemplates | Kept after scale-down |
Access modes
| Mode | Meaning |
|---|---|
ReadWriteOnce (RWO) | Read-write by one node. Several Pods on that node can share it |
ReadOnlyMany (ROX) | Read-only by many nodes |
ReadWriteMany (RWX) | Read-write by many nodes. Needs NFS, CephFS or similar |
ReadWriteOncePod (RWOP) | Read-write by exactly one Pod |
Binding rules
A claim binds to one PV that matches class, access modes, volume mode and capacity at least the request, and the
selector if present. Binding is 1:1 and a bound PV shows its full size. storageClassName: "" means no class and no
dynamic provisioning. Omitting the field uses the default class.
Reclaim policy
| Policy | After the claim is deleted |
|---|---|
Retain | PV becomes Released, data kept. Clear spec.claimRef to reuse it |
Delete | PV and backing volume removed. Default for dynamic PVs |
Recycle | Removed from use, do not choose it |
StorageClass fields
| Field | Values and effect |
|---|---|
provisioner | The CSI driver name, or kubernetes.io/no-provisioner for static PVs |
volumeBindingMode | Immediate, or WaitForFirstConsumer to provision where the Pod schedules |
reclaimPolicy | Delete (default) or Retain, copied to new PVs |
allowVolumeExpansion | Must be true to grow a claim, and it cannot shrink |
parameters, mountOptions | Driver specific |
| Default class | Annotation storageclass.kubernetes.io/is-default-class: "true" |
Manifests
apiVersion: v1
kind: PersistentVolume
metadata: { name: pv-data }
spec:
capacity: { storage: 10Gi }
accessModes: [ReadWriteOnce]
persistentVolumeReclaimPolicy: Retain
storageClassName: manual
hostPath: { path: /mnt/data }
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata: { name: data }
spec:
accessModes: [ReadWriteOnce]
storageClassName: manual
resources: { requests: { storage: 5Gi } }volumes: [{ name: data, persistentVolumeClaim: { claimName: data } }]Commands
k get pv,pvc,sc, k describe pvc data (Events show why it is Pending),
k patch pv x -p '{"spec":{"claimRef":null}}', k patch pvc data -p '{"spec":{"resources":{"requests":{"storage":"20Gi"}}}}',
k get csidrivers.