Bookmark this page

Lab: Virtual Machine Template Management

Create two Red Hat Enterprise Linux templates based on predefined images that contain a MariaDB server and an Apache HTTP server. You then create two VMs from the templates and confirm that the VMs contain a database with preloaded data and a configured web server.

Outcomes

  • Create two templates that use the mariadb-server and web-server images by defining the attributes.

  • Create a VM from the customized mariadb-server template and access it to confirm that the MariaDB service is up and running.

  • Create a VM from the customized web-server template and access it to confirm that the web server is up and running.

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 template-review namespace, and creates the mariadb-server and web-server persistent volume claims in that namespace.

[student@workstation ~]$ lab start template-review

Instructions

  1. From the command line on the workstation machine, use the oc command to log in to your Red Hat OpenShift cluster as the admin user with redhatocp as the password. The OpenShift cluster API endpoint is https://api.ocp4.example.com:6443. Open a web browser and log in to the OpenShift web console at https://console-openshift-console.apps.ocp4.example.com.

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

      [student@workstation ~]$ oc login -u admin -p redhatocp \
        https://api.ocp4.example.com:6443
      Login Successful
      ...output omitted...
    2. 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 redhatocp as the password.

  2. Clone the rhel8-server-small VM template to the template-review namespace and name it mariadb-server. Define a 20 GiB rootdisk volume that uses the ocs-external-storagecluster-ceph-rbd storage class as the boot source. Define the source of the rootdisk volume as the mariadb-server PVC in the template-review namespace. Enable the Live Migration eviction strategy. Configure the cloud-init service to create a dbadmin user with redhatocp as the password on VMs that are created from the template. Finally, use template variables to configure the name of the rootdisk data volume to the name of the VM that the template creates.

    1. Navigate to VirtualizationTemplates. Select the All Projects project from the Projects list and search for rhel8-server-small. Click the vertical ellipsis icon and select Clone.

    2. In the Clone template form, change Template name to mariadb-server. Change Template project to template-review. Leave the other form fields with their default values. Click Clone.

    3. Navigate to VirtualizationTemplates. Select the template-review project from the Projects list and select the mariadb-server template.

    4. Select the Scheduling tab and click the pencil icon under Eviction strategy. Confirm that the checkbox for Live Migration is selected, and then click Save.

    5. Select the Network interfaces tab, and confirm that the default interface is on the Pod Networking network and that it uses the Masquerade type.

    6. Select the Disks tab and detach the rootdisk disk. Click the vertical ellipsis icon next to the rootdisk line, and then click Detach. Click Detach to confirm.

    7. Click Add disk to create the rootdisk disk. Complete the form by using the following information and then click Save. Leave the other form fields with their default values.

      ParametersValue
      Use this disk as a boot source enabled
      Name rootdisk
      Source PVC (creates PVC)
      PVC project template-review
      PVC name mariadb-server
      PersistentVolumeClaim size 20 GiB
      StorageClass ocs-external-storageclass-ceph-rbd
      Apply optimized StorageProfile settings enabled
    8. Review the storage settings to confirm that the rootdisk volume storage size is bootable, that it has 20 GiB, and that it uses the ocs-external-storagecluster-ceph-rbd storage class.

    9. Use the YAML editor to set the name of the rootdisk data volume to the name of the VM that the template creates. Navigate to the YAML tab and locate the spec.dataVolumeTemplates.metadata.name and spec.template.volumes.datavolume.name objects. Update the object values to use the ${NAME} template variable, and then click Save.

    10. Configure Cloud-init to create the dbadmin user with redhatocp as the password. Select the Scripts tab and click Edit next to Cloud-init. In the User field, enter dbadmin and in the Password field, enter redhatocp and then click Apply.

  3. Create a mariadb-server-vm VM from the custom mariadb-server template in the template-review namespace.

    1. Navigate to VirtualizationCatalog. On the right panel of filter options, under Template project, select the template-review project and select the newly created template, Red Hat Enterprise Linux 8 VM.

    2. Enter mariadb-server-vm in the VirtualMachine Name field. Confirm that Start this virtual machine after creation is selected. Click Quick create VirtualMachine. Wait a few moments for the operation to complete.

  4. Connect to the console of the mariadb-server-vm VM. Log in as the dbadmin user with redhatocp as the password, which you defined in a previous step. Connect to the MariaDB instance as the devuser with developer as the password, by using the mysql -u devuser -p command. Use the SHOW DATABASES; command to confirm that the preconfigured sakila database is available. Exit the MariaDB instance with the EXIT; command and then log out of the VM.

    1. Navigate to VirtualizationVirtualMachines. Select the mariadb-server-vm machine to open the Overview tab for the VM.

    2. Click the Console tab and then click Guest login credentials to confirm that the defined guest login credentials are the dbadmin user with redhatocp as the password.

    3. Use the console to log in as the dbadmin user.

      mariadb-server-vm login: dbadmin
      password: redhatocp
      [dbadmin@mariadb-server-vm ~]$
    4. Connect to the MariaDB instance as the devuser with developer as the password.

      [dbadmin@mariadb-server-vm ~]$ mysql -u devuser -p
      Enter password: developer
      Welcome to the MariaDB monitor. Commands end with ; or \g.
      ...output omitted...
      MariaDB [(none)]>
    5. Confirm that the sakila database is available. Exit the MariaDB instance and then log out of the VM.

      MariaDB [(none)]> SHOW DATABASES;
      ----------------------
      | Database           |
      ----------------------
      | information++_++schema |
      | sakila             |
      ----------------------
      2 rows in set (0.004 sec)
      
      MariaDB [(none)]> EXIT;
      Bye
      [dbadmin@mariadb-server-vm ~]$ logout
  5. Clone the rhel8-server-small VM template to the template-review namespace and name it web-server. Define a 15 GiB rootdisk volume that uses the ocs-external-storagecluster-ceph-rbd storage class with a ReadWriteMany access mode and a Block volume mode. Define the boot source of the rootdisk volume as the web-server PVC within the template-review namespace. Attach an additional 5 GiB disk named tmpdata, which uses the ocs-external-storagecluster-cephfs storage class with the ReadWriteMany access mode and the Filesystem volume mode. Use template variables to configure the name of the rootdisk data volume to the name of the VM that the template creates. Enable the Live Migration eviction strategy. Configure the cloud-init service to create a webadmin user with redhatocp as the password on VMs that are created from the template.

    1. Navigate to VirtualizationTemplates. Select the All Projects project from the Projects list and search for rhel8-server-small. Click the vertical ellipsis icon and select Clone.

    2. In the Clone template form, change Template name to web-server. Change Template project to template-review. Leave the other form fields with their default values. Click Clone.

    3. Navigate to VirtualizationTemplates. Select the template-review project from the Projects list and select the web-server template.

    4. Select the Scheduling tab and click the pencil icon under Eviction strategy. Confirm that the checkbox for Live Migration is selected, and then click Save.

    5. Select the Network interfaces tab and confirm that the default interface is on the Pod Networking network and that it uses the Masquerade type.

    6. Select the Disks tab and detach the rootdisk disk. Click the vertical ellipsis icon next to the rootdisk line, and then click Detach. Click Detach to confirm.

    7. Click Add disk to create the rootdisk disk. Complete the form by using the following information and then click Save.

      ParametersValue
      Use this disk as a boot source enabled
      Name rootdisk
      Source PVC (creates PVC)
      PVC project template-review
      PVC name web-server
      PersistentVolumeClaim size 15 GiB
      StorageClass ocs-external-storageclass-ceph-rbd
      Apply optimized StorageProfile settings enabled
    8. Click Add disk to create the tmpdata disk. Complete the form by using the following information and then click Save.

      ParametersValue
      Use this disk as a boot source disabled
      Name tmpdata
      Source Blank (creates PVC)
      PersistentVolumeClaim size 5 GiB
      StorageClass ocs-external-storageclass-cephfs
      Apply optimized StorageProfile settings enabled
    9. Review the storage settings to confirm that the rootdisk volume storage size is bootable, that it has 15 GiB and that it uses the ocs-external-storagecluster-ceph-rbd storage class. Review the storage settings to confirm that the tmpdata volume storage has 5 GiB and that it uses the ocs-external-storagecluster-cephfs storage class.

    10. Use the YAML editor to set the name of the rootdisk data volume to the name of the VM that the template creates. Navigate to the YAML tab and locate the spec.dataVolumeTemplates.metadata.name and spec.template.volumes.datavolume.name objects. Update the object values to use the ${NAME} template variable, and then click Save.

    11. Configure Cloud-init to create the webadmin user with redhatocp as the password. Select the Scripts tab and click Edit next to Cloud-init. In the User field, enter webadmin, and in the Password field, enter redhatocp and then click Apply.

  6. Create a web-server-vm VM from the custom web-server template in the template-review namespace.

    1. Navigate to VirtualizationCatalog. On the right panel of filter options, under Template project, select the template-review project and select the newly created web-server Red Hat Enterprise Linux 8 VM template.

    2. Enter web-server-vm in the VirtualMachine Name field. Confirm that Start this virtual machine after creation is selected. Click Quick create VirtualMachine. Wait a few moments for the operation to complete.

  7. Connect to the VNC console of the web-server-vm VM by using the virtctl vnc command. Log in as the dbadmin user with redhatocp as the password, which you defined in a previous step. Confirm that the 5 GiB tmpdata disk is available as the vdc block device by using the lsblk command. Use the curl localhost command to confirm that the Apache HTTP web server responds to requests. Afterwards, log out of the VM and then disconnect from the VNC console.

    1. In the command line, connect to the console of the web-server-vm with the virtctl vnc command.

      [student@workstation ~]$ virtctl vnc web-server-vm -n template-review
    2. In the console window, log in as the webadmin user with redhatocp as the password.

      web-server-vm login: webadmin
      password: redhatocp
      [webadmin@web-server-vm ~]$
    3. Confirm that the tmpdata disk is available as the vdc block device.

      [webadmin@web-server-vm ~]$ lsblk
      NAME  MAJ:MIN  RM  SIZE RO TYPE
      vda   252:0     0    1M  0 disk
      vdb   252:16    0   30G  0 disk
      ...output omitted...
      vdc   252:32    0    5G  0 disk
    4. Confirm that the Apache httpd service is loaded and running. Press q to exit the status log.

      [webadmin@web-server-vm ~]$ systemctl status httpd
      ● httpd.service - The Apache HTTP Server
         Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
         Active: active (running) since Tue 2024-03-26 13:43:42 EDT; 5min ago
           Docs: man:httpd.service(8)
       Main PID: 922 (httpd)
         Status: "Running, listening on: port 80"
      ...output omitted...
    5. Use the curl command to confirm that the web server responds to requests. The command returns some HTML content.

      [webadmin@web-server-vm ~]$ curl localhost
      <!DOCTYPE html
      ...output omitted...
      </html>
    6. Log out of the VM and then close the VNC console.

      [webadmin@web-server-vm ~]$ logout

Evaluation

As the student user on the workstation machine, use the lab command to grade your work. Correct any reported failures and rerun the command until successful.

[student@workstation ~]$ lab grade template-review

Finish

As the student user 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 template-review

Revision: do316-4.14-d8a6b80