Define the attributes of a product template based on a predefined image to create a medium-sized VM that contains a web server.
Outcomes
Create a VM by using a product template.
Define the attributes of a product template. Define the boot source as a predefined image and define the size, the workload type, and the custom access credentials.
Access the VM to confirm that the web server is up and running.
Delete the VM.
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-intro namespace and exercise resources.
The OpenShift Virtualization operator auto-imports default boot images for Red Hat provided templates.
To enable custom boot sources for these templates, the lab command ensures that the enableCommonBootImageImport feature is disabled at the start of the exercise.
[student@workstation ~]$ lab start template-intro
Instructions
As the admin user, navigate to the Red Hat OpenShift web console, and confirm that the web-server-image data volume is available in the vm-images namespace.
From the command line, log in to your Red Hat OpenShift cluster as the admin user with redhatocp as the password.
[student@workstation ~]$oc login -u admin -p redhatocp \https://api.ocp4.example.com:6443Login Successful ...output omitted...
Confirm that the web-server-image data volume is accessible in the vm-images namespace, and that the corresponding PVC has a 10 GiB capacity and the Bound status.
[student@workstation ~]$oc get datavolume -n vm-imagesNAME PHASE PROGRESS RESTARTS AGE web-server-image Succeeded 100.0% 69s [student@workstation ~]$oc get pvc -n vm-imagesNAME STATUS VOLUME CAPACITY ACCESS MODES ... web-server-image Bound pvc-e32c...89b5 10Gi RWX ...
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 when prompted.
Use the Red Hat Enterprise Linux 8.0+ VM template to create the helloworld VM in the template-intro namespace.
Define the boot source as the web-server-image PVC in the vm-images project.
From the web console left panel, navigate to → .
Select the template-intro project and use the search bar to locate and click the Red Hat Enterprise Linux 8.0+ VM template.
Click .
![]() |
Complete the form according to the following table:
| Parameters | Value |
|---|---|
| Name | helloworld |
| Disk source | PVC (clone PVC) |
| PVC project | vm-images |
| PVC name | web-server-image |
![]() |
Leave the other form fields with their default values and click .
Navigate to the tab.
Click .
Define developer as the user and developer as the password in the form, and click .
![]() |
Navigate to the tab, and confirm that the network interface type is Masquerade.
Confirm that the attached disks include cloudinitdisk and rootdisk.
![]() |
Confirm that Server is selected for .
Review the settings of your VM and click .
![]() |
Observe the status of the helloworld VM and its resources by using the command line.
Use the oc get command to observe the progress of the VM's data volume.
[student@workstation ~]$oc get datavolume -n template-introNAME PHASE PROGRESS RESTARTS AGE helloworld CloneInProgress 70.0% 25s [student@workstation ~]$oc get datavolume -n template-introNAME PHASE PROGRESS RESTARTS AGE helloworld Succeeded 100.0% 45s
Use the oc get command to observe the status of the helloworld VM.
[student@workstation ~]$ oc get vm -n template-intro
NAME AGE STATUS READY
helloworld 2m Running TrueConnect to the console of the helloworld VM by using the virtctl console command and log in as the developer user with developer as the password, which you defined in a previous step.
From the command line, connect to the console of the helloworld VM by using the virtctl console command.
Press Enter to open the login prompt.
[student@workstation ~]$ virtctl console helloworld -n template-intro
Successfully connected to helloworld console. The escape sequence is ^]
Red Hat Enterprise Linux 8.5 (Ootpa)
Kernel 4.18.0-348.el8.x86_64 on an x86_64
Activate the web console with: systemctl enable --now cockpit.socket
helloworld login:Log in as the developer user with developer as the password.
hellworld login:developerPassword:developer[developer@helloworld ~]$
Use the systemctl status httpd command to confirm that the Apache httpd service is loaded and running.
Confirm that the Apache httpd service is loaded and running.
Press q to exit the status log.
[developer@helloworld ~]$ systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor prese>
Active: active (running) since Mon 2024-03-11 15:14:33 EDT; 5min ago
Docs: man:httpd.service(8)
Main PID: 947 (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.
[developer@helloworld ~]$ curl localhost
<!DOCTYPE html>
<html>
<head>
<title>Hello, World!</title>
</head>
<body>
<p>Hello, World! Welcome to Red Hat Training.</p>
</body>
</html>Shut down and delete the helloworld VM.
Use the sudo systemctl poweroff command to shut down the helloworld VM.
[developer@helloworld ~]$ sudo systemctl poweroff
...output omitted...
[ 2172.699653] reboot: Power down
You were disconnected from the console. This has one of the following reasons:
...output omitted...Delete the helloworld VM with the oc command.
[student@workstation ~]$ oc delete vm helloworld -n template-intro
virtualmachine.kubevirt.io "helloworld" deleted