learninfra · Linux · Networking · Kubernetes · System Design · AI Infrastructure · Exam blueprints · Drills

Storage (CKA)

Volumes that outlive pods: PVs, PVCs, StorageClasses and reclaim policies.

An interactive Kubernetes lesson: 23 steps, about 35 minutes, on a live simulation in your browser.

The shop records every order in a database pod, db, and web writes to it through a Service. A container's own filesystem is thrown away whenever the container restarts, so the data directory is mounted from a volume.

The simplest volume type is emptyDir: an empty directory the kubelet creates on the node when the pod is assigned there. Every container in the pod can mount it.

What you will learn

  1. Data that dies with the pod

    • emptyDir: a scratch directory: A volume belongs to the pod, not to a container. Containers only mount it.
    • A container restart keeps it: emptyDir survives container restarts, because the pod survives them.
    • Delete the pod: emptyDir lives exactly as long as its pod. Use it for caches and scratch space, never for data you need back.
  2. Volumes and claims

    • A PersistentVolume is cluster storage: A PersistentVolume is a piece of storage registered with the cluster. It exists whether or not any pod uses it.
    • A claim is a request: A claim is a request; a PV is the supply. Binding is one-to-one: the smallest PV that satisfies the claim is taken whole.
    • The pod mounts the claim: Pod → claim → volume. The pod holds a reference, the claim holds the binding, the volume holds the data.
    • Break it: three claims that never bind
    • Access modes: Access modes count nodes, not pods: RWO one node, ROX and RWX many. Only RWOP counts pods.
  3. When the claim is deleted

    • Retain: the data outlives the claim: Retain means: keep the data, and wait for a human. A Released volume is safe, not reusable.
    • Making a Released volume Available: Released → Available takes a deliberate act: clear claimRef. Kubernetes never recycles retained data by itself.
  4. StorageClasses

    • A StorageClass makes volumes on demand: Static: an admin makes PVs and claims pick from them. Dynamic: a claim names a StorageClass and a PV is made to order.
    • The default class, and a claim that waits: Immediate: provision when the claim is created. WaitForFirstConsumer: provision when a pod using the claim is scheduled. Pending without a pod is normal there.
    • The first consumer arrives: WaitForFirstConsumer lets the pod choose the place and makes the volume follow. Immediate makes the pod follow the volume.
    • Delete: the volume goes with the claim: Reclaim policy answers one question: when the claim is deleted, is the data kept (Retain) or destroyed (Delete)?
    • Break it: growing a volume
    • Break it: nobody to provision
  5. One volume per replica

    • StatefulSet: a claim per replica: volumeClaimTemplates give each StatefulSet replica its own claim, tied to the pod's ordinal: queue-1 always gets data-queue-1.
    • Scale the StatefulSet down: A StatefulSet creates claims and, by default, never deletes them. Removing a replica's data is always a separate, manual step.
  6. Pending claims

    • Reading a Pending claim: A Pending pod points at a Pending claim, and the claim's events name the cause. Always describe the claim.
    • Drill: why is the claim Pending?
    • Drill: protect a volume
  7. Recap & playground

    • Cheat sheet
    • Playground