- A Cloud Guru
Creating a Load-Balanced Managed Instance Group on Google Cloud Platform
In this hands-on lab, we are going to experience creating a managed instance group using an instance template, creating an HTTP load balancer to act as the instance group frontend, and then updating our instance group from a 'version 1' to 'version 2' website.
Table of Contents
Create Custom Images from Our Initial Machines
Upon logging into the Google Cloud Platform, navigate to
Compute Engineand stop the currently running instances. Utilize
Cloud Shellto quickly create two custom images using the following commands:
gcloud compute images create web-v1 --family=webserver --source-disk=web-1 --source-disk-zone=us-central1-a
gcloud compute images create web-v2 --family=webserver --source-disk=web-2 --source-disk-zone=us-central1-a
Once the images have created, verify they were created by navigating to the
Imagesmenu on the lefthand side.
Create an Instance Template for webv1
Instance Templateusing the custom image for
Instance Templateshould be of Machine Type e2-micro. Additionally, ensure the Firewall is configured to allow HTTP traffic.
Create a Managed Instance Group
Create a Managed Instance Group called web-group with the following parameters:
- Location: Single zone in us-central1
- Instance Template: instance-template-1
- Autoscaling: Minimum Number of Instances set to 3. Maximum number of instances set to 5
Additionally, create a Health Check that monitors TCP on port 80.
Create a Load Balancer
- Create an HTTP(S) Load Balancer that accepts connections from the internet.
- For the Frontend configruation, ensure the protocol is set to TCP on port 80.
- For the Backend, set the type to instance groups and select the web-group instance group.
- Apply the same Health Check created earlied to the backend.
View the Load Balanced Website
Once the Load Balancer has been provisioned, navigate to the Frontend tab and copy the IP address. Open this up in a new tab and observe the website loading is Version 1.
Update the Instance Group to the Version 2 Website
Create a new Instance Template using the webv2 custom image with the same parameters from the webv1 template. Once the template has been created, modify the Instance Group to use the new Instance Template and update the VMs. Make sure the Temporary additional instances and Maximum unavailable instances to 1.
After the change has started, observe the process in the console and begin refreshing the website and observe the change to version 2. You'll also notice the version 1 website is still showing up until all servers have been swapped to version 2.
Note: The whole process will take about 15 minutes.
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.