Dynamic Volume Provisioning Example Using StatefulSet

Dynamic PV provisioning is the easiest and most popular way of consuming persistent storage volumes exported from a Lightbits storage cluster. In this use case, Kubernetes instructs the Lightbits CSI plugin to create a volume on a specific Lightbits storage cluster, and makes it available on the appropriate Kubernetes cluster node before a pod requiring the storage is scheduled for execution on that node.

To consume PVs created for a particular StorageClass, the StorageClass name (not the YAML specification filename) must be referenced within a definition of another Kubernetes object.

For instance, to configure a StatefulSet to provide its pods with 10GB of persistent storage volumes from the StorageClass described above, you would enter something similar to the following into the StatefulSet.spec.volumeClaimTemplates section:

YAML
Copy

An example Kubernetes specification of StatefulSet to create several simple busybox-based pods that use PVs from an example-sc StorageClass is provided in the examples/statefulset-workload.yaml file of the Supplementary Package.

The commands and their respective outputs in the following shell transcript illustrate the creation of a StatefulSet from this specification and the corresponding Kubernetes object created.

Your output will differ, including different IP addresses, Kubernetes cluster nodes, PV and PVC names, and long output lines in the sample output are wrapped to fit the page width.

An example Kubernetes specification of StatefulSet to create several simple busybox-based pods that use PVs from an “example-sc” StorageClass is provided in the examples/statefulset-workload.yaml file of the supplementary package.

Deploying StatefulSet

To create the StatefulSet, run:

Bash
Copy

Verifying StatefulSet Deployment

Verify that all resources are created and in READY state.

Bash
Copy
Bash
Copy
Bash
Copy
Bash
Copy

As can be seen above, three pods belonging to the example-sts StatefulSet were created, with three corresponding PVs and PVCs.

To confirm that a pod has a PV attached to it and mounted, you can execute the following command and then cross-reference the output against the listings of PVs and PVCs, as shown in the previous sample output.

Bash
Copy

Based on the “Mounts:” section of the output example, you can see how the PV is represented inside a pod by executing the following command:

Bash
Copy

Most of the mountpoints of the container running inside the pod above are either virtual file systems or file systems rooted in Docker overlay mounts. However, the Lightbits-backed volume mountpoint will be a direct mount of the NVMe device exported to the Kubernetes node over NVMe/TCP transport (here: /dev/nvme0n3).

To see the corresponding underlying volumes information of the Lightbits storage server, you can connect to the Lightbits server using SSH. Then, use the Lightbits CLI utility (lbcli, see the Lightbits Administrator's Guide for details), to execute the following command:

Bash
Copy

When the Lightbits CSI plugin creates a volume on the Lightbits storage cluster, it uses the name of the PV that Kubernetes passed to it as the Lightbits volume name. Therefore, you can also cross-reference the volume names in the lbcli output against the kubectl pv command output that you obtained earlier.

Removing StatefulSet

Finally, to remove the StatefulSet and all of the corresponding pods created by the instructions above - as well as to verify their removal - execute the following commands:

Bash
Copy
Bash
Copy

Due to the way that StatefulSet-s are currently implemented in Kubernetes, the PVs and PVCs created by the above instructions—and the Lightbits volumes backing them—will likely remain for reasons detailed in the following note.

Kubernetes has a number of features designed to avert user data loss by preventing PV and/or PVC deletion in circumstances that might otherwise seem unexpected to someone unfamiliar with Kubernetes workings. These include:

  • Reclaim policy of PVs (see the “Reclaiming” section of the Kubernetes PVs documentation for details).
  • Protection of in-use PVs/PVCs (see the “Storage Object in Use Protection” section of the Kubernetes PVs documentation for details). StatefulSet PVC protection (see Kubernetes GitHub issue #55045).

The general Kubernetes troubleshooting links in the previous note might help in finding the root cause for the PV/PVC not being deleted as expected.

Make sure that you delete leftover PVC and PV resources before you proceed, by running the following commands:

Bash
Copy

Verify that all PV, PVC and PODs are gone:

Bash
Copy
Type to search, ESC to discard
Type to search, ESC to discard
Type to search, ESC to discard