Bookmark this page

Guided Exercise: Attach Persistent Storage to Virtual Machines

In your environment, NFS storage runs on slower, less expensive disks, and Red Hat OpenShift Data Foundation block storage runs on faster, more expensive backing devices. You need two new VMs for an upcoming project. The vm1 database machine requires faster storage, whereas vm2 is an internal-use file server that can use less expensive storage. In this exercise, you connect these two VMs to the appropriate storage service that meets the requirements.

Outcomes

  • Prepare new VM disks.

  • Attach disks to VMs.

  • Detach and delete disks from VMs.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

This command ensures that the cluster API is reachable. It also creates the storage-intro namespace and starts two virtual machines in that namespace: the vm1 VM, which hosts a MariaDB database, and the vm2 VM, which hosts a web server.

[student@workstation ~]$ lab start storage-intro

Instructions

  1. Use the OpenShift web console to confirm that the two VMs are running.

    1. Open a web browser and navigate to the web console URL. Select htpasswd_provider and log in as the admin user with redhatocp as the password.

      • https://console-openshift-console.apps.ocp4.example.com

    2. Navigate to VirtualizationVirtualMachines and select the storage-intro project. Confirm that the vm1 and vm2 VMs are running.

  2. Prepare a 5 GiB blank disk for the vm1 database server. Attach the disk to the VM by using a virtio interface. Use the ocs-external-storagecluster-ceph-rbd-​virtualization storage class, which provides fast block storage.

    1. Stop the vm1 VM so that you can use the virtio interface to attach the new disk. Remember that the only available interface is scsi when the VM is running.

      Select the vm1 VM and then click ActionsStop. Click Stop to confirm the operation, if needed. Wait for the machine to stop.

    2. Navigate to the ConfigurationDisks tab and then click Add disk. Complete the form by using the following information and click Save to create and attach the disk to the VM.

      Field Value
      Use this disk as a boot source Unset
      Name dbdata
      SourceBlank (creates PVC)
      Size5 GiB
      TypeDisk
      InterfaceVirtIO
      StorageClass ocs-external-storagecluster-ceph-rbd-​virtualization
      Apply optimized StorageProfile settings Checked
      Acces modeShared access (RWX)
      Volume modeBlock
      Enable preallocation Unset

      Note

      If the Interface field is set to scsi and virtio is not available, then click Cancel and start over. The web interface takes a few seconds to detect that the VM stopped.

    3. Click ActionsStart to start the vm1 VM.

      Note

      If a yellow admonition appears, then wait a few moments and try again to start the VM.

    4. Log in to the VM console and confirm that a new 5 GiB device is available. Navigate to the Console tab and then log in as the root user with redhat as the password. Run the lsblk command to list the block devices. Notice the 5 GiB vdc block device.

      [root@vm1 ~]# lsblk
      NAME     MAJ:MIN   RM   SIZE   RO   TYPE   MOUNTPOINT
      vda      252:0      0    10G    0   disk
      ├─vda1   252:1      0     1M    0   part
      ├─vda2   252:2      0   100M    0   part   /boot/efi
      └─vda3   252:3      0   9.9G    0   part   /
      vdb      252:16     0     1M    0   disk
      vdc      252:32     0     5G    0   disk	1

      1

      The vdc block device corresponds to the new disk that you added in a previous step.

    5. Log out of the VM console.

      [root@vm1 ~]# logout
  3. Prepare a 10 GiB blank disk for the vm2 web server. Attach the disk to the VM by using a virtio interface. Use the nfs-storage storage class.

    1. Navigate to VirtualizationVirtualMachines and then select the vm2 VM.

    2. Stop the vm2 VM so that you can use the virtio interface to attach the new disk. Click ActionsStop to stop the vm2 VM. Click Stop to confirm the operation, if needed. Wait for the machine to stop.

    3. Navigate to the ConfigurationDisks tab and then click Add disk. Complete the form by using the following information. At the bottom of the form, notice that the volume mode is set to Filesystem by default. Do not change that parameter. Click Save to create and attach the disk to the VM.

      Field Value
      Use this disk as a boot source Unset
      Name staticdata
      SourceBlank (creates PVC)
      Size10 GiB
      TypeDisk
      InterfaceVirtIO
      StorageClass nfs-storage
      Apply optimized StorageProfile settings Checked
      Access modeShared access (RWX)
      Volume modeFilesystem
      Enable preallocation Unset
    4. Click ActionsStart to start the vm2 VM.

    5. Log in to the VM console and confirm that a new 10 GiB device is available. Navigate to the Console tab and then log in as the root user with redhat as the password. Run the lsblk command to list the block devices. Notice the 10 GiB vdc block device.

      Note

      Even though you create the volume in Filesystem mode, OpenShift Virtualization exposes the volume as a block device to the operating system inside the VM. As a consequence, the lsblk command that you run inside the VM reports the volume as a new block device.

      [root@vm2 ~]# lsblk
      NAME     MAJ:MIN   RM   SIZE   RO   TYPE   MOUNTPOINT
      vda      252:0      0    10G    0   disk
      ├─vda1   252:1      0     1M    0   part
      ├─vda2   252:2      0   100M    0   part   /boot/efi
      └─vda3   252:3      0   9.9G    0   part   /
      vdb      252:16     0     1M    0   disk
      vdc      252:32     0    10G    0   disk	1

      1

      The vdc block device corresponds to the new disk that you added in a previous step.

    6. Log out of the VM console.

      [root@vm2 ~]# logout
  4. Detach the additional disk from the vm2 VM.

    1. Click ActionsStop to stop the vm2 VM.

    2. Navigate to the ConfigurationDisks. At the end of the row of the staticdata disk, click the vertical ellipsis icon and then click Detach. Click Detach in the confirmation window.

    3. Click ActionsStart to start the vm2 VM.

    4. Log in to the VM console and confirm that the device no longer exists. Navigate to the Console tab and then log in as the root user with redhat as the password. Run the lsblk command to list the block devices. Notice that the command no longer reports the vdc device.

      [root@vm2 ~]# lsblk
      NAME     MAJ:MIN   RM   SIZE   RO   TYPE   MOUNTPOINT
      vda      252:0      0    10G    0   disk
      ├─vda1   252:1      0     1M    0   part
      ├─vda2   252:2      0   100M    0   part   /boot/efi
      └─vda3   252:3      0   9.9G    0   part   /
      vdb      252:16     0     1M    0   disk
    5. Log out of the VM console.

      [root@vm2 ~]# logout

Finish

On the workstation machine, use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish storage-intro

Revision: do316-4.14-d8a6b80