Introduction
In this article, we would try to understand more about VM Instance template and start-up scripts. We would also see how we can spin up multiple VM instances quickly using the instance template mechanism.
In this article, we will cover the following topics:
- Start-up script
- VM Instance template
- Creating multiple VMs using an instance template
Prerequisites
- Google free tier or paid account.
- Basic knowledge of using Google cloud services and understanding of Virtual Machines in general.
- At least one VM instance was created in the Google Cloud platform.
Step 1. Start up Script
The process of installing OS updates when the VM Starts is called bootstrapping.
This can be achieved using start-up script.
We create a new VM instance and configure the installation of the Apache server using start-up scripts.
In this article, we would not cover step-by-step VM creation since it was already covered in the previous 2 articles.
Follow the steps from the above article and kindly copy and paste the below scripts in the automation section. This script will install the apache server when the VM machine is launched.
#!/bin/bash
apt update
apt -y install apache2
Wait for some time while VM is getting created and the initial software installation process is in progress.
Since there are start-up scripts this VM Instance creation would take more time.
Click on the external IP Address and Apache open page would be displayed.
Note: If you are not able to access your VM, check if you have allowed http/https traffic in the firewall rule configuration.
Step 2. VM Instance templates
Search for instance templates or under instance template click on Create Instance Template
Specify a valid name for your template.
Configure the template with the same configuration and start-up script as mentioned in step 1
Click on create and wait while the template has been created.
Once the template is ready it is visible under Instance templates.
Step 3. Creating VMs using instance templates
Under VM Creation select the option "New VM from template" as mentioned below and select your instance template.
In the second step customize the VM instance if required and click on create.
Click on the external IP address of the new VM Instance and you would see the homepage of the Apache server.
Using this approach, we can configure multiple VM instances with the same configuration.
This would reduce the time required to configure individual VM machines.
We can very quickly spin up multiple VM machines with the same configuration using this approach.
Note: Remember to delete or free all unused cloud resources which are not in use. This would help to Save GCP Credits.
Summary
In this article, we have learned how to work with instance template and start-up scripts
In the upcoming articles, we would see how to improve the launch time of VM creation using custom images in GCP.
Thanks a lot for reading. I hope you liked this article. Please share your valuable suggestions and feedback. Write in the comment box in case you have any questions. Have a good day!