What Is Persistent Volume in Kubernetes: Explained Simply
Persistent Volume (PV) in Kubernetes is a piece of storage in the cluster that exists independently of pods. It allows data to persist beyond the life of individual pods by providing a stable storage resource that pods can use and share.How It Works
Think of a Persistent Volume as a dedicated storage locker in a shared workspace. Even if you leave the workspace (pod stops), your locker (data) stays intact and ready for you or others to use later.
In Kubernetes, pods are temporary and can be created or destroyed anytime. Without persistent storage, any data inside a pod disappears when the pod stops. A Persistent Volume solves this by providing storage that lives independently from pods.
Administrators create Persistent Volumes that represent real storage resources like disks or network storage. Developers then request storage by creating Persistent Volume Claims, which bind to these volumes, letting pods use the storage safely and reliably.
Example
This example shows a simple Persistent Volume and a Persistent Volume Claim that a pod can use to store data persistently.
apiVersion: v1
kind: PersistentVolume
metadata:
name: example-pv
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /mnt/data
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: example-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: Pod
metadata:
name: example-pod
spec:
containers:
- name: app
image: busybox
command: ["sleep", "3600"]
volumeMounts:
- mountPath: "/data"
name: storage
volumes:
- name: storage
persistentVolumeClaim:
claimName: example-pvc
When to Use
Use Persistent Volumes when your application needs to keep data safe even if pods restart or move to other nodes. This is common for databases, logs, or any stateful application.
For example, if you run a database in Kubernetes, you want its data to survive pod crashes or upgrades. Persistent Volumes provide this by storing data outside the pod lifecycle.
They are also useful when multiple pods need to share the same data or when you want to separate storage management from application deployment.
Key Points
- Persistent Volumes provide stable storage independent of pod lifecycle.
- They are created by admins and claimed by users via Persistent Volume Claims.
- Support different storage backends like local disks, cloud storage, or network storage.
- Enable stateful applications to keep data safe and available.
- Allow sharing storage between pods if access modes permit.