Skip to main content

How do we restrict a StorageClass to specific nodes?

Syself support For release

To restrict a StorageClass to specific nodes, create your own StorageClass with allowedTopologies and leave standard unchanged. Syself Autopilot manages standard, and an update reverts changes to it.

Set volumeBindingMode: WaitForFirstConsumer on your class. Without the field, Kubernetes uses Immediate and creates the volume before the pod has a node.

How narrow the restriction can be depends on the storage driver:

  • Hetzner Cloud Volumes (csi.hetzner.cloud): the topology is the Hetzner location. A class can allow fsn1 only, but it cannot name single nodes.
  • TopoLVM (topolvm.io): a volume lives on one bare-metal server, so a class can list individual servers by node name, with the key topology.topolvm.io/node.

A class for Hetzner Cloud Volumes in one location:

yaml
				apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: standard-fsn1
provisioner: csi.hetzner.cloud
volumeBindingMode: WaitForFirstConsumer
reclaimPolicy: Retain
allowVolumeExpansion: true
allowedTopologies:
  - matchLabelExpressions:
      - key: csi.hetzner.cloud/location
        values: ["fsn1"]
			

A StorageClass decides where a volume is created. To decide where the pod runs, use a nodeSelector or node affinity. Hetzner Cloud Volumes attach only to cloud servers, so keep pods that use them on cloud nodes, for example with the node label autopilot.syself.com/machine-type: hcloud.

Check the Storage classes reference for the classes that come with your cluster. For the node labels you can select on, see Node affinity and selectors in practice.

Still stuck?

Prepare your case, then email us.