Working with Custom Images on Google Compute Engine

Hands-On Lab

 

Photo of Matthew Ulasien

Matthew Ulasien

Team Lead Google Cloud in Content

Length

01:00:00

Difficulty

Intermediate

In this hands-on lab, we are going to practice creating custom images from two versions of a web server (which will be provided for you), add both images to the same image family, describe the image family, deprecate an image, and create a new web server from our custom images.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Working with Custom Images on Google Compute Engine

Introduction

In this hands-on lab, we are going to practice creating custom images from two versions of a web server (which will be provided for you), add both images to the same image family, describe the image family, deprecate an image, and create a new web server from our custom images.

Solution

Begin by logging in to the GCP Console using the credentials provided on the hands-on lab page.

Be sure to launch the lab in incognito (or other private view) mode to avoid cached login issues.

You will have two custom web servers created in Compute Engine for you when you begin the lab.

Create image from base-apache instance using web console

Create custom image from base-apache instance using web console:

  • Navigate to the Compute Engine section using the menu in the top-left
  • Stop both instances by checking the boxes next to the instance name and clicking the Stop icon in the top menu
  • Go to Compute Engine > Images
  • Click CREATE IMAGE
  • Name image "webserver-base"
  • Set Family to "webserver"
  • In the Source dropdown menu, select Disk
  • In the Source disk dropdown menu, select base-apache
  • Click Create

Create image from custom-webpage instance using gcloud command

Create image from custom-webpage instance using gcloud command:

  • Stop the instance (if it is not already stopped)
  • Open Cloud Shell (the icon is in the blue bar at the top of the page)
  • Enter command to create image from the custom-webpage disk, name the image "custom-webpage", and add to the webserver image family
    • gcloud compute images create custom-page-1 --source-disk=custom-webpage --source-disk-zone=us-central1-a --family=webserver
  • Verify that image is created and in the appropriate family using the web console

View images in web console and view 'webserver' image family information in command line

View images in web console and view webserver image family information in command line:

  • In web console, go to Compute Engine > Images
  • To describe image family and view latest image, enter command:
    • gcloud compute images describe-from-family webserver
  • Shown image is the latest version

Deprecate base image in our 'webserver' image family using command line

Deprecate base version using command line:

  • First, view process in web console:
    • Go back to Compute Image > Images
    • Place check next to webserver-base, and click DEPRECATE
    • Set State to Deprecated, and set Replacement as custom-webpage
    • Cancel out and do the same thing via command line.
  • In Cloud Shell, enter:
    • gcloud compute images deprecate webserver-base --state DEPRECATED
  • Verify in web console

Create a new web server from custom image

Create a new web server from custom image:

  • Go to Compute Engine > VM Instances
  • Click Create Instance
  • Name the instance "new-webpage"
  • Place it in the us-east1 (South Carolina) Region and the us-east1-b Zone.
  • Under Boot disk, click Change
  • Click on Custom images from the top menu
  • Click on Show deprecated images to view all images
  • Select custom-webpage, and click Select
  • Check the box for Allow HTTP traffic under Firewall settings
  • Click Create
  • Once the instance is up, click the external IP address to verify the new web page works

Conclusion

Congratulations, you've completed this hands-on lab!