tezvyn:

PersistentVolumeClaim: How Pods Request Storage

AI-drafted, machine-checkedSource: kubernetes.iobeginner
PersistentVolumeClaim: How Pods Request Storage

A PersistentVolumeClaim (PVC) is a request for storage, like a claim check for a storage locker. Pods use it to mount durable storage for databases or file uploads. The footgun: a PVC is just a request; a matching PersistentVolume must exist to fulfill it.

WHY IT EXISTS Pods are ephemeral; their internal filesystems are destroyed when they die. Stateful applications like databases need data to survive pod restarts. Kubernetes needed a way to decouple the transient lifecycle of a Pod from the persistent lifecycle of its storage.

THE MENTAL MODEL A PersistentVolumeClaim (PVC) is a request for storage made by an application. It's like ordering from a cloud provider's menu: "I need 50 GiB of fast SSD storage that can be written to by one Pod at a time." The PVC doesn't care which specific disk provides this, only that its requirements are met. It abstracts the storage implementation away from the application developer.

HOW IT WORKS A developer defines a PVC in a YAML file, specifying requirements like storage capacity (e.g., storage: 8Gi) and access modes (e.g., ReadWriteOnce). When the PVC is created, Kubernetes tries to find a matching PersistentVolume (PV)—a piece of storage provisioned by an admin—that satisfies the claim. If a suitable PV is found, Kubernetes binds the PVC to it. If a StorageClass is configured for dynamic provisioning, a new PV can be created on-demand. A Pod manifest then references the PVC by name to mount the volume.

WHEN TO USE IT Use a PVC whenever a Pod needs to store data that must survive its own termination. This is standard for databases (PostgreSQL, MySQL), message queues with disk-backed persistence (RabbitMQ), or any application that needs to save files, like a CMS or an artifact repository.

WHEN NOT TO USE IT For temporary, scratch data that can be lost when a Pod dies, a simpler emptyDir volume is more appropriate. For application configuration, use ConfigMaps or Secrets, not a persistent volume. PVCs are for application data, not configuration or ephemeral scratch space.

ONE CANONICAL EXAMPLE A WordPress deployment. The WordPress application runs in a stateless Pod. It needs a place to store user-uploaded images. You create a PVC requesting 20Gi of storage. The WordPress Pod's deployment manifest then references this PVC by name, mounting it at /var/www/html/wp-content. If the Pod crashes and restarts, the new Pod re-attaches to the same PVC, and all the images are still there because the underlying storage (the PV) was never deleted.

Read the original → kubernetes.io

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.