In this tutorial you will learn to create and configure Google Cloud Managed Instance Group with practical examples and Hands on demo.
what is managed instance group in gcp
Managed instance Group is an identical set up of virtual machines created using instance templates. Virtual machine configuration including machine family, machine type, software and image configuration and any other advance configuration is specified in Instance template and this template is used to set up identical set of virtual machines as google cloud managed instance group (MIG).
You can learn more about Instance templates here Create GCP Instance Template In 2 Minutes – Google Cloud Tutorials
Features of Google Cloud Managed Instance Group
- Maintain certain number of instances:Managed Instance Group can be configured to use minimum number of instances and if any of the instance fails MIG launches another instance in the group.
- Detect Application failures using health checks – Health checks can be configured at application level and if the health check fails on an instance that instance would be replaced with new healthy instance maintaining self-healing.
- MIG also supports (Auto Scaling) increase and decrease of virtual machines based on load. Load balancer is added to distribute load across different virtual machines in MIG. For higher availability Regional managed instance groups is created (create multiple instances in different zones).
- Release new versions of applications without any downtime using Rolling Updates and Canary Deployment.
- Rolling Updates – Release new version step by step (gradually). Update a percentage of instances to new version at a time.
- Canary Deployment – Test new version with a group of instances before releasing it across all instances.
Google Cloud Create Managed Instance Group
The first step to create a MIG is to create an Instance template.
Instance template can be used to specify below list of configurations for virtual machines along with other metadata.
- Machine Type
- Machine Family
- Firewalls Rules
- Startup Script
- Network, subnetwork and disk configuration.
- OS Image and other software configuration.
This is hands on tutorial, and you can follow along. Google cloud offers Google cloud free trial account with free credits worth 400 $ to learn and explore Google Cloud Platform. For more details on how to step up your free trial account refer Google Cloud Free Credits – Google Cloud Tutorials.
It is recommended to create a new GCP project for create machine image gcp demo. At the end of the demo, we will delete this project. This will ensure that all cloud resources created as a part of demo are deleted and there are no recurring charges.
Enter https://console.cloud.google.com/ in your browser and log in with Gmail account.
Search “Compute Engine” in google cloud search box.
In left navigation under instance templates click on create Instance Template.
In this article we will create instance template with default configuration for machine family, machine type and advance configuration. If you are interested to learn more about advance configuration options refer Create GCP Instance Template In 2 Minutes – Google Cloud Tutorials.
Review Instance template and click on create.
In left navigation under instance groups click on create Instance group.
Google cloud supports 3 types of instance groups.
Managed instance group stateless is used to host workloads of type web applications,API.
Managed instance group stateful is used to host workloads of type Databases. In this case data needs to be persisted before an instance is shutdown.
Google Cloud also supports grouping of virtual machines with different configuration. This is called unmanaged instance group. This is not used very often and should be limited to specific use case.
In this tutorial we will use manage instance group stateless.
Enter instance group group and description.
Select instance template created in above step 1.
If you need higher availability for your instance group select multiple zone option.In this case virtual machines are created in across multiple zones in same region for higher availability.
Select Target distribution shape.
In this demo we are selecting Even distribution shape and checked checkbox for Allow instance redistribution.
MIG creates and deletes virtual machines to maintain same number of VM’s across different zones. In even distribution the number of virtual machines in any zones does not differ by more than 1. This is default configuration. This is also recommended option for highly available workloads.
In balanced mode MIG prioritizes creation of virtual machines in zones which has available resources and distributes the virtual machines across multiple zones for high availability. It is recommended option for background jobs processing.
In ANY mode MIG creates virtual machine in zones with unused resources. It is recommended option for batch jobs and workloads which requires less availability.
ANY SINGLE ZONE mode MIG creates all virtual machines in any one zone within region.
Proactive instance redistribution is ON by default for MIG. You can set this to OFF when creating a new MIG or edit it for existing MIG.
Turning off proactive instance redistribution is useful if you need to Protect VMs with stateful workloads from unwanted automatic deletion due to proactive redistribution.
MIG supports multiple auto scaling modes.
If this is set to OFF auto scaling will not be performed by MIG.
In scale out mode MIG will only add instances to group with increase in traffic. It will not remove virtual machines even when traffic surge is low.
As a part of this demo, we are selecting auto scaling mode with add and remove instances.
Configure minimum and maximum number instances in MIG.
Google cloud supports multiple auto scaling signals.
Default is CPU utilization metrics.
Along with this it also supports Http load balacing,Cloud PUB SUB and cloud monitoring metrics.
Predictive auto scaling is new feature added by google cloud platform. In this option google cloud will Analyse historic traffic trends to increase or decrease virtual machines in MIG.
As a part of this demo, we will use CPU utilization metrics with 60 % utilization.
Whenever the traffic on the workload increases and CPU Utilization crosses 60% new virtual machine would be added to be MIG.
When the traffic is less virtual machines are automatically removed from MIG.
Google cloud also supports scheduled auto scaling using Auto scaling schedules.
If you run your workload on MIG you can use this option to auto scale ahead of time based on workload patterns.
initialization or cool down period is the time auto scaler must wait before scaling in.During the VM launch time CPU utilization might be high. This time will be omitted for auto scaling decisions.
If you expect load spikes to follow on your workload after it has reduced, you can configure scale in feature. You can limit the scale in rate of auto scaler to prevent auto scaling and reduce number of virtual machines beyond the specified. limit.
How to configure health check for Google Cloud Managed Instance Group
Google Cloud Managed Instance Group supports auto healing using health checks.
To configure a new health check in auto healing tab, click on create new health checkup.
Health check is performed at regular intervals using http request and you can also log health check logs in cloud logging.
- Check Interval: Time intervals to perform health check.
- Healthy threshold: How many consecutive success requests must happen to mark VM instance as healthy.
- UnHealthy threshold: How many consecutive failure requests must happen to mark VM instance as healthy.
- Timeout: Initial timeout period.
Review configuration and click on create.
A new MIG will be created and visible under Instance groups tab.
To learn more about stateful configuration for manage instance group refer Stateful managed instance groups | Compute Engine Documentation | Google Cloud.
At the end of demo remember to delete GCP project. If you are using existing GCP project delete MIG,virtual machines to prevent recurring charges from google cloud.
What is a managed instance group in GCP?
Managed instance Group is an identical set up of virtual machines created using instance templates. Virtual machine configuration including machine family, machine type, software and image configuration and any other advance configuration is specified in Instance template and this template is used to set up identical set of virtual machines as google cloud managed instance group (MIG).
What is the difference between managed and unmanaged instance group in Google Cloud?
In managed instance group all virtual machines are identical in terms of hardware and software configuration.
Unmanage instance group allows you to create virtual machines with different hardware and software configuration.
How do I create a managed instance group in Google Cloud?
Refer step 2 of this article to for step-by-step tutorial to create a managed instance group in Google Cloud.
How do I update managed instance groups in GCP?
MIG can be updated to new instance template using rolling update (gradual update of instance group to new instance template) and canary deployment or rolling restart/replace (Gradual restart and replace of all instances in a group)