204 β€” Persistent Volumes and Storage

Intermediate

Master persistent storage in Kubernetes using Persistent Volumes, Persistent Volume Claims, and Storage Classes for stateful applications.

Learning Objectives

1
Understand Persistent Volumes (PV) and Persistent Volume Claims (PVC)
2
Create and manage persistent storage
3
Use Storage Classes for dynamic provisioning
4
Mount volumes in pods for data persistence
Step 1

Create a Persistent Volume

Define storage resources available in the cluster.

Commands to Run

cat > persistent-volume.yaml << 'EOF'
apiVersion: v1
kind: PersistentVolume
metadata:
  name: my-pv
spec:
  capacity:
    storage: 1Gi
  accessModes:
  - ReadWriteOnce
  hostPath:
    path: /data/pv
EOF
kubectl apply -f persistent-volume.yaml
kubectl get pv

What This Does

Persistent Volumes are cluster resources representing physical storage. Administrators provision PVs, users claim them with PVCs.

Expected Outcome

PV created with 1Gi capacity, STATUS shows Available, ACCESS MODES shows RWO.

Pro Tips

  • 1
    PVs are cluster-wide resources (not namespaced)
  • 2
    AccessModes: ReadWriteOnce (RWO), ReadOnlyMany (ROX), ReadWriteMany (RWX)
  • 3
    hostPath is for testing only - use cloud storage in production
  • 4
    Status: Available β†’ Bound β†’ Released
  • 5
    Reclaim policy: Retain, Delete, or Recycle
Was this step helpful?

All Steps (0 / 10 completed)