RHEL VM with Apache httpd¶
Deploy a Red Hat Enterprise Linux 9 virtual machine on OpenShift Virtualization, install Apache httpd, and serve a webpage accessible via an OpenShift Route.
Prerequisites¶
- OpenShift Virtualization installed and healthy
- A default virtualization StorageClass with RWX support
- RHEL 9 boot source available (
oc get datasources -n openshift-virtualization-os-images | grep rhel9) ocandvirtctlinstalled locally
Create the Project¶
Create the Virtual Machine¶
Choose one of the two options below.
Apply a VirtualMachine manifest with cloud-init that sets credentials, installs httpd, and creates a landing page:
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
name: rhel-httpd
namespace: rhel-httpd
spec:
runStrategy: Always
template:
spec:
domain:
resources:
requests:
memory: 2Gi
devices:
disks:
- name: rootdisk
disk:
bus: virtio
- name: cloudinit
disk:
bus: virtio
volumes:
- name: rootdisk
dataVolume:
name: rhel-httpd-rootdisk
- name: cloudinit
cloudInitNoCloud:
userData: |
#cloud-config
user: cloud-user
password: Pass123!
chpasswd:
expire: false
packages:
- httpd
runcmd:
- systemctl enable httpd --now
- echo '<html><body><h1>Hello from OpenShift Virtualization</h1><p>Served by Apache httpd on RHEL 9</p></body></html>' > /var/www/html/index.html
- restorecon -Rv /var/www/html
dataVolumeTemplates:
- metadata:
name: rhel-httpd-rootdisk
spec:
sourceRef:
kind: DataSource
name: rhel9
namespace: openshift-virtualization-os-images
storage:
accessModes:
- ReadWriteMany
volumeMode: Block
resources:
requests:
storage: 30Gi
Create the VM using virtctl with cloud-init credentials. This does not install httpd automatically — install and start it manually after the VM boots (see step 3).
- Wait for the VM to reach Running:
Verify httpd is Running Inside the VM¶
- Once the VM is running, open a console session:
- Log in as
cloud-user/Pass123!. If you used Option A, verify httpd:
If you used Option B, install and start httpd first:
sudo dnf install -y httpd
sudo systemctl enable httpd --now
echo '<html><body><h1>Hello from OpenShift Virtualization</h1><p>Served by Apache httpd on RHEL 9</p></body></html>' | sudo tee /var/www/html/index.html
sudo restorecon -Rv /var/www/html
curl localhost
You should see the HTML page content. Press Ctrl+] to exit the console.
Expose httpd via a Service and Route¶
- Create a Service targeting port 80 on the VM:
apiVersion: v1
kind: Service
metadata:
name: rhel-httpd
namespace: rhel-httpd
spec:
selector:
vm.kubevirt.io/name: rhel-httpd
ports:
- protocol: TCP
port: 80
targetPort: 80
- Create a Route to expose the service externally:
- Verify the page is accessible:
You should see:
<html><body><h1>Hello from OpenShift Virtualization</h1><p>Served by Apache httpd on RHEL 9</p></body></html>