Attach and Mount Chain

A new PVC asks for a cloud disk, and before the app in its Pod can write a byte, the CSI driver is called several times. What does each call do, in what order, and which of them are undone when the Pod is deleted?

Play the animation 5 steps, animated, plays on a computer or a tablet

Attach and Mount Chain diagram: The CSI attach and mount chain

Attach and Mount Chain, step by step

  1. CreateVolume runs first, on the controller side, for a dynamically provisioned claim. The provisioner asks the driver to carve a real disk out of the cloud backend. When the call returns, a disk called vol-1 exists somewhere in the provider, but it is not attached to any Node yet and nothing can read a byte of it.

    Play from step 1
  2. ControllerPublishVolume runs next, if the driver requires attach. The attach and detach controller writes a VolumeAttachment for the Node the Pod is on, and the external-attacher turns it into this call. Here that is a cloud API call, and vol-1 shows up on the Node as a raw block device, /dev/nvme1n1, still unformatted.

    Play from step 2
  3. Once the VolumeAttachment shows attached, Kubelet sends NodeStageVolume, the first of two Node calls, on a driver that stages. The node plugin formats the device if still blank and mounts it once, at a staging path Kubelet just made. Stage and publish are split so one mount per Node serves however many Pods use it.

    Play from step 3
  4. NodePublishVolume is the last call, once per Pod. It usually bind-mounts the staged filesystem into this Pod private directory rather than mounting the disk again. Kubelet may then apply the Pod fsGroup, unless the driver did, and the runtime binds the result into the container as /data. Only then does Pod A start and begin writing.

    Play from step 4
  5. When Pod A is deleted, the calls unwind in reverse. NodeUnpublishVolume drops the Pod A bind mount. If no other Pod on the Node uses the volume, NodeUnstageVolume unmounts the staging path, which Kubelet deletes. On a healthy Node only then does ControllerUnpublishVolume detach the disk. The disk stays: reclaim policy acts only once the claim goes.

    Play from step 5

Sources