Launch templates
In this article:
Launch templates#
General information#
Launch templates specify instance configuration information and help reduce the number of steps and actions to create an instance. In particular, launch templates are used to describe the configuration of instances you want to launch in an Auto Scaling group.
To avoid setting the same parameters every time you launch a similar instance, you can save them in a launch template. For example, you can select the image from which an instance is typically created, specify the instance type, add user data, set network and other parameters. When launching an instance from a template, these parameters will be applied automatically.
For each launch template, you can create its versions with different instance parameters. When launching an instance from a template, you can choose any of its versions. If the version is not explicitly specified, the default version is used. When creating a template, the first version is created and set as default. Subsequently, you can set any of the template versions as default.
Versioning works well with automation tools. For example, you need to run a more powerful machine to accommodate an increased application load, and you create an instance using the default version of a launch template. You can create a new version of the launch template with the desired instance type and set it as default. The template ID will remain the same and no changes to the automation code itself will be required.
Note
You can create up to 50 launch templates in each project and up to 100 versions of each template. To increase the limits, leave a request on the support portal or write to support@k2.cloud.
Creating a launch template#
When creating a launch template, you can specify all or only a part of the parameters that will be used when creating an instance from this template. If required, the specified parameters can be changed when creating an instance.
The creation procedure for a launch template is similar to that for an instance, with a few exceptions. Below, only the main template creation steps and differences are described. To learn more about the selection and meaning of particular parameters, see the instance creation procedure description.
To create a launch template, go to the respective section and click Create.
Step 1. Select an image#
From the list of images, select the pre-built OS image you want to use to create the instance and click Select.
Note
To display backup-related images, enable Show recovery points.
Note
If the desired image is not among the available images, click Create new image. You will be automatically switched to Images subsection. Create here the desired image according to the instruction. You will have to start the procedure for creating a launch template all over again, so it is better to create the image in advance.
Step 2. Select an instance placement#
At this step, you need to select where in the cloud the instance will be placed.
Placement group.
Placement type — If the default value (
Shared server
) is selected, instances will be started on a shared computing node where instances of other users can also run. For parameters of the launch template for starting instances on a dedicated host, see the documentation for dedicated hosts.
Step 3. Select an instance type#
Select the instance type with the required vCPU count and RAM size from the list and click Select to proceed to the next step.
Step 4. Specify template and instance parameters#
At this step, specify the launch template name and (optionally) its version description.
Note
The template name can contain ASCII characters only, and its length cannot be less than 3 and more than 128 characters. Version description cannot contain more than 256 characters.
To set network parameters, specify the VPC where the corresponding network resources will be located. You must also select the type of network settings you want to configure: Security Groups or Advanced Network Configuration. This choice determines which network parameters can be configured in the launch template.
Note
VPC is not saved in the launch template explicitly: this parameter is only used to filter available network resources when creating the template.
If the Security Groups option is selected, you can specify up to 5 security groups. They will be assigned to the primary network interface when an instance is created from the template. If no security group is selected, then the default security group will be added to the launch template.
When RAM Monitoring checkbox is selected, RAM monitoring is enabled.
Note
RAM monitoring is only available for Linux instances. In addition to enabling monitoring, CloudWatch agent must be installed on them (for details, see).
If you select the Advanced network configuration option, you can specify the subnet the primary network interface will be attached to and additional network parameters in the next step. The specified network interface parameters are ignored when instances are to be created in the Auto Scaling group, so we recommend to use this option only when you plan to create individual instances from the template.
Note
Если в выбранной подсети включено автоматическое назначение Elastic IP-адресов, то при создании экземпляра в этой подсети основному сетевому интерфейсу будет автоматически назначен Elastic IP при наличии свободных выделенных адресов.
In addition, you can also specify:
SSH-key;
user data.
If you want instances created from a template to be automatically deleted upon shutdown, set the Delete on instance shutdown flag.
Then, you can proceed directly to viewing the selected instance configuration, which will be written to the template. To do this, click Overview and create. If you want to make configuration more specific by describing attached devices (for example, network interface parameters), click Next.
Step 5. Specify network interface parameters#
At this step, you can add the necessary network interfaces and set their parameters.
Note
This step is available only if the Advanced network configuration option was selected in the previous step.
You can select an existing or new network interface as the primary one. The primary interface is attached to the network that was selected in the previous step. For the new interface, you can specify:
description;
private IP;
security groups.
If you want the interface to be automatically deleted, along with the instance, check the Delete with instance checkbox. To assign an external IP address to the interface, check the Associate with existing Elastic IP checkbox. For details, read about network interface parameters.
Attention
If you select the existing network interface, then an error will occur when you try to create another instance from this launch template. The reason: the interface will already be used by the previously created instance. Specifying an existing interface in a launch template makes sense, for example, when only one instance is to be launched periodically from this template during business hours and deleted at the end of the business day.
To configure additional interfaces, click Add device. For each of them, you can specify a network to which it will be attached and set the same parameters as for the primary interface. However, you cannot assign Elastic IPs to additional network interfaces in the instance wizard. If necessary, this can be done manually later.
Once you have set the interface parameters, you can proceed to the template configuration overview or go to the next step. In the former case, click Overview and create; in the latter, click Next.
Step 6. Set parameters of the volumes to attach#
In this step, you can set parameters of the volumes that will be created together with the instance.
For each volume you want to attach, you can select:
volume snapshot from which it will be created;
volume size;
volume type;
IOPS;
throughput (if applicable for the selected volume type).
If you want the volume to be automatically deleted, along with the instance, check the Delete with instance checkbox. For details, read about volume parameters.
To add a volume, click Add volume and set its parameters.
Once you have set the volume parameters, you can proceed to the template configuration overview or go to the next step. In the former case, click Overview and create; in the latter, click Next.
Step 7. Add tags#
In this step, you can assign tags to the launch template, instances, and/or volumes. To assign the Name tag, click Add Name tag; to assign an arbitrary tag, click Add tag.
Set the tag key and value (for the Name tag, the key is already set). In addition to the template, you can select other resources (instances and/or volumes), which a tag is to be assigned to. To this end, select the appropriate checkboxes. For each tag, at least one checkbox must be selected. By default, a tag is assigned to a launch template only.
To specify additional tags, click Add tag. After setting the required tags, click Overview and Create.
Step 8. Review parameters#
In the Overview step, check the template configuration and click Create.
Using template versions#
Once created, a launch template cannot be modified. Instead, you can create a version of the template and change and/or add the parameters you need.
Template versions are numbered in the order they are created. Version 1 is that created along with the launch template.
You can set a default version and delete those you no longer need.
Create a launch template version#
To create a launch template version, go to the template page. To do this, in the Launch Templates subsection, find the desired template in the table and click its ID. In the Information tab, you can specify the version from which the next version will be created. The desired version can be found by its number and description in the version selector.
Note
We recommend that you always add a version description to facilitate further search. Otherwise, you will have to remember the number of the version that contains the desired instance configuration.
The launch template version wizard contains the same steps as the launch template wizard. To run it, click Create new version. It opens in the Parameters step. If you need to change the instance type or the image from which the instance will be created, then go back a step or two by clicking Back.
In any step, you can change any parameter values and set parameter values that were not previously specified. However, the values of the parameters you set earlier cannot be left blank.
Note
Tags can be assigned to a template, but not a version; therefore, in the Tags step, you can assign tags to instances or volumes only.
Change the default version#
The default version is used if no particular version is specified when creating an instance from a template. To set a default version:
go to the Information tab on the template page;
in the version selector, select the version you want to set as the default version;
click Set version as default.
Delete a launch template version#
Template versions are deleted permanently. A newly created version cannot be assigned the number of the deleted version. It will be assigned the next serial number. To delete a template version:
go to the Information tab on the template page;
in the version selector, select the version you want to delete;
click Delete version.
Attention
You cannot delete the default version. If a version you want to delete is the default one, set another default version first.
Launching an instance from a template#
Launch templates are used when creating instances within Auto Scaling groups. But you can also use launch templates to create individual instances with specific configuration.
Note
The cloud checks whether resources required to create an instance are available only when the launch template is used. If the resources specified in the launch template are unavailable, the instance creation will fail. For example, if the image specified in the template is no longer available, an error will occur when creating an instance.
Note
To create an instance from a launch template with a security group other than that from the default VPC, you must additionally specify SubnetID.
Go to Virtual machines Storage Launch templates and select the desired launch template in the table.
Click Create instance.
In the dialog window, select the launch template version or use the default one.
Specify the number of instances to be launched.
If necessary, change the instance type and the Name tag, as well as the resources which the Name tag is assigned to.
Once the parameters are set, click Overview and Launch and check the instance configuration.
Click Launch.
You can also create an instance on the template page in the Information tab or in the Instances section. In addition, instances can be launched from a template using an API method RunInstances. This method allows you to change any instance parameters, not only its type and Name tag.
Managing launch templates#
Assign tags to a launch template#
If you didn’t assign tags when creating a template, you can do it later. To do it:
Go to Virtual machines Storage Launch templates;
select the desired launch template in the table;
click Customize tags;
in the dialog window, set tag keys and values;
to confirm changes, click Apply.
Note
If you want new tags to be also assigned to instances and volumes created from the template, then create a new launch template version and select the appropriate checkboxes. To learn which tags are assigned to the created resources, go to the template page and then to the Resource tags tab.
Delete launch template#
A launch template you no longer need can be deleted. All template versions will be deleted along with the template. To delete a launch template:
Go to Virtual machines Storage Launch templates;
select the template you no longer need in the table;
Click Delete;
confirm deletion. Be careful: a deleted launch template cannot be restored.
Information about a launch template versions#
To view information about a launch template version, go to the respective section. Click the link with the ID in the launch template table to open the page of the selected resource. Here you will find details of the selected launch template version configuration. The launch template version can be selected in the version selector.
The Information tab contains the launch template version description and creation time, as well as configuration details of the instance that will be created, such as source image, instance type, placement group, and SSH key. In this tab, you can create a new template version, set the default version, delete the version you no longer need, and also create an instance from the launch template.
The Volumes tab displays parameters of the volumes that will be attached to the instance at its creation: the snapshot from which the volume will be created, its size, type, and the value of the option Delete with instance.
Data in the Network and Security tab depends on the option you selected when creating the launch template in the Parameters step: Security groups or Advanced network configuration. Selecting the former option displays information about the network groups that will be assigned to the primary interface of the instance: group ID and name, description, and Name tag. Selecting the latter option displays information about the network interfaces to be attached to the instance: device index, interface description, subnet where it is created, Elastic IP, Private IP, and the value of the Delete with instance option.
The Resource Tags tab contains keys and values of the assigned tags and specifies resources (instances and/or volumes) to which tags will be assigned.