Bookmark this page

Guided Exercise: Connect Virtual Machines to External Storage

Add a data disk to a MariaDB VM over iSCSI to accommodate a new database. Use a dedicated data disk from your SAN with iSCSI.

Outcomes

  • Create a Persistent Volume to declare an iSCSI target.

  • Create a Persistent Volume Claim and attach it as a VM disk.

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. The command also creates the storage-external namespace and starts a virtual machine named mariadb-server in that namespace.

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

Instructions

  1. As the admin user, locate and then navigate to the OpenShift web console. Confirm that the mariadb-server VM is running.

    1. From the command line, log in to your Red Hat OpenShift cluster as the admin user.

      [student@workstation ~]$ oc login -u admin -p redhat \
        https://api.ocp4.example.com:6443
      Login Successful
      ...output omitted...
    2. Identify the URL for the OpenShift web console.

      [student@workstation ~]$ oc whoami --show-console
      https://console-openshift-console.apps.ocp4.example.com
    3. Open a web browser and navigate to https://console-openshift-console.apps.ocp4.example.com. Select htpasswd_provider and log in as the admin user with redhat as the password.

    4. Navigate to VirtualizationVirtualMachines. Confirm that the mariadb-server VM is running.

  2. Create the PV resource that declares the iSCSI target to connect.

    1. From the command line on the workstation machine, review the /home/student/DO316/labs/storage-external/pv.yaml resource file that the lab command prepared.

      [student@workstation ~]$ cat ~/DO316/labs/storage-external/pv.yaml
      apiVersion: v1
      kind: PersistentVolume
      metadata:
        name: iscsi-pv
      spec:
        capacity:
          storage: 1Gi
        accessModes:
          - ReadWriteOnce
        volumeMode: Block
        claimRef:  1
          name: mariadb-binlog
          namespace: storage-external
        iscsi:  2
           targetPortal: 192.168.51.40:3260
           iqn: iqn.2021-10.com.example:server.disk1
           lun: 0
           initiatorName: iqn.2021-10.com.example:client-server.disk1

      1

      The claimRef section specifies that the PV is for a PVC named mariadb-binlog in the storage-external namespace. A following step instructs you to create that PVC.

      2

      The iscsi section provides the details of the iSCSI target in the classroom environment.

    2. Use the oc command to create the resource:

      [student@workstation ~]$ oc apply -f ~/DO316/labs/storage-external/pv.yaml
      persistentvolume/iscsi-pv created

      If you prefer the OpenShift web console, then navigate to StoragePersistentVolumes. Click Create PersistentVolume and then copy and paste the ~/DO316/labs/storage-external/pv.yaml resource file into the YAML editor. Click Create.

    3. Run the oc get pv command to verify your work.

      [student@workstation ~]$ oc get pv
      NAME        CAPACITY    ACCESS MODES    RECLAIM POLICY    STATUS    ...
      iscsi-pv    1Gi         RWO             Retain            Available ...
      ...output omitted...
  3. Create the mariadb-binlog PVC and confirm that Kubernetes binds it to the PV.

    1. From the command line, review the /home/student/DO316/labs/storage-external/pvc.yaml resource file that the lab command prepared.

      [student@workstation ~]$ cat ~/DO316/labs/storage-external/pvc.yaml
      apiVersion: v1
      kind: PersistentVolumeClaim
      metadata:
        name: mariadb-binlog
        namespace: storage-external
      spec:
        resources:
          requests:
            storage: 1Gi
        accessModes:
          - ReadWriteOnce
        volumeMode: Block

      Notice that the name, namespace, storage, accessModes, and volumeMode parameters match the parameters of the PV resource.

    2. Use the oc command to create the resource:

      [student@workstation ~]$ oc apply -f ~/DO316/labs/storage-external/pvc.yaml
      persistentvolumeclaim/mariadb-binlog created

      If you prefer the OpenShift web console, then navigate to StoragePersistentVolumeClaims and select the storage-external project. Click Create PersistentVolumeClaimWith Form and then complete the form by using the following information:

      FieldValue
      StorageClass Keep the default provided class
      PersistentVolumeClaim name mariadb-binlog
      Access mode Single user (RWO)
      Size 1 GiB
      Volume mode Block

      Click Create.

    3. Run the oc get pvc command to confirm that Kubernetes binds your PVC to the iscsi-pv PV.

      [student@workstation ~]$ oc get pvc -n storage-external
      NAME            STATUS  VOLUME    CAPACITY  ACCESS MODES  STORAGECLASS  AGE
      mariadb-binlog  Bound   iscsi-pv  1Gi       RWO           nfs-storage   10m
      ...output omitted...

      The command must report the status as Bound and the volume as iscsi-pv.

      Note

      If you do not get that status, then delete the PVC and the PV and start again. Ensure that you create the PVC in the storage-external project with the correct name and parameters.

      Use the oc command to delete the resources:

      [student@workstation ~]$ oc delete pvc mariadb-binlog -n storage-external
      persistentvolumeclaim "mariadb-binlog" deleted
      [student@workstation ~]$ oc delete pv iscsi-pv
      persistentvolume "iscsi-pv" deleted
  4. Attach the mariadb-binlog PVC as a disk to the mariadb-server VM by using a virtio interface.

    1. Use the OpenShift web console to stop the 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.

      Navigate to VirtualizationVirtualMachines, select the mariadb-server VM, and then click ActionsStop. Wait for the machine to stop.

    2. Navigate to the Configuration tab and then click Add disk. Complete the form by using the following information:

      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 is stopped.

      Click Save to create and attach the disk to the VM.

      FieldValue
      Name binlogdisk
      Source Use an existing PVC
      PVC name mariadb-binlog
      Type Disk
      Interface VirtIO
    3. Click ActionsStart and then wait for the machine to start.

    4. Log in to the VM console and confirm that a new 1 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 1 GiB vdc block device.

      [root@mariadb-server ~]# 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    1G  0 disk
    5. Log out of the VM console.

      [root@mariadb-server ~]# 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-external

Revision: do316-4.14-d8a6b80