Loading

Quipoin Menu

Learn • Practice • Grow

kubernetes / Persistent Volumes
tutorial

Persistent Volumes

While regular volumes are tied to a Pod’s lifecycle, persistent volumes provide storage that lives independently of any Pod. They are a cluster‑wide resource that users can claim and reuse.

PersistentVolume (PV)

A PV is a piece of storage in the cluster provisioned by an administrator. It is independent of any Pod. Examples include NFS shares, cloud disks (AWS EBS, GCE PD), or local storage.

PersistentVolumeClaim (PVC)

A PVC is a request for storage by a user or Pod. It specifies size, access modes, and optionally a StorageClass. When a PVC is created, Kubernetes binds it to an available PV that satisfies the request.

PVCs decouple Pods from the actual storage implementation.

Example: PV and PVC

First, create a PV using hostPath (for testing only):
apiVersion: v1
kind: PersistentVolume
metadata:
name: test-pv
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /mnt/data
Now create a PVC that requests 500Mi of storage:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: test-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 500Mi
Apply both:
kubectl apply -f pv.yaml
kubectl apply -f pvc.yaml
Check binding status:
kubectl get pv
kubectl get pvc

Using a PVC in a Pod

Mount the PVC as a volume in a Pod:
apiVersion: v1
kind: Pod
metadata:
name: pvc-pod
spec:
volumes:
- name: my-storage
persistentVolumeClaim:
claimName: test-pvc
containers:
- name: app
image: busybox
command: ["sh", "-c", "echo Data > /data/file.txt; sleep 3600"]
volumeMounts:
- name: my-storage
mountPath: /data

StorageClasses

In production, PVs are often dynamically provisioned using StorageClasses. A StorageClass defines a “type” of storage (e.g., fast SSDs, slow HDDs). When you create a PVC with a StorageClass, Kubernetes automatically provisions a matching PV.


Two Minute Drill
  • PersistentVolume (PV) is cluster storage; PersistentVolumeClaim (PVC) requests it.
  • PVCs bind to PVs based on size and access modes.
  • Pods use PVCs as volumes.
  • StorageClasses enable dynamic provisioning.

Need more clarification?

Drop us an email at career@quipoinfotech.com