CSI Ephemeral Volumes

A Pod needs a credential from an external store mounted as files, with no PV or PVC created for it. How can a driver hand over a volume that lives as long as the Pod, and what in the cluster has to allow it first?

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

CSI Ephemeral Volumes, Kubernetes diagram

CSI Ephemeral Volumes, step by step

  1. Pod web-0 declares a CSI volume inline, with the driver name, a few volumeAttributes and readOnly true, which this driver requires. The Pod names no claim, so no PVC or PV is created and no StorageClass is read. An inline CSI volume is never attached, so no VolumeAttachment either. The Pod lands on Node-1 and Kubelet picks up its spec.

    Play from step 1
  2. Kubelet checks the CSIDriver object of this driver. The object lists Ephemeral in volumeLifecycleModes, so an inline volume is allowed. With no such mode, or no CSIDriver at all, Kubelet refuses the mount. The attributes come straight from the Pod author, so an admin says no by removing the mode or with a webhook.

    Play from step 2
  3. Kubelet calls NodePublishVolume on the node plugin directly, with no ControllerPublishVolume and no NodeStageVolume. The call carries the volumeAttributes plus Pod info, since this CSIDriver sets podInfoOnMount. With no PV to take a handle from, Kubelet also adds a volume id, a hash of the Pod UID and volume name.

    Play from step 3
  4. The driver has to create the volume inside that one call. Here it is the Secrets Store driver, and it mounts an empty tmpfs at the path Kubelet gave it. The volume attributes point to a SecretProviderClass, and the provider plugin that class names fetches db-password from the external store while the driver waits.

    Play from step 4
  5. With db-password in hand the driver writes it into that tmpfs as a file, and the call returns. Only then does Kubelet start the container, so the Pod turns Running and the app reads db-password at /mnt/secrets like any other file.

    Play from step 5
  6. Deleting the Pod takes the volume with it. Once its containers have stopped, Kubelet calls NodeUnpublishVolume and the driver deletes the volume, and only then is the Pod object gone. There is no claim to release and no PV to reclaim, because the volume lives and dies with the Pod.

    Play from step 6

Sources