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 web console on the left-hand side.
Create Managed Instance Template
  1. From the Compute Engine menu, select Instance templates.
  2. Name the template instance-template-1 (most likely the default name).
  3. Change the machine type to e2-micro.
  4. Under Boot disk, click Change > Custom images > choose the web-v1 image that we created in the previous step.
  5. Click Select from the bottom.
  6. Under Firewall, select Allow HTTP traffic.
  7. Click Create.
Create 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. We may choose whichever region or zone is closest.
  5. Leave the Group type as Managed instance group.
  6. Under Instance template, choose instance-template-1.
  7. Under Autoscaling policy, set minimum number of instances to 3, and maximum number of instances to 5
  8. Select the dropdown menu under Health check, and then click Create a health check.
  9. Name our health check health-check-1.
  10. We can leave all other settings at their defaults. Make sure that the Protocol is set to TCP with a Port value of 80.
  11. Click Save and continue.
  12. Back in the instance group menu, click Create to create our group.
Create a Load Balancer
  1. From the top left menu, scroll down to Network services, and then click Load balancing.
  2. Click Create load balancer.
  3. Under HTTP(S) Load Balancing, click Start configuration.
  4. Name the load balancer lb-1.
  5. Click Backend configuration.
  6. Under the menu Backend services & backend buckets, select the dropdown menu.
  7. Mouse over Backend services, then 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, click the dropdown menu under Instance group and select the web-group instance group.
  11. Under the Health check dropdown menu, select health-check-1 , which we created earlier.
  12. Click Create.
  13. Back at the main load balancer menu, click Frontend configuration.
  14. On the right side menu, name the frontend as frontend-1.
  15. All other defaults should be fine, make sure that the Protocol and Port is set to HTTP 80.
  16. Click Done.
  17. Back at the main load balancer menu, click Review and finalize.
  18. If everything looks good, click Create.
View the Load Balanced Website
  1. In the load balancing menu, click on Frontends from the top horizontal bar.
  2. We should see the IP address for the frontend. Open a new tab and copy/paste the address into a new tab address bar. If the site can’t be displayed, give the load balancer a few more minutes to initialize
  3. Once the website is working correctly, leave this tab up to refer to later.
Update the Instance Group to Version 2 Website
  1. First, create a new instance template.

  2. In the Compute Engine menu, select Instance templates.

  3. Create a new instance template, we will be using the same process as the first template.

  4. Name the instance template instance-template-2.

  5. Set machine type to e2-micro.

  6. Change boot disk to our web-v2 custom image from earlier.

  7. Under firewall, select Allow HTTP traffic.

  8. Click Create.

    Next we will update our instance group using the Group Updater.

  9. In the Compute Engine menu, click Instance groups.

  10. Click on our web-group.

  11. Click ROLLING UPDATE from the top menu on the console page.

  12. Under Template, select instance-template-2 from the dropdown menu.

  13. The rest of the defaults should be fine, however we can adjust Maximum surge and Maximum unavailable to 1 instance(s) if we wish.

  14. Ensure that the Update mode is set to Proactive.

    Note: If we to use a multi-zone group vs. a single-zone group, we would be more restricted in regards to our surge/max unavailable settings.

  15. Click Update.

Additional Resources

We recommend running the lab in an incongnito mode browser (or equivalent private browsing mode) to avoid cached login issues.

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?