I'm trying to leverage a local volume dynamic provisioner for k8s, Rancher's one, with multiple instances, each with its own storage class so that I can provide multiple types of local volumes based on their performance (e.g. ssd, hdd ,etc).
The underlying infrastructure is not symmetric; some nodes only have ssds, some only hdds, some of them both.
I know that I can hint the scheduler to select the proper nodes by providing node affinity rules for pods.
But, is there a better way to address this problem at the level of provisioner / storage class only ? E.g., make a storage class only available for a subset of the cluster nodes.
There is no need to define node affinity rules on
Podlevel when using local persistent volumes. Node affinity can be specified inPersistentVolumedefinition.No, it cannot be specified on a
StorageClasslevel. Neither you can make aStorageClassavailable only for a subset of nodes.But when it comes to a provisioner, I would say yes, it should be feasible as one of the major storage provisioner tasks is creating matching
PersistentVolumeobjects in response toPersistentVolumeClaimcreated by the user. You can read about it here:So looking at the whole volume provision process from the very beginning it looks as follows:
User creates only
PersistenVolumeClaimobject, where he specifies aStorageClass:and it can be used in a
Poddefinition:So in practice, in a
Poddefinition you need only to specify the properPVC. No need for defining any node-affinity rules here.A
Podreferences aPVC,PVCthen references aStorageClass,StorageClassreferences theprovisionerthat should be used:So in the end it is the task of a
provisionerto create matchingPersistentVolumeobject. It can look as follows:So a
Podwhich uses myclaimPVC-> which references the local-storageStorageClass-> which selects a proper storageprovisionerwill be automatically scheduled on the node selected inPVdefinition created by this provisioner.