Skip to content

Example Virtual Machines

This guide walks through deploying an example Red Hat Enterprise Linux 9 virtual machine on OpenShift Virtualization. Use it as a smoke test after OpenShift Virtualization is installed, or as a starting point before failover and backup/restore exercises.

Prerequisites

  • OpenShift Virtualization installed and the HyperConverged instance is healthy
  • A default virtualization StorageClass (storageclass.kubevirt.io/is-default-virt-class: "true")
  • Boot sources available in the cluster
  • oc and optionally virtctl installed locally

Verify boot sources before creating a VM:

oc get datasources -n openshift-virtualization-os-images

Templates that show Source available in the console are ready to use. If RHEL sources are missing, wait for the DataImportCron jobs to finish or confirm the cluster can pull from the Red Hat registry.

Create a Project

oc new-project example-vms

Deploy from the Web Console

  1. Go to VirtualizationVirtualMachines → ensure you are in the example-vms project → click CreateFrom template
  2. Select Red Hat Enterprise Linux 9 (choose a tile with Source available)
  3. Name the VM example-rhel9
  4. Click Customize VirtualMachine

Optional: Set Login Credentials

  1. Open the Scripts tab
  2. Under Cloud-init, set a password for the guest user (or paste an SSH public key). Example cloud-init:

    #cloud-config
    user: cloud-user
    password: Pass123!
    chpasswd:
      expire: false
    

Note

RHEL cloud images do not ship with a usable default password. Set a password or SSH key before first boot, or you will not be able to log in from the console.

Optional: Confirm Disk and Run Strategy

  1. Open the Disks tab and confirm the root disk uses your virtualization StorageClass
  2. Prefer ReadWriteMany (RWX) if you plan to live-migrate or test failover later
  3. On the Overview tab, leave Start this VirtualMachine after creation selected so the VM boots immediately (runStrategy: Always)

Create and Wait

  1. Click Create VirtualMachine
  2. Wait until the VM status shows Running

    Provisioning clones the boot source PVC first. On a cold cluster this can take several minutes.

Verify the Virtual Machine

From the CLI:

oc get vm,vmi example-rhel9 -n example-vms -o wide

The VirtualMachine should be Ready, and the VirtualMachineInstance should show Running with a node assigned.

Check guest interfaces and IP (requires the QEMU guest agent, included on RHEL templates):

oc get vmi example-rhel9 -n example-vms -o jsonpath='{.status.interfaces}' | jq

Watch creation events if the VM stays in provisioning:

oc get events -n example-vms --field-selector involvedObject.name=example-rhel9 --sort-by='.lastTimestamp'

Access the Console

  1. Go to VirtualizationVirtualMachines → click example-rhel9
  2. Open the Console tab
  3. Log in as cloud-user with the password (or SSH key) you set in cloud-init
  4. Confirm the guest is healthy:

    cat /etc/redhat-release
    ip addr
    

Deploy from the CLI (Optional)

You can create the same style of VM with virtctl using a cluster DataSource:

virtctl create vm \
  --name example-rhel9 \
  --instancetype u1.medium \
  --preference rhel.9 \
  --volume-import type:ds,src:openshift-virtualization-os-images/rhel9 \
  --cloud-init-user cloud-user \
  --cloud-init-password Pass123! \
  | oc apply -n example-vms -f -

Start the VM if it was created stopped:

virtctl start example-rhel9 -n example-vms

Watch until it is running:

oc get vmi example-rhel9 -n example-vms -w

Tip

Run virtctl create vm --help for additional options such as CPU/memory overrides, extra disks, and cloud-init SSH keys.

Cleanup

oc delete vm example-rhel9 -n example-vms
oc delete project example-vms

When deleting from the web console, confirm that associated disks (PVCs) are removed if you do not need to reuse them.

Next Steps