Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru

Managing Google Compute Engine Images and Instance Groups

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.


Path Info

Clock icon Beginner
Clock icon 30m
Clock icon Apr 09, 2021

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    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.

  2. Challenge

    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 Advanced options.  Under Management, Automation, paste in 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>
    7. Click Create to create the instance template.

  3. Challenge

    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.

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

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.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans