Provision a virtual machine on OpenShift Virtualization by using a QCow2 container disk image hosted on an OCI container registry.
If your OS image does not already contain the Red Hat Edge Manager agent enrollment configuration, inject it through cloud-init user data during provisioning.
Before you begin
- OpenShift Virtualization is installed on your OpenShift Container Platform cluster.
- You have built a QCow2 container disk image and pushed it to an OCI container registry.
- The
flightctl CLI is installed, and you are logged in to your Red Hat Edge Manager service instance.
- The
oc CLI is installed, you are logged in to your OpenShift Container Platform cluster instance, and you have changed to the project in which you want to create your virtual machine.
Procedure
-
Request a new Red Hat Edge Manager agent enrollment configuration and store it in a file called
config.yaml. Run the following command:
flightctl certificate request --signer=enrollment --expiration=365d --output=embedded > config.yaml
-
Create a cloud configuration user data file called
cloud-config.yaml that places the agent configuration in the correct location during the first boot. Run the following command:
cat <<EOF > cloud-config.yaml
#cloud-config
write_files:
- path: /etc/flightctl/config.yaml
content: $(cat config.yaml | base64 -w0)
encoding: b64
permissions: '0600'
EOF
-
Create a Kubernetes
Secret that contains the cloud configuration user data file:
oc create secret generic enrollment-secret --from-file=userdata=cloud-config.yaml
-
Create a file that contains the
VirtualMachine resource manifest. Replace <your_registry>/<your_repo>:<your_tag> with the location of your QCow2 container disk image. Run the following command:
cat <<'EOF' > my-bootc-vm.yaml
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
name: my-bootc-vm
spec:
runStrategy: RerunOnFailure
template:
spec:
domain:
cpu:
cores: 1
memory:
guest: 1024M
devices:
disks:
- name: containerdisk
disk:
bus: virtio
- name: cloudinitdisk
disk:
bus: virtio
volumes:
- name: containerdisk
containerDisk:
image: <your_registry>/<your_repo>:<your_tag>
- name: cloudinitdisk
cloudInitConfigDrive:
secretRef:
name: enrollment-secret
EOF
-
Apply the resource manifest to your cluster by running the following command:
oc apply -f my-bootc-vm.yaml
Results
- Verify that the virtual machine was created and is running: