Node
Mounting a volume
CSI attach and mount
From a PersistentVolumeClaim to a directory inside the container, through the CSI driver. The web app gets an uploads volume: 10 Gi on fast-nvme. The chain has five links - claim, provision, attach, stage, publish - and the container doesn't start until the last one clicks into place.
- Claim
- uploads · 10Gi · ReadWriteOnce
- Class
- fast-nvme · WaitForFirstConsumer
- Volume
- pvc-3f8a91c2… · 10 Gi
- In the container
- /uploads · ext4
Read the whole lesson as text
1. The claim
You apply a PersistentVolumeClaim: 10 Gi, ReadWriteOnce, class fast-nvme. No disk exists yet, and none will for now: the class says WaitForFirstConsumer, so the claim stays Pending until a Pod that uses it is scheduled. A disk made now might land in a zone where the Pod can't run.
- kubectl posts the claim: 10 Gi on fast-nvme.
- The claim stays Pending: the class waits for the first Pod that uses it.
2. The Pod decides
Now a Pod that mounts the claim. The scheduler weighs the Pod's requests and the zones fast-nvme can serve, picks node-2 in zone b, and writes that choice onto the claim. The driver's provisioner sidecar - an ordinary Pod watching the API - sees it, asks the backend for a 10 Gi volume in zone b, and writes back a PersistentVolume. The claim turns Bound. Only then does the scheduler bind the Pod to node-2.
- The scheduler plans around the volume's topology, picks node-2, and tells the claim.
- The driver's provisioner sees where the Pod will run, creates a volume there, and offers a PV.
- The Pod is bound to node-2. Its kubelet immediately needs the volume - which is not attached to this node yet.
3. Attach
The driver's controller half - a Deployment talking to the storage backend - runs ControllerPublishVolume: map pvc-3f8a91c2… to node-2. On the node this appears as a new device, /dev/nvme2n1. Attaching is cluster work; it happens once per volume per node, no matter how many Pods there mount it.
- The driver attaches the volume to node-2 over the storage network.
- The disk is visible on node-2; the kubelet can proceed to mounting.
4. Stage and publish
Now the node half of the driver - a DaemonSet Pod on node-2. NodeStageVolume does the once-per-volume work: mkfs.ext4 on first use, then a mount at a global path. NodePublishVolume does the per-Pod work: a bind mount of the staged filesystem into the Pod's own directory under /var/lib/kubelet. Splitting them means a second Pod on this node mounts in milliseconds, no second format.
- The node plugin formats the empty disk and stages one filesystem for the whole node.
- A bind mount of the staged filesystem appears in the Pod's volume directory.
5. Into the container
The kubelet hands the mount to containerd with the Pod spec. runc, setting up the container's mount namespace, bind-mounts the Pod directory at /uploads inside the new rootfs. The app opens /uploads/logo.png and writes - and the bytes travel the storage network to the nvme pool, though the app only ever saw a local directory.
- The container is created with the volume in its mount list.
- The app saves a file, and the bytes leave for the storage backend.
Summary
Claim, provision, attach, stage, publish - then one more mount into the container's namespace. Each link is a different controller talking to a different thing: the API server, the storage backend, the node's kernel. The Pod sat in Pending and then ContainerCreating through all of it, because a container with a promised volume starts only when the volume is real.
Next lesson: List and watch