An instance group is a collection of virtual machine (VM) instances that you can manage as a single entity.
Compute Engine offers two kinds of VM instance groups, managed and unmanaged:
- Managed instance groups (MIGs) let you operate apps on multiple identical VMs. You can make your workloads scalable and highly available by taking advantage of automated MIG services, including: autoscaling, autohealing, regional (multiple zone) deployment, and automatic updating.
- Unmanaged instance groups let you load balance across a fleet of VMs that you manage yourself.
In this article, we will discuss on Managed instance groups.
Managed instance groups
Managed instance groups offer the following advantages:
- Keeping VM instances running. If a VM in the group stops, crashes, or is deleted by an action other than an instance group management command (for example, an intentional scale in), the MIG automatically recreates that VM in accordance with the original instance’s specification (same VM name, same template) so that the VM can resume its work.
- Application-based autohealing. You can also set up an an application-based health check, which periodically verifies that your application responds as expected on each of the MIG’s instances. If an application is not responding on a VM, the autohealer automatically recreates that VM for you. Checking that an application responds is more precise than simply verifying that a VM is up and running.
- Regional (multiple zone) coverage. Regional MIGs let you spread app load across multiple zones. This replication protects against zonal failures. If that happens, your app can continue serving traffic from instances running in the remaining available zones in the same region.
- Load balancing. MIGs work with load balancing services to distribute traffic across all of the instances in the group.
- Scaling. When your apps require additional compute resources, autoscaled MIGs can automatically grow the number of instances in the group to meet demand. If demand drops, autoscaled MIGs can automatically shrink to reduce your costs.
- Automated updates. The MIG automatic updater lets you safely deploy new versions of software to instances in your MIG and supports a flexible range of rollout scenarios, such as rolling updates and canary updates. You can control the speed and scope of deployment as well as the level of disruption to your service.
Now let’s understand, how to create Managed instance groups and how to use it for autoscaling.
Create a Instance Template:
- Please go to the Navigation Menu → Compute Engine → Instance Templates.
2. Click on “Create Instance Template”:
3. The window would be similar to “Create VM instances” screen. Once you have provided the necessary details, click “Create”:
4. You will see that our instance template is ready.
Create a Managed Instance Group:
5. Now Go to “Compute Engine → Instance groups.
6. Select “Create Instance Groups”:
7. In the screen shown below, Provide below details:
- Instance Group name
- Location — Single zone or Multiple Zone
8. Provide Port name and Port numbers incase we are enabling HTTP Load Balancing.
9. Select “Instance Template”. Select “AutoScalling Mode” as Autoscale.
10. Mention Autoscaling metrics. In our case, we have mentioned it as CPU utilization: 80%. Mention Min Number / Max Number instances.
11. Create “Health Check” Monitoring. Once we have provided all the Details, Click “Create”.
12. You will see our Instance Group has been created:
13. Now go to Compute Engine → VM instances , You will see 2 Virtual Machine instances running.
14. Now try to shut down a Virtual Machine, you will not be able to do so and will be prompted this message:
You can’t stop the VM instance you’ve selected because it’s managed by a group. To stop this VM instance, first remove it from group my-vm-group
This Concludes our tutorial for Autoscaling with Managed Instance Groups.