arrow_back

Google Cloud Fundamentals: Getting Started with Compute Engine

Sign in Join
Get access to 700+ labs and courses

Google Cloud Fundamentals: Getting Started with Compute Engine

Lab 25 minutes universal_currency_alt 5 Credits show_chart Introductory
info This lab may incorporate AI tools to support your learning.
Get access to 700+ labs and courses

Overview

In this lab, you will create virtual machines (VMs) and connect to them. You will also create connections between the instances.

Objectives

In this lab, you will learn how to perform the following tasks:

  • Create a Compute Engine virtual machine using the Google Cloud console.
  • Create a Compute Engine virtual machine using the gcloud command-line interface.
  • Connect between the two instances.

Task 1. Sign in to the Google Cloud console

For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.

  1. Sign in to Qwiklabs using an incognito window.

  2. Note the lab's access time (for example, 1:15:00), and make sure you can finish within that time.
    There is no pause feature. You can restart if needed, but you have to start at the beginning.

  3. When ready, click Start lab.

  4. Note your lab credentials (Username and Password). You will use them to sign in to the Google Cloud Console.

  5. Click Open Google Console.

  6. Click Use another account and copy/paste credentials for this lab into the prompts.
    If you use other credentials, you'll receive errors or incur charges.

  7. Accept the terms and skip the recovery resource page.

Task 2. Create a virtual machine using the Cloud console

  1. In the Navigation menu (Navigation menu), click Compute Engine > VM instances.
  2. Click CREATE INSTANCE.
  3. On the Create an Instance page, for Name, type my-vm-1.
  4. For Region and Zone, select the region and zone assigned by Google Cloud Skills Boost.
  5. For Machine type, accept the default.
  6. Click on the OS and storage.
  7. Under Operating system and storage, if the Image shown is not Debian GNU/Linux 11 (Bullseye), click Change and select Debian GNU/Linux 11 (Bullseye).
  8. Click Networking.
  9. For Firewall, click Allow HTTP traffic.
  10. Leave all other defaults unmodified.
  11. To create and launch the VM, click Create.
Note: The VM can take about two minutes to launch and be fully available for use.

Click Check my progress to verify the objective. Create a virtual machine using the Cloud console

Task 3. Create a virtual machine using the gcloud command line

  1. In the Cloud console, on the top right toolbar, click the Activate Cloud Shell button (Cloud Shell icon).

  2. Click Continue.

  3. To display a list of all the zones in the region to which Google Cloud Skills Boost assigned you, enter this partial command gcloud compute zones list | grep followed by the region that Google Cloud Skills Boost or your instructor assigned you to.

    Your completed command will look like this:

    gcloud compute zones list | grep {{{project_0.default_region|Region 1}}}
  4. Choose a zone from that list other than the zone to which Google Cloud Skills Boost assigned you. For example, if Google Cloud Skills Boost assigned you to region and zone you might choose zone .

  5. To set your default zone to the one you just chose, enter this partial command gcloud config set compute/zone followed by the zone you chose.

    Your completed command will look like this:

    gcloud config set compute/zone {{{project_0.default_zone_2|zone 2}}}
  6. To create a VM instance called my-vm-2 in that zone, execute this command:

    gcloud compute instances create "my-vm-2" \ --machine-type "e2-medium" \ --image-project "debian-cloud" \ --image-family "debian-11" \ --subnet "default"
Note: The VM can take about two minutes to launch and be fully available for use.
  1. To close the Cloud Shell, execute the following command:

    exit

Click Check my progress to verify the objective. Create a virtual machine using the gcloud command line

Task 4. Connect between VM instances

  1. In the Navigation menu, click Compute Engine > VM instances.

    You will see the two VM instances you created, each in a different zone.

    Notice that the Internal IP addresses of these two instances share the first three bytes in common. They reside on the same subnet in their Google Cloud VPC even though they are in different zones.

  2. To open a command prompt on the my-vm-2 instance, click SSH in its row in the VM instances list.

  3. Use the ping command to confirm that my-vm-2 can reach my-vm-1 over the network:

    ping my-vm-1.{{{project_0.default_zone|zone 1}}}

    Notice that the output of the ping command reveals that the complete hostname of my-vm-1 is my-vm-1.us-.c.PROJECT_ID.internal, where PROJECT_ID is the name of your Google Cloud Platform project. The Cloud console automatically supplies Domain Name Service (DNS) resolution for the internal IP addresses of VM instances.

  4. Press Ctrl+C to abort the ping command.

  5. Return to the Cloud Console tab.

  6. Click SSH in the my-vm-1 row in the VM instances list.

  7. At the command prompt on my-vm-1, install the Nginx web server:

    sudo apt-get install nginx-light -y
  8. Use the nano text editor to add a custom message to the homepage of the web server:

    sudo nano /var/www/html/index.nginx-debian.html
  9. Use the arrow keys to move the cursor to the line just below the h1 header. Add text like this, and replace YOUR_NAME with your name:

    Hi from YOUR_NAME
  10. Press Ctrl+O and then press Enter to save your edited file, and then press Ctrl+X to exit the nano text editor.

  11. Confirm that the web server is serving your new page. At the command prompt on my-vm-1, execute this command:

    curl http://localhost/

    The response will be the HTML source of the web server's home page, including your line of custom text.

  12. Return to the command prompt on my-vm-2

  13. To confirm that my-vm-2 can reach the web server on my-vm-1, at the command prompt on my-vm-2, execute this command:

    curl http://my-vm-1.{{{project_0.default_zone|zone 1}}}/

    The response will again be the HTML source of the web server's home page, including your line of custom text.

  14. In the Navigation menu, click Compute Engine > VM instances.

  15. Copy the External IP address for my-vm-1 and paste it into the address bar of a new browser tab.

You will see your web server's home page, including your custom text.

Note: If you forgot to click Allow HTTP traffic when you created the my-vm-1 VM instance, your attempt to reach your web server's home page will fail. You can add a firewall rule to allow inbound traffic to your instances, although this topic is out of scope for this course.

Congratulations!

In this lab, you created virtual machine (VM) instances in two different zones and connected to them using ping, ssh, and HTTP.

End your lab

When you have completed your lab, click End Lab. Google Cloud Skills Boost removes the resources you’ve used and cleans the account for you.

You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.

The number of stars indicates the following:

  • 1 star = Very dissatisfied
  • 2 stars = Dissatisfied
  • 3 stars = Neutral
  • 4 stars = Satisfied
  • 5 stars = Very satisfied

You can close the dialog box if you don't want to provide feedback.

For feedback, suggestions, or corrections, please use the Support tab.

Copyright 2022 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.

Before you begin

  1. Labs create a Google Cloud project and resources for a fixed time
  2. Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
  3. On the top left of your screen, click Start lab to begin

Use private browsing

  1. Copy the provided Username and Password for the lab
  2. Click Open console in private mode

Sign in to the Console

  1. Sign in using your lab credentials. Using other credentials might cause errors or incur charges.
  2. Accept the terms, and skip the recovery resource page
  3. Don't click End lab unless you've finished the lab or want to restart it, as it will clear your work and remove the project

This content is not currently available

We will notify you via email when it becomes available

Great!

We will contact you via email if it becomes available

One lab at a time

Confirm to end all existing labs and start this one

Use private browsing to run the lab

Use an Incognito or private browser window to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.