Create a Red Hat Enterprise Linux VM from an existing MariaDB image and use it to manage a database server.
Outcomes
Create a VM.
Access the VNC console with the virtctl command.
Access the database with the oc port-forward command.
Manage the VM from the command line.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
[student@workstation ~]$ lab start accessing-create
This command ensures that all resources are available for this exercise.
Instructions
As the admin user, locate and navigate to the Red Hat OpenShift web console.
Use the terminal to log in to your Red Hat OpenShift cluster as the admin user.
[student@workstation ~]$oc login -u admin -p redhatocp \https://api.ocp4.example.com:6443Login Successful ...output omitted...
Identify the URL for the OpenShift web console.
[student@workstation ~]$ oc whoami --show-console
https://console-openshift-console.apps.ocp4.example.comOpen a web browser and navigate to https://console-openshift-console.apps.ocp4.example.com.
Click and log in as the admin user with redhatocp as the password.
Create a VM that contains a preconfigured MariaDB database server.
From the OpenShift web console, locate the left panel. If you do not see the left panel, then click the main menu icon at the upper left of the web console.
Navigate to → . Select the → project.
![]() |
Navigate to → .
![]() |
Select the template and click the button.
![]() |
Specify databasevm as the VM name.
Select the → menu option.
Specify http://utility.lab.example.com:8080/openshift4/images/mariadb-server.qcow2 in the field.
![]() |
From the section, enter redhat123 for the field.
![]() |
Click the button.
Select the tab and then click the Cloud-init
icon.
![]() |
Change the Cloud-init user to operator1 and click .
![]() |
Navigate to the tab. Click the edit icon for . Increase the memory value to 4 GiB.
![]() |
Select the tab and confirm that the network interface type is masquerade.
![]() |
Select the tab and confirm that the attached disks include cloudinitdisk and rootdisk.
![]() |
Review the settings and click to create the VM.
![]() |
Review the details of your new VM.
From the VM Overview tab, wait until the changes to Running before continuing this exercise.

Access the VNC console with the virtctl command and retrieve the status of the database server.
In your terminal, select the creating-accessing-vms project.
[student@workstation ~]$ oc project creating-accessing-vms
Now using project "creating-accessing-vms" on server "https://api.ocp4.example.com:6443".List the available VM instances.
[student@workstation ~]$ oc get vmi
NAME AGE PHASE IP NODENAME READY
databasevm 3m Running 10.8.2.12 worker02 TrueOpen a new terminal window and use the virtctl vnc command to access the VM's VNC console.
Log in to the console as the operator1 user with redhat123 as the password, as previously defined in the Optional parameters settings.
[student@workstation ~]$ virtctl vnc databasevm![]() |
You can find the credentials in the OpenShift web console. Navigate to → and select your VM. Click the tab and then click .
Retrieve the status of the database server.
[cloud-user@databasevm ~]$ systemctl status mariadb
mariadb.service - MariaDB 10.3 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled)...
Active: active (running)...
...output omitted...Access the MariaDB service with the oc port-forward command.
Open a new terminal window and use the oc get pods command to determine the name of the virt-launcher pod of the VMI.
Your virt-launcher pod has a different name from the following example.
[student@workstation ~]$oc get podsNAME READY STATUS RESTARTS AGE virt-launcher-databasevm-g92gf 1/1 Running 0 9m22s [student@workstation ~]$PODNAME=virt-launcher-databasevm-g92gf[student@workstation ~]$echo $PODNAMEvirt-launcher-databasevm-g92gf
Use the oc port-forward command to connect to the virt-launcher pod of the VMI. Specify the 33066:3306 ports.
[student@workstation ~]$ oc port-forward $PODNAME 33066:3306
Forwarding from 127.0.0.1:33066 -> 3306
Forwarding from [::1]:33066 -> 3306A successful connection does not return your console to the command-line prompt. This behavior is expected.
Open another terminal window and use the mysql command to connect to the MariaDB database on 127.0.0.1.
Log in as the devuser user with developer as the password, and specify the port with the -P 33066 option.
[student@workstation ~]$mysql -u devuser -h 127.0.0.1 -P 33066 -pEnter password:developerWelcome to the MariaDB monitor. Commands end with ; or \g....output omitted...
The VM already contains a loaded database named sakila that has several tables. Retrieve the data from the actor and city tables.
MariaDB [(none)]>USE sakila;...output omitted... Database changed MariaDB [sakila]>SELECT * FROM actor;+----------+-------------+--------------+---------------------+ | actor_id | first_name | last_name | last_update | +----------+-------------+--------------+---------------------+ | 1 | PENELOPE | GUINESS | 2006-02-15 04:34:33 | | 2 | NICK | WAHLBERG | 2006-02-15 04:34:33 | | 3 | ED | CHASE | 2006-02-15 04:34:33 | | 4 | JENNIFER | DAVIS | 2006-02-15 04:34:33 | ...output omitted... MariaDB [sakila]>SELECT * FROM city;+---------+----------------------------+------------+---------------------+ | city_id | city | country_id | last_update | +---------+----------------------------+------------+---------------------+ | 1 | A Corua (La Corua) | 87 | 2006-02-15 04:45:25 | | 2 | Abha | 82 | 2006-02-15 04:45:25 | | 3 | Abu Dhabi | 101 | 2006-02-15 04:45:25 | | 4 | Acua | 60 | 2006-02-15 04:45:25 | ...output omitted...
Exit the database.
MariaDB [sakila]>EXIT;bye
Return to the terminal that is executing the oc port-forward command.
Press Ctrl+C to end the connection.
[student@workstation ~]$ oc port-forward virt-launcher-databasevm-4qqj6 33066:3306
Forwarding from 127.0.0.1:33066 -> 3306
Forwarding from [::1]:33066 -> 3306
Handling connection for 33066
^C[student@workstation ~]$Manage the VM instance from the command line.
Use the virtctl command to stop the VMI and then delete the VM with the oc delete command.
[student@workstation ~]$oc get vmiNAME AGE PHASE IP NODENAME READY databasevm 3m Running 10.8.2.12 worker02 True [student@workstation ~]$virtctl stop databasevmVM databasevm was scheduled to stop [student@workstation ~]$oc delete vm databasevmvirtualmachine.kubevirt.io "databasevm" deleted
Confirm that the resource no longer exists.
[student@workstation ~]$oc get vmiNo resources found in creating-accessing-vms namespace. [student@workstation ~]$oc get vmNo resources found in creating-accessing-vms namespace.