Managing Google Compute Engine Images and Instance Groups

30 minutes
  • 3 Learning Objectives

About this Hands-on Lab

Managing groups of identical virtual machines can provide extra reliability and resilience in your infrastructure, as each individual machine comes as a disposable component – easily replaced from a template that you have previously defined. In this lab, we’ll set up a “golden image” for our desired compute engine instance and use it to create an instance template. Then we’ll deploy a group of managed instances based on this template that are distributed across a region for high availability.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create a Golden Image for a Web Server
  1. In the GCP console, navigate to Compute Engine > VM instances and click Create.

  2. Change the Machine type to e2-small.

  3. Under Firewall, check the box for Allow HTTP traffic. (This isn’t strictly required for our golden image instance, but it conveniently creates an HTTP firewall rule for us).

  4. Click Create to create the instance.

  5. When the instance is up and running, click SSH to connect to it.

  6. Update system packages and install the Apache web server on the instance:

    sudo apt update
    sudo apt -y install apache2
  7. Stop the instance from the cloud console.

  8. In the Compute Engine menu, select Storage > Images and click Create Image.

  9. Name the image "apache-gold" and select your instance as the source disk.

  10. Change the location to Regional and click Create to create the disk image.

Create an Instance Template
  1. In the Compute Engine menu, select Virtual machines > Instance templates and click Create instance template.

  2. Name the template "apache-template".

  3. Change the Machine type to e2-small.

  4. Under Firewall, check the box for Allow HTTP traffic.

  5. Change the Boot disk. Select Custom images and choose the apache-gold image you just created.

  6. Expand the Management, security, disks, networking, sole tenancy section.

  7. Add the following startup script:

    #! /bin/bash
    ZONE=`curl -fs http://metadata/computeMetadata/v1/instance/zone -H "Metadata-Flavor: Google" | cut -d'/' -f4`
    cat > /var/www/html/index.html <<EOF
    <html><body><h1>Hello Cloud Gurus</h1><p>This server is serving from ${ZONE}.</p></body></html>
    EOF
  8. Click Create to create the instance template.

Create a Regional Managed Instance Group
  1. In the Compute Engine menu, select Instance groups and click Create instance group.
  2. Name the instance group apache.
  3. Under Location, select Multiple zones.
  4. Under Instance template, select the apache-template you just created.
  5. Under Autoscaling, enter the Minimum number of instances as "3" and the Maximum number of instances as "5".
  6. Click Create to create the instance group.
  7. After a few minutes, you will have three managed instances running in your group. Select the group to see the list of managed instances, then click any of the external IP links to view the web page served by the instance, which should display the zone they are running in.

Additional Resources

Log in to Google Cloud Platform by opening https://console.cloud.google.com/ in a private browser window. Then, sign in using the credentials provided on the lab page.

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.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!

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