FlexVolume explored

As I covered in my previous blog post, FlexVolume is just not another Kubernetes volume plugin. It enables third-party vendors to add support for their storage backends in Kubernetes. All third party vendors have to do is provide a binary executable driver which implements FlexVolume callouts. FlexVolume also allows vendors to transparently pass down vendor specific options from Kubernetes pod spec to their drivers.

Flex volume plugin definition
Plugin definition is very similar to other Kubernetes volume plugins. In addition, it allows user to pass any vendor specific options to their driver as key value pairs. FlexVolume plugin or Kubernetes will not interpret these options and will pass them transparently to the backend driver.

In the following example pod spec, FlexVolume is using the driver “kubernetes.io/lvm” and the options “VolumeID” & “VolumeGroup” are specific to “kubernetes.io/lvm” driver and are passed transparently to it. As we know, the “VolumeGroup” is a construct which is specific to LVM and thus without requiring any changes to LVM & Kubernetes, with the power of flex volume vendors can enable their existing storage backends by simply implementing a driver.

The following pod spec uses a volume “vol1” from LVM’s volume group “kube_vg” and sets it up for the pod named “fio” and mounts the volume at /data inside the pod.

FlexVolume plugin callouts
FlexVolume plugin invokes third party driver binaries with the following callouts to set up the volume.

  1. Attach: attach a volume to Kubernetes Kubelet node.
  2. Detach: detach the volume from Kubernetes Kubelet node.
  3. Mount: mount the attached volume
  4. Unmount: unmount the attached volume.

It is NOT necessary for a driver to implement all these callouts. Driver can respond back saying “Not supported” for some of these callouts. For example, a network file system FlexVolume driver can respond “Not supported” to attach and detach callouts as there is nothing to attach and detach for network file systems.

It is straightforward and easy to implement a third-party driver using these callouts. If you need more information or help, please feel free to ping me at [email protected].

For additional information, the links below are a good starting point.

Call out syntax
Please refer to driver invocation model at: https://github.com/kubernetes/kubernetes/tree/master/examples/flexvolume

Example Driver
Please refer to: https://github.com/kubernetes/kubernetes/blob/master/examples/flexvolume/lvm for an example FlexVolume driver.

Steps to install third-party driver
Install the third-party driver in vendor~driver directory under kubelet-plugins. Kubelet restart is required after installing the plugin to take effect.

└── exec
└── vendor~driver
└── driver