Skip to main content

Concept and Usage

Persistent Volume (PV) is a storage resource in the cluster provisioned by an administrator or dynamically via Storage Classes. A PV has its own lifecycle, meaning it is not tied to any pod. To use a PV in your pod, you create a Persistent Volume Claim (PVC) that requests a PV with specific storage requirements.
PV and PVC are bound together — one PV can only be bound to one PVC (one-to-one relationship). No other PVC can use the same PV’s remaining capacity.
1

Create a PV

pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-example
  labels:
    type: fast-storage  # Optional label for PV
spec:
  capacity:
    storage: 1Gi           # Reserve 1Gi storage
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  hostPath:
    path: /data
Access Modes:
Access ModeDescription
ReadWriteOnceMounted as read-write by a single node. Multiple pods on the same node can access it.
ReadOnlyManyMounted as read-only by many nodes.
ReadWriteManyMounted as read-write by many nodes.
ReadWriteOncePodMounted as read-write by a single Pod only, across the whole cluster.
Reclaim Policies:
PolicyDescription
RetainVolume remains until manually deleted.
DeleteVolume is deleted when the PVC is deleted.
When deleting a PV, delete the associated PVC first, otherwise the PV will not be deleted.
2

Create a PVC

When you create a PVC, Kubernetes will bind the PVC to a PV that meets the requirements. If no matching PV exists, the PVC status will remain unbound.
pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-example
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  selector:           # Optional: bind to a specific PV by label
    matchLabels:
      type: fast-storage
3

Use the PVC in a Pod

pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: pod-example
spec:
  containers:
    - name: nginx
      image: nginx
      volumeMounts:
        - name: my-pvc-example  # Must match the volume name below
          mountPath: /usr/share/nginx/html
  volumes:
    - name: my-pvc-example
      persistentVolumeClaim:
        claimName: pvc-example

Build docs developers (and LLMs) love