What is a PersistentVolume in Kubernetes?

· Category: Kubernetes

Short answer

A PersistentVolume (PV) is a cluster-wide storage resource provisioned by an administrator or dynamically by a StorageClass. It abstracts the underlying storage system and provides durable storage for Pods.

How it works

A PV is a piece of storage in the cluster that has been provisioned. It has a lifecycle independent of any individual Pod. When a Pod needs storage, it requests a PV through a PersistentVolumeClaim. The PV is then bound to the claim and mounted into the Pod.

Example

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv0001
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /data/pv0001

Why it matters

PVs decouple storage from Pods, allowing data to persist beyond the Pod lifecycle. They support various backends like NFS, cloud disks, and local storage, making Kubernetes suitable for stateful applications.

Key differences

  • PV: Cluster resource, provisioned by admin or dynamic provisioner.
  • PVC: User request for storage.
  • StorageClass: Defines the provisioner and parameters for dynamic provisioning.

Common issues

  • Mismatched access modes prevent binding.
  • Retention policies determine whether data is kept or deleted when a PVC is removed.
  • Node affinity constraints can block Pod scheduling for local volumes.