Creating a Load-Balanced Managed Instance Group on Google Cloud Platform

1 hour
  • 6 Learning Objectives

About this Hands-on Lab

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.

**Note:** Use **e2-micro** instances instead of **f1-micro**.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create Custom Images from Our Initial Machines
  1. Stop the currently running Compute Engine instances.
  2. Open Cloud Shell from the top right-hand side corner.
  3. Run the following commands in Cloud Shell to quickly create two custom images named web-v1 and web-v2:
    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
  4. Verify new images are in the Images menu in the web console on the left-hand side.
Create a Managed Instance Template
  1. From the Compute Engine menu, select Instance templates.
  2. Click CREATE INSTANCE TEMPLATE.
  3. Name the instance template "instance-template-1" (most likely the default name).
  4. Change the Machine type to e2-micro.
  5. Under Boot disk, click Change > Custom images and choose the web-v1 image that you created in the previous step.
  6. Click Select from the bottom.
  7. Under Firewall, select Allow HTTP traffic.
  8. Click Create.
Create a Managed Instance Group
  1. From the Compute Engine menu, click Instance groups.
  2. Click CREATE INSTANCE GROUP.
  3. Name the group "web-group".
  4. Under Location, choose Single zone. Choose us-east1 for the region or a zone in us-east1.
  5. Under Instance template, choose instance-template-1.
  6. Under Autoscaling, set the Minimum number of instances to 3 and the Maximum number of instances to 5.
  7. From the Health check dropdown, select Create a health check.
  8. Name the health check "health-check-1".
  9. Leave all the other settings at their defaults. Make sure that the Protocol is set to TCP with a Port value of 80.
  10. Click Save and continue.
  11. Back in the instance group menu, click Create to create the group.
Create a Load Balancer
  1. From the top left menu, scroll down to Networking, click on Network services, and then click Load balancing.
  2. Click Create load balancer.
  3. Under HTTP(S) Load Balancing, click START CONFIGURATION.
  4. Click From Internet to my VMs or serverless servicesandGlobal HTTP(S) Load Balancer (classic) then click CONTINUE.
  5. Name the load balancer "lb-1".
  6. Click Backend configuration.
  7. Click the Backend services & backend buckets menu and select CREATE A BACKEND SERVICE.
  8. Name the backend service "backend-1".
  9. Under Backend type, make sure that Instance groups is selected (should be the default).
  10. Under the New backend section, from the Instance group dropdown, select the web-group instance group.
  11. Set the Port numbers to 80.
  12. From the Health check dropdown menu, select health-check-1.
  13. Click CREATE.
  14. In the New HTTP(S) load balancer menu on the left, click Frontend configuration.
  15. Name the frontend "frontend-1".
  16. Leave all the other settings at their defaults. Make sure that the Protocol is set to HTTP with a Port value of 80.
  17. Click DONE.
  18. In the New HTTP(S) load balancer menu on the left, click Review and finalize.
  19. If everything looks good, click CREATE.
View the Load Balanced Website
  1. On the Load balancing page, click REFRESH.
  2. Click on Frontends in the top menu.
  3. You should see the IP address for the frontend. Open a new tab and copy/paste the address into the address bar. If the site can’t be displayed, give the load balancer a few more minutes to initialize.
  4. Once the website loads, verify that it displays VERSION 1.
Update the Instance Group to the Version 2 Website
  1. Back in the GCP Console, from the top left menu, click on Compute Engine and then select Instance templates.
  2. Create a new instance template using the same process as the first template.
  3. Name the instance template "instance-template-2".
  4. Set the Machine type to e2-micro.
  5. Change the Boot disk to the web-v2 custom image.
  6. Under Firewall, select Allow HTTP traffic.
  7. Click Create.
  8. In the Compute Engine menu, click Instance groups.
  9. Click on web-group.
  10. Click UPDATE VMS in the top menu.
  11. Under Template, select instance-template-2 from the dropdown menu.
  12. Leave all the other settings at their defaults. Make sure that the Temporary additonal instances (maximum surge) and Maximum unavailable instances options are set to 1 instance.
  13. Click UPDATE VMS.
  14. After about 13 minutes, in the browser tab where you access the load balancer via it’s IP address, refresh the page until only the website displays VERSION 2.

Additional Resources

We recommend running the lab in an incognito mode browser (or equivalent private browsing mode) to avoid cached login issues. The switchover from template 1 to template 2 takes about 13 minues. The service advertisments at the top of someof the pages can be optionally dismissed by clicking the 'X'.

What are Hands-on Labs

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.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?