Configuring shared volumes for virtual machines

You can configure shared disks to allow multiple virtual machines (VMs) to share the same underlying storage. A shared disk’s volume must be block mode.

You configure disk sharing by exposing the storage as either of these types:

  • An ordinary virtual machine disk

  • A logical unit number (LUN) device with an iSCSi connection and raw device mapping, as required for Windows Failover Clustering for shared volumes

Configuring disk sharing by using virtual machine disks

You can configure block volumes so that multiple virtual machines (VMs) can share storage.

The application running on the guest operating system determines the storage option you must configure for the VM. A disk of type disk exposes the volume as an ordinary disk to the VM.

Prerequisites

  • The volume access mode must be ReadWriteMany (RWX) if the VMs that are sharing disks are running on different nodes.

    If the VMs that are sharing disks are running on the same node, ReadWriteOnce (RWO) volume access mode is sufficient.

  • The storage provider must support the required Container Storage Interface (CSI) driver.

Procedure

  1. Create the VirtualMachine manifest for your VM to set the required values, as shown in the following example:

    1. apiVersion: kubevirt.io/v1
    2. kind: VirtualMachine
    3. metadata:
    4. name: <vm_name>
    5. spec:
    6. template:
    7. # ...
    8. spec:
    9. domain:
    10. devices:
    11. disks:
    12. - disk:
    13. bus: virtio
    14. name: rootdisk
    15. disk1: disk_one (1)
    16. - disk:
    17. bus: virtio
    18. name: cloudinitdisk
    19. disk2: disk_two
    20. shareable: true (2)
    21. interfaces:
    22. - masquerade: {}
    23. name: default
    1Identifies a device as a disk.
    2Identifies a shared disk.
  2. Save the VirtualMachine manifest file to apply your changes.

Configuring disk sharing by using LUN

You can configure a LUN-backed virtual machine disk to be shared among multiple virtual machines by enabling SCSI persistent reservation. Enabling the shared option allows you to use advanced SCSI commands, such as those required for a Windows failover clustering implementation, against the underlying storage. Any disk to be shared must be in block mode.

A disk of type LUN exposes the volume as a LUN device to the VM. This allows the VM to execute arbitrary iSCSI command passthrough on the disk.

You reserve a LUN through the SCSI persistent reserve options to protect data on the VM from outside access. To enable the reservation, you configure the feature gate option. You then activate the option on the LUN disk to issue SCSI device-specific input and output controls (IOCTLs) that the VM requires.

Prerequisites

  • The volume access mode must be ReadWriteMany (RWX) if the VMs that are sharing disks are running on different nodes.

    If the VMs that are sharing disks are running on the same node, ReadWriteOnce (RWO) volume access mode is sufficient.

  • The storage provider must support a Container Storage Interface (CSI) driver that uses the SCSI protocol.

  • If you are a cluster administrator and intend to configure disk sharing by using LUN, you must enable the cluster’s feature gate on the HyperConverged custom resource (CR).

Procedure

  1. Edit or create the VirtualMachine manifest for your VM to set the required values, as shown in the following example:

    1. apiVersion: kubevirt.io/v1
    2. kind: VirtualMachine
    3. metadata:
    4. name: vm-0
    5. spec:
    6. template:
    7. spec:
    8. domain:
    9. devices:
    10. disks:
    11. - disk:
    12. bus: sata
    13. name: rootdisk
    14. - errorPolicy: report
    15. lun: (1)
    16. bus: scsi
    17. reservation: true (2)
    18. name: na-shared
    19. serial: shared1234
    20. volumes:
    21. - dataVolume:
    22. name: vm-0
    23. name: rootdisk
    24. - name: na-shared
    25. persistentVolumeClaim:
    26. claimName: pvc-na-share
    1Identifies a LUN disk.
    2Identifies that the persistent reservation is enabled.
  2. Save the VirtualMachine manifest file to apply your changes.

Enabling the PersistentReservation feature gate

You can enable the SCSI persistentReservation feature gate and allow a LUN-backed block mode virtual machine (VM) disk to be shared among multiple virtual machines.

The persistentReservation feature gate is disabled by default.

Prerequisites

  • Cluster administrator privileges are required.

  • The volume access mode ReadWriteMany (RWX) is required if the VMs that are sharing disks are running on different nodes. If the VMs that are sharing disks are running on the same node, the ReadWriteOnce (RWO) volume access mode is sufficient.

  • The storage provider must support a Container Storage Interface (CSI) driver that uses the SCSI protocol.

Procedure

  1. Enable the persistentReservation feature gate by running the following command:

    1. $ oc patch hyperconverged kubevirt-hyperconverged -n kubevirt-hyperconverged \
    2. --type json -p '[{"op":"replace","path":"/spec/featureGates/persistentReservation", "value": true}]'

Additional resources