VolumeAttachment

A cloud disk must be attached to a Node before a Pod mounts it, yet for a CSI volume the Kubelet attaches nothing. Who records the attachment, how does the Kubelet learn it is done, and what detaches the disk?

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

VolumeAttachment diagram: The VolumeAttachment object

VolumeAttachment, step by step

  1. The attach and detach controller in kube-controller-manager, not Kubelet, decides that a CSI volume needs attaching. It sees a Pod bound to a Node with a volume not attached there and takes the job on, if the driver requires attach. With attachRequired false no VolumeAttachment is written.

    Play from step 1
  2. The controller writes VolumeAttachment csi-7f3a, its name a hash of volume handle, driver and Node. Its spec names that driver, vol-1 and Node-1, and status.attached reads false because nothing has set it yet. It is the one cluster record that vol-1 belongs on Node-1. Nothing physical has happened yet.

    Play from step 2
  3. The external-attacher for the driver the spec names picks this one up, adds its finalizer and calls ControllerPublishVolume, which attaches vol-1 to Node-1 in the storage backend. The device is physically on the Node now, and Kubelet still will not touch it, because the object still says false.

    Play from step 3
  4. When the backend confirms the attach, the attacher writes status.attached true back onto the same VolumeAttachment, changing its status in place with nothing recreated. Everything downstream waits for that one field.

    Play from step 4
  5. Kubelet has been blocked all along. It first waits for vol-1 to be listed as attached in the Node status, and the controller adds vol-1 to that list only after status.attached turns true. Kubelet then checks that same field on the object before it has vol-1 mounted for the Pod at /data. Only then does the Pod start.

    Play from step 5
  6. Deleting the object is what tears the attach down. On a healthy Node, once the Pod is gone and Kubelet reports vol-1 unmounted, the controller deletes the object. The attacher sees the deletion mark, calls ControllerUnpublishVolume, and once vol-1 is detached it lifts its finalizer and the object goes.

    Play from step 6

Sources