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
- Stop the currently running Compute Engine instances.
- Open Cloud Shell from the top right-hand side corner.
- Run the following commands in Cloud Shell to quickly create two custom images named
web-v1
andweb-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
- Verify new images are in the Images menu in the web console on the left-hand side.
- Create a Managed Instance Template
- From the Compute Engine menu, select Instance templates.
- Click CREATE INSTANCE TEMPLATE.
- Name the instance template "instance-template-1" (most likely the default name).
- Change the Machine type to e2-micro.
- Under Boot disk, click Change > Custom images and choose the web-v1 image that you created in the previous step.
- Click Select from the bottom.
- Under Firewall, select Allow HTTP traffic.
- Click Create.
- Create a Managed Instance Group
- From the Compute Engine menu, click Instance groups.
- Click CREATE INSTANCE GROUP.
- Name the group "web-group".
- Under Location, choose Single zone. Choose us-east1 for the region or a zone in us-east1.
- Under Instance template, choose instance-template-1.
- Under Autoscaling, set the Minimum number of instances to 3 and the Maximum number of instances to 5.
- From the Health check dropdown, select Create a health check.
- Name the health check "health-check-1".
- Leave all the other settings at their defaults. Make sure that the Protocol is set to TCP with a Port value of 80.
- Click Save and continue.
- Back in the instance group menu, click Create to create the group.
- Create a Load Balancer
- From the top left menu, scroll down to Networking, click on Network services, and then click Load balancing.
- Click Create load balancer.
- Under HTTP(S) Load Balancing, click START CONFIGURATION.
- Click From Internet to my VMs or serverless servicesandGlobal HTTP(S) Load Balancer (classic) then click CONTINUE.
- Name the load balancer "lb-1".
- Click Backend configuration.
- Click the Backend services & backend buckets menu and select CREATE A BACKEND SERVICE.
- Name the backend service "backend-1".
- Under Backend type, make sure that Instance groups is selected (should be the default).
- Under the New backend section, from the Instance group dropdown, select the web-group instance group.
- Set the Port numbers to 80.
- From the Health check dropdown menu, select health-check-1.
- Click CREATE.
- In the New HTTP(S) load balancer menu on the left, click Frontend configuration.
- Name the frontend "frontend-1".
- Leave all the other settings at their defaults. Make sure that the Protocol is set to HTTP with a Port value of 80.
- Click DONE.
- In the New HTTP(S) load balancer menu on the left, click Review and finalize.
- If everything looks good, click CREATE.
- View the Load Balanced Website
- On the Load balancing page, click REFRESH.
- Click on Frontends in the top menu.
- 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.
- Once the website loads, verify that it displays VERSION 1.
- Update the Instance Group to the Version 2 Website
- Back in the GCP Console, from the top left menu, click on Compute Engine and then select Instance templates.
- Create a new instance template using the same process as the first template.
- Name the instance template "instance-template-2".
- Set the Machine type to e2-micro.
- Change the Boot disk to the web-v2 custom image.
- Under Firewall, select Allow HTTP traffic.
- Click Create.
- In the Compute Engine menu, click Instance groups.
- Click on web-group.
- Click UPDATE VMS in the top menu.
- Under Template, select instance-template-2 from the dropdown menu.
- 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.
- Click UPDATE VMS.
- 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.