
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Create a virtual machine with gcloud
/ 50
Update the firewall
/ 50
Cloud Shell provides you with command-line access to computing resources hosted on Google Cloud. Cloud Shell is a Debian-based virtual machine with a persistent 5-GB home directory, which makes it easy for you to manage your Google Cloud projects and resources. The gcloud
command-line tool and other utilities you need are pre-installed in Cloud Shell, which allows you to get up and running quickly.
In this hands-on lab, you learn how to connect to computing resources hosted on Google Cloud via Cloud Shell with the gcloud
tool.
You are encouraged to type the commands themselves, which reinforces the core concepts. Many labs will include a code block that contains the required commands. You can easily copy and paste the commands from the code block into the appropriate places during the lab.
gcloud
commands.vim
, emacs
, or nano
.Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.
This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method. On the left is the Lab Details pane with the following:
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
If necessary, copy the Username below and paste it into the Sign in dialog.
You can also find the Username in the Lab Details pane.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab Details pane.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.
Click Activate Cloud Shell at the top of the Google Cloud console.
Click through the following windows:
When you are connected, you are already authenticated, and the project is set to your Project_ID,
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
Output:
Output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
After Cloud Shell is activated, you can use the command line to invoke the Cloud SDK gcloud
tool or other tools available on the virtual machine instance. Later in the lab, you will use your $HOME
directory, which is used in persistent disk storage to store files across projects and between Cloud Shell sessions. Your $HOME
directory is private to you and cannot be accessed by other users.
In this section, you'll learn about aspects of the development environment that you can adjust.
Certain Google Compute Engine resources live in regions or zones. A region is a specific geographical location where you can run your resources. Each region has one or more zones. For example, the us-central1
region denotes a region in the Central United States that has zones us-central1-a
, us-central1-b
, us-central1-c
, and us-central1-f
. The following table shows zones in their respective regions:
Western US | Central US | Eastern US | Western Europe | Eastern Asia |
---|---|---|---|---|
us-west1-a | us-central1-a | us-east1-b | europe-west1-b | asia-east1-a |
us-west1-b | us-central1-b | us-east1-c | europe-west1c | asia-east1-b |
- | us-central1-c | us-east1-d | europe-west1-d | aisia-east1-c |
- | us-central1-f | - | - | - |
Resources that live in a zone are referred to as zonal resources. Virtual machine instances and persistent disks live in a zone. If you want to attach a persistent disk to a virtual machine instance, both resources must be in the same zone. Similarly, if you want to assign a static IP address to an instance, the instance must be in the same region as the static IP address.
Set the region to
To view the project region setting, run the following command:
Set the zone to
To view the project zone setting, run the following command:
Copy your project ID to your clipboard or text editor. The project ID is listed in 2 places:
In Cloud Shell, run the following gcloud
command, to view the project id for your project:
In Cloud Shell, run the following gcloud
command to view details about the project:
Find the zone and region metadata values in the output.
You'll use the zone (google-compute-default-zone
) from the output later in this lab.
google-compute-default-region
and google-compute-default-zone
keys and values are missing from the output, no default zone or region is set.
The output includes other useful information regarding your project. Take some time to explore this in more detail.
Environment variables define your environment and help save time when you write scripts that contain APIs or executables.
Create an environment variable to store your Project ID:
Create an environment variable to store your Zone:
To verify that your variables were set properly, run the following commands:
If the variables were set correctly, the echo commands will output your Project ID and Zone.
Use the gcloud
tool to create a new virtual machine (VM) instance.
To create your VM, run the following command:
Output:
Command details
gcloud compute
allows you to manage your Compute Engine resources in a format that's simpler than the Compute Engine API.instances create
creates a new instance.gcelab2
is the name of the VM.--machine-type
flag specifies the machine type as e2-medium.--zone
flag specifies where the VM is created.--zone
flag, the gcloud
tool can infer your desired zone based on your default properties. Other required instance settings, such as machine type
and image
, are set to default values if not specified in the create
command.Click Check my progress to verify your performed task. If you have successfully created a virtual machine with the gcloud
tool, an assessment score is displayed.
create
command, run the following command:The gcloud
tool offers simple usage guidelines that are available by adding the -h
flag (for help) onto the end of any gcloud
command.
Run the following command:
You can access more verbose help by appending the --help
flag onto a command or running the gcloud help
command.
Run the following command:
To exit type Q
and hit Enter.
Run the following command:
The results of the gcloud config --help
and gcloud help config
commands are equivalent. Both return long, detailed help.
There are global flags
in gcloud
that govern the behavior of commands on a per-invocation level. Flags override any values set in SDK properties.
View the list of configurations in your environment:
To see all properties and their settings:
List your components:
This command displays the gcloud
components that are ready for you to use in this lab.
The gcloud
command-line interface (CLI) is a powerful tool for working at the command line.
You may want specific information to be displayed.
List the compute instance available in the project:
gcloud
has some clever formatting that can help identify specific resources.
Example Output:
List the gcelab2 virtual machine:
Example Output:
In the above command, you asked gcloud
to only show the information matching the criteria i.e. a virtual instance name matching the criteria.
List the firewall rules in the project:
Output:
List the firewall rules for the default network:
Output:
List the firewall rules for the default network where the allow rule matches an ICMP rule:
Output:
gcloud compute
makes connecting to your instances easy.
The gcloud compute ssh
command provides a wrapper around SSH, which takes care of authentication and the mapping of instance names to IP addresses.
To connect to your VM with SSH, run the following command:
Output:
To continue, type Y.
To leave the passphrase empty, press Enter twice.
Install nginx
web server on to virtual machine:
You don't need to do anything here. To disconnect from SSH and exit the remote shell, run the following command:
You should be back at your project's command prompt.
When using compute resources such as virtual machines, it's important to understand the associated firewall rules.
List the firewall rules for the project:
Output:
From the above you can see there are two networks available.
The default
network is where the virtual machine gcelab2
is located.
Try to access the nginx service running on the gcelab2
virtual machine.
Note: Communication with the virtual machine will fail as it does not have an appropriate firewall rule. The nginx web server is expecting to communicate on tcp:80. To get communication working you need to:
Add a tag to the virtual machine:
Update the firewall rule to allow:
Click Check my progress to verify the objective.
List the firewall rules for the project:
Output:
Verify communication is possible for http to the virtual machine:
You will see the default nginx
output.
Viewing logs is essential to understanding the working of your project.
Use gcloud
to access the different logs available on Google Cloud.
View the available logs on the system:
Output:
View the logs that relate to compute resources:
Output:
Read the logs related to the resource type of gce_instance
:
Read the logs for a specific virtual machine:
The following multiple-choice question should reinforce your understanding of this lab's concepts.
You learned how to launch Cloud Shell and run some sample gcloud
commands.
To learn more about Cloud Shell, refer to the Cloud Shell documentation or the YouTube video, Using Google Cloud Shell.
To learn more about gcloud
, refer to the gcloud documentation or the YouTube video, Getting Help with gcloud.
Continue learning by taking these labs:
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated March 12, 2025
Lab Last Tested March 12, 2025
Copyright 2025 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.
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