StorageClass CreationΒΆ

MetalK8s uses StorageClass objects to describe how volumes are formatted and mounted. This topic explains how to use the CLI to create a StorageClass.

  1. Create a StorageClass manifest.

    You can define a new StorageClass using the following template:

    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: <storageclass_name>
    provisioner: kubernetes.io/no-provisioner
    reclaimPolicy: Retain
    volumeBindingMode: WaitForFirstConsumer
    mountOptions:
      - rw
    parameters:
      fsType: <filesystem_type>
      mkfsOptions: <mkfs_options>
    

    Set the following fields:

    • mountOptions: specifies how the volume should be mounted. For example: rw (read/write), or ro (read-only).

    • fsType: specifies the filesystem to use on the volume. xfs and ext4 are the only currently supported file system types.

    • mkfsOptions: specifies how the volume should be formatted. This field is optional (note that the options are passed as a JSON-encoded string). For example '["-m", "0"]' could be used as mkfsOptions for an ext4 volume.

    • Set volumeBindingMode as WaitForFirstConsumer in order to delay the binding and provisioning of a Pod until a Pod using the PersistentVolumeClaim is created.

  2. Create the StorageClass.

    root@bootstrap $ kubectl apply -f storageclass.yml
    
  3. Check that the StorageClass has been created.

    root@bootstrap $ kubectl get storageclass <storageclass_name>
    NAME                         PROVISIONER                    AGE
    <storageclass_name>          kubernetes.io/no-provisioner   2s