Create a VM Template from an Existing Virtual Machine
This document outlines how to create a reusable virtual machine (VM) template from an existing VM for rapid deployment of new VMs.
TOC
PrerequisitesProcedureStep 1: Basic Configuration on the Virtual MachineStep 2: Create a VM SnapshotStep 3: Retrieve Disk Snapshot Resource NameStep 4: Create a DataSource ResourceLabel Parameters Explanation:Step 5: Create a New VM Using the TemplatePrerequisites
- A properly deployed and configured KubeVirt environment.
- Access to the Web Console and kubectl tool.
- A configured VM with necessary software already installed.
Procedure
Step 1: Basic Configuration on the Virtual Machine
Inside the VM, perform the following steps:
- Install cloud-init.
- Install the
qemu-guest-agent. - Install any required software.
Once installations are complete, run the following commands to clean cloud-init data and shut down the VM:
Step 2: Create a VM Snapshot
Using the KubeVirt Web Console:
- Navigate to Virtualization > Virtual Machines.
- Select the VM intended to serve as a template.
- Click Actions, select Create Snapshot, name your snapshot, and confirm.
Step 3: Retrieve Disk Snapshot Resource Name
Obtain the complete snapshot resource name using one of these methods:
-
Via Web Console:
- Navigate to Storage > Volume Snapshots.
- Find and record the full snapshot resource name under "Data Source."
-
Using kubectl:
Record the complete snapshot resource name from the output.
Step 4: Create a DataSource Resource
Create the following DataSource resource in the kube-public namespace, ensuring you replace placeholders with the actual snapshot name and namespace:
Label Parameters Explanation:
Important:
- Ensure the namespace is
kube-public. - These disk-related parameters can be modified during VM creation but providing defaults simplifies the process.
Step 5: Create a New VM Using the Template
- Access the KubeVirt Web Console, go to Container Platform > Virtualization > Virtual Machines.
- Click Create Virtual Machine.
- Under Image, select Image Instance as the Provision Method.
- Select your newly created DataSource from the dropdown.
- Configure any additional parameters as required and complete the VM creation process.
You have now successfully created and deployed new VMs using your VM template.