Let's think about it this way for a second
A container's filesystem is ephemeral (temporary) — every time a pod restarts or gets recreated, everything inside it is gone. For an app that needs to hold onto data, like a database, that's a serious problem. A Volume connects storage outside the container's filesystem — a PersistentVolume (PV) is a storage resource (disk space) that the cluster admin has provisioned, while a PersistentVolumeClaim (PVC) is the request an app makes saying 'I need this much storage.'
Let's connect this to a real scenario
If a database Pod (say, PostgreSQL) has a PVC attached, then even if the pod crashes and gets recreated, the data in the PVC (customer records, order history) will still be there — the new pod just reattaches to the same old PVC. On local minikube, you can use the `hostPath` volume type for testing (in production you'd use cloud disks, like AWS EBS).
Let's look at it together
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: db-storage
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: Pod
metadata:
name: db-pod
spec:
containers:
- name: postgres
image: postgres:16
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: db-vol
volumes:
- name: db-vol
persistentVolumeClaim:
claimName: db-storage$ kubectl get pvc db-storage
NAME STATUS VOLUME CAPACITY ACCESS MODES
db-storage Bound pvc-xxxx 1Gi RWO5-Minute Try-It
Create a PVC, mount it into a Pod, write a file, then delete the pod with `kubectl delete pod` and check whether the data is still there once the new pod comes back up.
A Quick Word of Caution
Deleting a PVC (depending on the reclaim policy) can mean the data inside is gone for good — always check you have a backup before deleting a production database volume.