Kubernetes StorageClasses

StorageClassess in Kubernetes are used to link PVCs with a backend storage provisioner. For instance StorageOS. A StorageClass defines parameters to pass to the provisioner. Which in case of StorageOS, they can translate into behaviour applied to the Volumes. Many StorageClasses can be provisioned to apply different feature labels to the StorageOS Volumes.

By default the StorageOS Cluster Operator installs the fast StorageClass at bootstrap of StorageOS. You can define its name in the StorageOS Cluster Resource.

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: fast
  labels:
    app: storageos
provisioner: csi.storageos.com # CSI Driver
allowVolumeExpansion: true
parameters:
  pool: default
  csi.storage.k8s.io/fstype: ext4

  # Change the NameSpace below if StorageOS doesn't run in kube-system
  csi.storage.k8s.io/controller-expand-secret-name: csi-controller-expand-secret
  csi.storage.k8s.io/controller-publish-secret-name: csi-controller-publish-secret
  csi.storage.k8s.io/node-publish-secret-name: csi-node-publish-secret
  csi.storage.k8s.io/provisioner-secret-name: csi-provisioner-secret
  csi.storage.k8s.io/controller-expand-secret-namespace: kube-system   # NameSpace that runs StorageOS Daemonset
  csi.storage.k8s.io/controller-publish-secret-namespace: kube-system  # NameSpace that runs StorageOS Daemonset
  csi.storage.k8s.io/node-publish-secret-namespace: kube-system        # NameSpace that runs StorageOS Daemonset
  csi.storage.k8s.io/provisioner-secret-namespace: kube-system         # NameSpace that runs StorageOS Daemonset

StorageClasses can be created to define default labels for StorageOS volumes. But also to map to any semantic aggregation of volumes that suit your use case. Whether there are different roles, dev, staging and prod. Or a StorageClass maps to a team or customer using the cluster, etc.

Examples

You can find the basic examples in the StorageOS use-cases repository, in the 00-basic directory.

git clone https://github.com/storageos/use-cases.git storageos-usecases
cd storageos-usecases/00-basic

StorageClass definition in v2-storageclass-replicated.yaml.

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: storageos-replicated
provisioner: csi.storageos.com # CSI Driver
allowVolumeExpansion: true
parameters:
  fsType: ext4
  pool: default
  storageos.com/replicas: "1" # Enforces 1 replica for the Volume

  # Change the NameSpace below if StorageOS doesn't run in kube-system
  csi.storage.k8s.io/controller-expand-secret-name: csi-controller-expand-secret
  csi.storage.k8s.io/controller-publish-secret-name: csi-controller-publish-secret
  csi.storage.k8s.io/node-publish-secret-name: csi-node-publish-secret
  csi.storage.k8s.io/provisioner-secret-name: csi-provisioner-secret
  csi.storage.k8s.io/controller-expand-secret-namespace: kube-system   # NameSpace that runs StorageOS Daemonset
  csi.storage.k8s.io/controller-publish-secret-namespace: kube-system  # NameSpace that runs StorageOS Daemonset
  csi.storage.k8s.io/node-publish-secret-namespace: kube-system        # NameSpace that runs StorageOS Daemonset
  csi.storage.k8s.io/provisioner-secret-namespace: kube-system         # NameSpace that runs StorageOS Daemonset

That StorageClass can be used by a PVC:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-vol-1
spec:
  storageClassName: "storageos-replicated" # StorageOS StorageClass
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi

The above StorageClass has the storageos.com/replicas label set. This label tells StorageOS to create a volume with a replica. Adding StorageOS feature labels to the StorageClass ensures all volumes created with the StorageClass have the same labels.

You can also choose to add the label in the PVC definition rather than the StorageClass. The PVC definition takes precedence over the SC.