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
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.
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:6443Login Successful ...output omitted...
Open a web browser and navigate to https://console-openshift-console.apps.ocp4.example.com.
Select and log in as the admin user with redhatocp as the password.
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.
Navigate to → .
Select the All Projects project from the list and search for rhel8-server-small.
Click the vertical ellipsis icon and select .
In the form, change to mariadb-server.
Change to .
Leave the other form fields with their default values.
Click .
Navigate to → .
Select the template-review project from the list and select the mariadb-server template.
Select the tab and click the pencil icon under .
Confirm that the checkbox for Live Migration is selected, and then click .
Select the tab, and confirm that the default interface is on the Pod Networking network and that it uses the Masquerade type.
Select the tab and detach the rootdisk disk.
Click the vertical ellipsis icon next to the rootdisk line, and then click .
Click to confirm.
Click to create the rootdisk disk.
Complete the form by using the following information and then click .
Leave the other form fields with their default values.
| Parameters | Value |
|---|---|
| enabled | |
rootdisk
| |
PVC (creates PVC)
| |
template-review
| |
mariadb-server
| |
20 GiB
| |
ocs-external-storageclass-ceph-rbd
| |
| enabled |
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.
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 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 .
Configure Cloud-init to create the dbadmin user with redhatocp as the password.
Select the tab and click next to Cloud-init.
In the field, enter dbadmin and in the field, enter redhatocp and then click .
Create a mariadb-server-vm VM from the custom mariadb-server template in the template-review namespace.
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.
Navigate to → .
Select the mariadb-server-vm machine to open the tab for the VM.
Click the tab and then click to confirm that the defined guest login credentials are the dbadmin user with redhatocp as the password.
Use the console to log in as the dbadmin user.
mariadb-server-vm login:dbadminpassword:redhatocp[dbadmin@mariadb-server-vm ~]$
Connect to the MariaDB instance as the devuser with developer as the password.
[dbadmin@mariadb-server-vm ~]$mysql -u devuser -pEnter password:developerWelcome to the MariaDB monitor. Commands end with ; or \g. ...output omitted... MariaDB [(none)]>
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
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.
Navigate to → .
Select the All Projects project from the list and search for rhel8-server-small.
Click the vertical ellipsis icon and select .
In the form, change to web-server.
Change to .
Leave the other form fields with their default values.
Click .
Navigate to → .
Select the template-review project from the list and select the web-server template.
Select the tab and click the pencil icon under .
Confirm that the checkbox for Live Migration is selected, and then click .
Select the tab and confirm that the default interface is on the Pod Networking network and that it uses the Masquerade type.
Select the tab and detach the rootdisk disk.
Click the vertical ellipsis icon next to the rootdisk line, and then click .
Click to confirm.
Click to create the rootdisk disk.
Complete the form by using the following information and then click .
| Parameters | Value |
|---|---|
| enabled | |
rootdisk
| |
PVC (creates PVC)
| |
template-review
| |
web-server
| |
15 GiB
| |
ocs-external-storageclass-ceph-rbd
| |
| enabled |
Click to create the tmpdata disk.
Complete the form by using the following information and then click .
| Parameters | Value |
|---|---|
| disabled | |
tmpdata
| |
Blank (creates PVC)
| |
5 GiB
| |
ocs-external-storageclass-cephfs
| |
| enabled |
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.
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 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 .
Configure Cloud-init to create the webadmin user with redhatocp as the password.
Select the tab and click next to Cloud-init.
In the field, enter webadmin, and in the field, enter redhatocp and then click .
Create a web-server-vm VM from the custom web-server template in the template-review namespace.
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.
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-reviewIn the console window, log in as the webadmin user with redhatocp as the password.
web-server-vm login:webadminpassword:redhatocp[webadmin@web-server-vm ~]$
Confirm that the tmpdata disk is available as the vdc block device.
[webadmin@web-server-vm ~]$lsblkNAME 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
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...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>Log out of the VM and then close the VNC console.
[webadmin@web-server-vm ~]$ logout