Course contentsShow
← Software Engineering
Lesson 1449 of 1,93342. Containerization and OrchestrationFree lesson

Volumes and Persistent Storage

Understanding ephemeral and persistent volumes, storage classes, and persistent volume claims.

Volumes and Persistent Storage

You'll learn how Kubernetes handles ephemeral container data versus persistent storage that survives pod restarts.

The Problem: Containers Are Ephemeral

By default, containers—and the pods that contain them—are temporary. When a pod dies or restarts, all data inside its filesystem disappears. This is fine for stateless applications, but databases, file uploads, logs, and user-generated content need to survive beyond a single pod's lifetime.

Understanding Volume Types

Kubernetes offers multiple volume types to address different persistence needs:

Ephemeral Volumes attach to a pod's lifecycle. When the pod is deleted, so is the volume. Examples include emptyDir (shared scratch space between containers in a pod) and configMap or secret volumes (inject configuration).

Persistent Volumes (PV) are cluster-wide storage resources that exist independently of any pod. They represent actual storage (cloud disks, network file systems, local disks) provisioned by administrators or dynamically.

The Persistent Volume Claim (PVC) Pattern

Rather than pods directly referencing storage infrastructure, Kubernetes uses an abstraction layer:

  1. PersistentVolumeClaim (PVC): A developer requests storage with specific size and access requirements
  2. PersistentVolume (PV): Kubernetes binds the claim to an available volume that meets those requirements
  3. StorageClass: Defines how storage is provisioned (which cloud provider, performance tier, replication policy)

This separation lets developers request "100GB of fast storage" without knowing whether it's AWS EBS, Google Persistent Disk, or a local SSD.

Lifecycle Independence

Once bound, a PVC and its data persist even if the pod using it is deleted. You can redeploy the pod, and it reconnects to the same PVC—your data is still there. Storage classes also define reclaim policies (retain, delete, or recycle the PV when the PVC is deleted).

Key Takeaway: Kubernetes separates ephemeral (pod-coupled) storage from persistent storage using PersistentVolumeClaims, StorageClasses, and PersistentVolumes, enabling stateful applications to survive pod restarts and migrations.