Schedule Volumes by Label
Volume scheduling based on drive labels
DirectPV offers multiple ways to restrict how volumes schedule to drives:
- Available drive space
- Node topology with affinity and anti-affinity and similar tools
- User-defined drive labels
You can assign labels to classify types of drives. Once assigned, use those labels in storage class parameters to select the desired types.
By default, the DirectPV drives do not have any user-defined labels set on them.
Use kubectl directpv label drives
to set user-defined labels for DirectPV drives.
Tutorial
<label-key>
,<label-value>
and <drive-name>
with appropriate values based on the classification you chose
-
Set the label on the DirectPV drive(s).
kubectl directpv label drives <label-key>=<label-value> --drives /dev/<drive-name>
-
Verify that the labels are properly set by using the
list
command with the--show-labels
flag.kubectl directpv list drives --drives /dev/<drive-name> --show-labels
-
Create or modify the storage class definition.
Set a
parameter
value in the definition YAML. The value should follow the formdirectpv-min-io/<label-key>: <label-value>
.parameters: directpv.min.io/<label-key>: <label-value>
Refer to the default storage classkubectl get storageclass directpv-min-io -n directpv -o yaml
to compare and check if all the fields are present on the new storage class.The following YAML is an example of a storage class definition that includes a
parameters
section:allowVolumeExpansion: false allowedTopologies: - matchLabelExpressions: - key: directpv.min.io/identity values: - directpv-min-io apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: finalizers: - foregroundDeletion labels: application-name: directpv.min.io application-type: CSIDriver directpv.min.io/created-by: kubectl-directpv directpv.min.io/version: v1beta1 name: directpv-min-io-new # Define any storage class name of your choice resourceVersion: "511457" uid: e93d8dab-b182-482f-b8eb-c69d4a1ec62d parameters: fstype: xfs directpv.min.io/<label-key>: <label-value> provisioner: directpv-min-io reclaimPolicy: Delete volumeBindingMode: WaitForFirstConsumer
-
Deploy the workload with the new storage class name set.
Volumes are only placed on the labeled drives. You can verify this with the following command:
kubectl directpv list drives --labels <label-key>:<label-value> kubectl directpv list volumes