Curriculum / Part 7 · Kubernetes, schedulers and data locality
Lesson 31

Storage in Kubernetes

Kubernetes storage objects: PersistentVolume, PersistentVolumeClaim, StorageClass, CSI drivers, access modes and binding modes.

⏱ 35 min5-question quizLab 7.1

The simple version

You fill in a form asking for "a 2 TB locker that four people can open" (the claim). The building manager checks which locker types they have (storage classes) and gives you a real locker (the volume). If you asked for something no locker type offers, your form just sits in the tray.

The objects

ObjectWhat it is
PersistentVolumeClaim (PVC)A request: size, access mode, storage class
PersistentVolume (PV)An actual piece of storage bound to one claim
StorageClassA recipe: which CSI driver provisions it, reclaim policy, binding mode
CSI driverThe plugin that creates and attaches storage for a given system

Access modes

ModeMeaningTypical backing
ReadWriteOnce (RWO)Read-write by one nodeBlock devices, local NVMe
ReadOnlyMany (ROX)Read-only by many nodesShared filesystems, snapshots
ReadWriteMany (RWX)Read-write by many nodesShared filesystems (NFS, parallel FS)
ReadWriteOncePod (RWOP)Read-write by one podDrivers that support it

A multi-node training job that shares a dataset volume needs RWX or ROX from a class backed by shared storage. Asking a node-local class for RWX leaves the claim, and its pods, Pending (Lab 7.1).

Binding and lifecycle

volumeBindingMode: WaitForFirstConsumer delays provisioning until a pod is scheduled, so node-local volumes land on the right node; Immediate provisions as soon as the claim exists. reclaimPolicy: Retain keeps the data when the claim is deleted; Delete removes it. Most of a claim's spec can't change after creation: to switch class or mode, create a new claim.

$ kubectl get pvc,pv,sc
$ kubectl describe pvc train-data    # events explain why it's Pending

Tools

kubectl get pvc|pv|sc|pods
State of claims, volumes, classes and pods.
kubectl describe pvc NAME
Events from the provisioner (why it's Pending).
kubectl apply -f / delete pvc
Create or replace claims.

Quiz

Lab

Lab 7.1 · Pods stuck Pending

Four training pods (trainer-0 to trainer-3) must all read and write the same dataset volume. They have been Pending for minutes. The claim is defined in manifests/train-pvc.yaml.

Start lab 7.1 →

Try it now in the simulator (opens with the command ready; press Enter):

$ kubectl get sc$ cat manifests/train-pvc.yaml