Creating Windows Images Based on ISO using KubeVirt
This document discusses a virtual machine solution based on the open-source component KubeVirt, using KubeVirt virtualization technology to create a Windows operating system image through an ISO image file. The ISO files are uploaded to the cluster via CDI DataVolume, eliminating the need to build and push container images to a registry.
Prerequisites
-
All components in the cluster are functioning correctly.
-
Please prepare the Windows image and the latest virtio-win-tools in advance.
-
The
kubectlcommand-line tool is installed and configured to access the cluster. -
A StorageClass that supports the
ReadWriteMany(RWX) access mode is available in the cluster. Live migration requires every PVC attached to the virtual machine to be shared, so all DataVolumes in this document use RWX. If you do not need live migration,ReadWriteOnce(RWO) also works.
Constraints and Limitations
-
When starting KubeVirt, the size of the custom image's filesystem will affect the speed of writing the image to the disk in PVC. If the filesystem is too large, it may result in extended creation times.
-
It is recommended to keep the Windows C drive below 100G to minimize the initial size. Subsequent expansion must be done manually after creation for Windows systems.
Procedure
Upload ISO Files to DataVolumes
Upload the Windows ISO and virtio-win ISO files directly to the cluster storage using the CDI upload mechanism.
Set up the CDI Upload Proxy
-
Set up port-forwarding to the CDI upload proxy. This port-forward session will be used for uploading both ISO files. The
cdi-uploadproxyService runs in the namespace the virtualization components are installed in, which iskubevirtby default.Note: Each upload needs its own authentication token, obtained from CDI with an
UploadTokenRequest. A token authorizes uploading to one specific PVC and is valid for 5 minutes, so the token is requested in each upload procedure below, immediately before the transfer starts, rather than once up front.
Upload the Windows ISO
-
Create an upload-type DataVolume for the Windows ISO by saving the following YAML to a file named
dv-win-iso.yaml. Adjust thestoragesize based on the actual ISO file size (Windows ISOs are typically 4–6 GB). -
Execute the following command to create the DataVolume.
-
Wait for the DataVolume to enter the
UploadReadyphase. -
Request an upload token for the
win-iso-dvPVC. The token is valid for 5 minutes, so run this immediately before the upload. -
Upload the Windows ISO file using curl. Replace the file path with the actual path to your ISO.
-
Verify that the DataVolume status changes to
Succeeded.
Upload the virtio-win ISO
-
Create an upload-type DataVolume for the virtio-win ISO by saving the following YAML to a file named
dv-virtio-iso.yaml. -
Execute the following command to create the DataVolume.
-
Wait for the DataVolume to enter the
UploadReadyphase. -
Request an upload token for the
virtio-iso-dvPVC. This is a separate token from the one used for the Windows ISO, because a token authorizes uploading to a single PVC. -
Upload the virtio-win ISO file using curl.
-
Verify that the DataVolume status changes to
Succeeded.Note: The
--insecureflag is used to skip self-signed certificate verification. In a production environment, configure proper certificates. Large file uploads may take a long time; ensure network stability.
Create Virtual Machine
-
Access the Container Platform.
-
In the left navigation bar, click on Virtualization > Virtual Machines.
-
Click on Create Virtual Machine.
-
Fill in the necessary parameters such as Name, Image, etc., in the form page. For detailed parameters and configuration, please refer to Create Virtual Machine.
-
Switch to YAML.
-
Replace the configuration under the spec.template.spec.domain.devices field with the following content. The USB tablet input device is required for correct mouse positioning in the VNC console (see kubevirt#2392, kubevirt#3474). Without it, the mouse pointer will be misaligned because VNC uses absolute coordinates while the default PS/2 mouse only supports relative coordinates.
-
Replace the spec.template.spec.volumes field with the following content. Both ISO files are referenced as DataVolumes instead of container images.
-
Add the following annotation under
spec.template.metadata.annotations. The primary interface of this virtual machine usesbridgebinding on the pod network, which KubeVirt refuses to live-migrate by default; this annotation declares that the underlying CNI can follow the migration and lifts that restriction. Kube-OVN, the default CNI of the platform, preserves the virtual machine IP address across a migration. Without this annotation, migration is rejected withInterfaceNotLiveMigratable.Note: KubeVirt only reports the first condition that blocks live migration, and the interface check runs before the disk check. If any PVC still uses
ReadWriteOnce, the virtual machine remains non-migratable after adding this annotation, and the reason reported changes toDisksNotLiveMigratable. Both the annotation and RWX access modes are required. -
Check the YAML file. The complete YAML after finishing the configuration is as follows.
-
Click Create.
-
Click Actions > VNC Login.
-
When the prompt press any key boot from CD or DVD appears, press any key to enter the Windows installation program; if you do not see the prompt, click on Send Remote Command in the top left of the page, then select Ctrl-Alt-Delete from the dropdown menu to restart the server.
Note: If a message appears at the top of the virtual machine details page stating The current virtual machine has configuration changes that require a restart to take effect, please restart, this message can be ignored; no restart is necessary.
Install Windows Operating System
-
Follow the installation instructions to install the system after entering the installation page.
Note: During the partition selection step, the bus must be sata for the disk to be correctly recognized. Therefore, you need to select each partition in turn and click Delete to remove all partitions, allowing the system to handle it automatically.
-
After configuring the administrator account password, click Send Remote Command in the top left of the page, then select Ctrl-Alt-Delete from the dropdown menu.
-
When prompted The Ctrl+Alt+Delete combination will restart the server, confirm to restart, click OK.
-
Enter the password to access the Windows system desktop; at this point, the Windows operating system installation is complete.
Install virtio-win-tools
This tool primarily contains the necessary drivers.
-
Open File Explorer.
-
Double-click CD Drive(E:) virtio-win-<version>, run the virtio-win-guest-tools directory to enter the installation page, and follow the installation instructions. The <version> part should be based on the actual situation.
-
After the installation is complete, power off the Windows system.
Export Custom Windows Image
Please refer to Export Virtual Machine Image for the specific operation.
Use Windows Image
-
Access the Container Platform.
-
In the left navigation bar, click on Virtualization > Virtual Machines.
-
Click on Create Virtual Machine.
-
Fill in the necessary parameters on the form page. For the image, select the exported Windows image. For detailed parameters and configuration, please refer to Create Virtual Machine.
-
(Optional) If using a newer operating system, such as Windows 11, enable features like clock, UEFI, TPM, etc. Switch to YAML and replace the original YAML file with the following YAML file.
-
Click Create.
Add Internal Route
By configuring a NodePort type internal route, expose the port for remote desktop connections.
-
Access the Container Platform.
-
In the left navigation bar, click on Virtualization > Virtual Machines.
-
Click on the virtual machine name created with the Windows image in the list to enter the details page.
-
Click on the Add icon next to Internal Route in the Login Information area.
-
Configure parameters according to the following instructions.
-
Click OK to return to the details page.
-
Click on the Internal Route link in the Login Information area.
-
Save the Virtual IP information in the basic information area and the Host Port information in the port area.
Remote Access
This document discusses using the Windows operating system for remote connection as an example. Other operating systems can use software that supports the RDP protocol for connection.
-
Open Remote Desktop Connection.
-
Enter the saved Virtual IP and Host Port from the Add Internal Route step, formatted as Virtual IP:Host Port, for example: 192.1.1.1:3389 .
-
Click Connect.