How to Create and Deploy Virtual Machines with Templates in RedHat Virtualization
Rapid Deployment using templates
A template is a copy of a preconfigured virtual machine, used to simplify the subsequent, repeated creation of similar virtual machines. Templates capture the installed software, software configuration, and hardware configuration of the original virtual machine. When administrators need to deploy multiple (mostly) identical machines, it can be beneficial to use templates instead of doing multiple installations.
A template can be seen as a bit-for-bit copy of the original disk image and bears many resemblances to imaging a machine with tools like Clonezilla or Ghost. Just like an automated installation such as Kickstart, this helps maintain consistency across machines, making management and troubleshooting easier.
When working with virtual machines, basing machines on a template can also help reduce memory usage. Since machines based on the same template will be very similar, Kernel Same-page Merging (KSM) has a higher chance of finding duplicate memory pages on those machines that can be merged in physical memory.
NOTEOne of the challenges involved in using templates is making sure that no identifying information, such as references to MAC addresses or SSL certificates, are left behind since these may cause issues when multiple machines are deployed from the same template. This process is called sealing the image.
CREATING A TEMPLATE FROM A VIRTUAL MACHINE
Consider the following procedure outlining the steps necessary to create a template from an existing virtual machine:
1. Install a fresh virtual machine to be the baseline for the template.
2. Seal the image. This means that all information unique to the original virtual machine needs to be removed. This includes hardware information specific to the original virtual machine, such as MAC addresses; unique system configurations, such as the host name and static IP addresses; and possibly logs and other data.
3. Shut down the sealed virtual machine.
4. Create a template from the virtual machine using the Administration Portal.
5. Test the template by creating another virtual machine based on the new template.
NOTE:For Linux virtual machines, Red Hat Virtualization can use virt-sysprep to seal the image as it creates the template. Virtual machines running other operating systems need to be sealed before creating the template.
To create a template, administrators need to select the Virtual Machines tab, right-click the virtual machine they want to use for the template, then select Make Template from the menu. This brings up a dialog like the one shown as follows.
The following list describes the settings for the New Template window:
- Alias: An alias for the virtual machine disk used by the template. By default, the alias is set to the same value as that of the source virtual machine.
- Virtual Size: The current actual size of the virtual disk used by the template. This value cannot be edited, and is provided for reference only.
- Format: The format of the disks that the template should use. A QCOW2 format always implies that a disk is thin provisioned. The RAW format in file storage implies thin provisioned, while RAW on block storage implies preallocated virtual disks.
- Target: The storage domain on which the virtual disk used by the template is stored. By default, the storage domain is set to the same value as that of the source virtual machine. Any storage domain in the cluster can be selected.
This procedure describes the steps needed to create a sealed template from an existing Linux virtual machine:
- From the list of available virtual machines, select the appropriate virtual machine.
- Make sure that the virtual machine is powered down.
- With the virtual machine selected, click the Make Template button.
- Specify a Name, Description, and Comment for the template.
- Select the appropriate cluster for the template.
- Optionally, select a CPU Profile for the template, if any are available.
- Select the disk format, the storage domain, and the disk profile. By default, they are the same as those of the source virtual machine.
- To make this template public, select the Allow all users access to this Template check box.
- Select the Seal Template check box to automatically run the commands to seal a Linux-based template.
- Click the OK button to create the template.
While the template is being created, the virtual machine status displays an Image Locked status.The process of creating the template may take a long time, depending on the size and number of the virtual disks, and the underlying storage hardware. When finished, the template is added to the Templates tab.
NOTE: Non-Linux virtual machines must be manually sealed and shut down prior to using them to create the template. The procedure to do this varies depending on the operating system. For example, Microsoft Windows systems usually use Sysprep to seal images for use in templates. Red Hat Virtualization provides some files to assist you with this process.
Using a template to create a new virtual machine
Once a template has been created from a virtual machine, administrators can create new virtual machines using that template.
To create a new virtual machine from an existing template:
- Log in to the Administration Portal and navigate to the Virtual Machines tab. Click the New VM button to bring up the New Virtual Machine window.
- In this window, enter a Name and Description for your new virtual machine. In the Template drop-down menu, select the appropriate template for the virtual machine.
- With the New Virtual Machine window still open, make sure that you can see the advanced options. Click on Show Advanced Options if they’re not displayed. Navigate to the Resource Allocation tab. In that tab, select how to provision the virtual disks for the new server. If Provisioning is set to Thin, an overlay is used on top of the original template. If Provisioning is set to Clone, the original template is cloned and the Format option to select (per disk) a Raw or QCOW2 image becomes available.
- Click OK to create the virtual machine. Wait for its Status to go from Image Locked to Down before proceeding.
- Start the new virtual machine by right-clicking it in the Virtual Machines tab and selecting Run from the context menu.
- Open a console to the new virtual machine by right-clicking it and selecting Console from the context menu.