Containers are ephemeral by design — data written inside them disappears when the Pod is recreated. Kubernetes' PersistentVolume system solves this, giving applications durable storage that survives Pod restarts and rescheduling.
The Core Concepts
PersistentVolume (PV) — a piece of actual storage in the cluster (a disk, directory, or network storage), provisioned by an administrator or dynamically.
PersistentVolumeClaim (PVC) — a request for storage made by an application, specifying how much space and what access mode it needs.
StorageClass — defines how storage is dynamically provisioned, letting PVCs automatically get matching PVs without manual pre-creation.
Simple Example: Local Path Storage (Single-Node Clusters)
For single-node k3s clusters (see How to Install a Single-Node Kubernetes Cluster with k3s), the built-in local-path StorageClass is often sufficient and enabled by default.
Step 1 — Create a PersistentVolumeClaim
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-app-storage
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
kubectl apply -f pvc.yaml
Step 2 — Verify the Claim Was Bound
kubectl get pvc
Status should show Bound, meaning a matching PersistentVolume was successfully provisioned and attached.
Step 3 — Mount the PVC in a Pod/Deployment
spec:
containers:
- name: my-app
image: my-app:latest
volumeMounts:
- mountPath: /data
name: app-storage
volumes:
- name: app-storage
persistentVolumeClaim:
claimName: my-app-storage
Access Modes Explained
| Mode | Meaning |
|---|---|
| ReadWriteOnce (RWO) | Mounted read-write by a single node at a time (most common) |
| ReadOnlyMany (ROX) | Mounted read-only by multiple nodes |
| ReadWriteMany (RWX) | Mounted read-write by multiple nodes (needs a storage backend that supports this, like NFS) |
Using Persistent Storage for a Database
See How to Deploy a Database in Kubernetes with StatefulSets, which combines PVCs with StatefulSets specifically designed for stateful workloads like databases.
Checking What's Actually Using Storage
kubectl get pv
kubectl describe pvc my-app-storage
What Happens to Data When a Pod Is Deleted
Data in a PersistentVolume survives Pod deletion and rescheduling — only deleting the PVC itself (or, depending on the reclaim policy, the PV) actually removes the underlying data. Deleting a Deployment does NOT delete its associated PVCs by default.
Backing Up Kubernetes Persistent Volumes
Standard Kubernetes doesn't include built-in backup for PV data — back up the underlying storage directly (e.g. the host path for local-path storage) using your normal VPS backup approach; see How to Set Up Automated VPS Backups.
Common Errors
PVC stuck in "Pending" — no StorageClass is available to satisfy the request, or the requested access mode isn't supported by any available storage; check kubectl get storageclass and kubectl describe pvc for details.
Data lost after Pod restart despite using a PVC — verify the volumeMounts path in the container spec actually matches where your application writes data.
Continue Reading
- How to Deploy a Database in Kubernetes with StatefulSets
- How to Install a Single-Node Kubernetes Cluster with k3s
- How to Set Up Automated VPS Backups
Browse more articles in Kubernetes & Container Orchestration.