Volume Management Using the CLI

This topic describes how to create and delete a MetalK8s Volume using the CLI. Volume objects enable a declarative provisioning of persistent storage, to use in Kubernetes workloads (through PersistentVolumes).

Requirements

  • StorageClass objects must be registered in your cluster to create Volumes. For more information refer to StorageClass Creation.

Creating a Volume

  1. Create a Volume manifest using one of the following templates:

    rawBlockDevice Volumes

    apiVersion: storage.metalk8s.scality.com/v1alpha1
    kind: Volume
    metadata:
      name: <volume_name>
    spec:
      nodeName: <node_name>
      storageClassName: <storageclass_name>
      mode: "Filesystem"
      rawBlockDevice:
        devicePath: <devicePath>
    

    Set the following fields:

    • name: the name of your volume, must be unique.

    • nodeName: the name of the node where the volume will be located.

    • storageClassName: the StorageClass to use.

    • mode: describes how the volume is intented to be consumed, either Block or Filesystem (default to Filesystem if not specified).

    • devicePath: path to the block device (for example: /dev/sda1).

    lvmLogicalVolume Volumes

    apiVersion: storage.metalk8s.scality.com/v1alpha1
    kind: Volume
    metadata:
      name: <volume_name>
    spec:
      nodeName: <node_name>
      storageClassName: <storageclass_name>
      mode: "Filesystem"
      lvmLogicalVolume:
        vgName: <vg_name>
        size: 10Gi
    

    Set the following fields:

    • name: the name of your volume, must be unique.

    • nodeName: the name of the node where the volume will be located.

    • storageClassName: the StorageClass to use.

    • mode: describes how the volume is intented to be consumed, either Block or Filesystem (default to Filesystem if not specified).

    • vgName: LVM VolumeGroup name to create the LogicalVolume the VolumeGroup must exists on the Node.

    • size: Size of the LVM LogicalVolume to create.

  2. Create the Volume.

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

    root@bootstrap $ kubectl get volume <volume_name>
    NAME             NODE        STORAGECLASS
    <volume_name>   bootstrap   metalk8s-demo-storageclass
    

Deleting a Volume

Note

A Volume object can only be deleted if there is no backing storage, or if the volume is not in use. Otherwise, the volume will be marked for deletion and remain available until one of the conditions is met.

  1. Delete a Volume.

    root@bootstrap $ kubectl delete volume <volume_name>
    volume.storage.metalk8s.scality.com <volume_name> deleted
    
  2. Check that the Volume has been deleted.

    Note

    The command below returns a list of all volumes. The deleted volume entry should not be found in the list.

    root@bootstrap $ kubectl get volume