In this hands-on lab, you learn how to connect to computing resources hosted on Google Cloud via gcloud, Google Cloud's CLI tool.
You are encouraged to type the commands themselves, which reinforces the core concepts. This lab uses code blocks that contain the required commands. You can easily copy and paste the commands from the code block into the appropriate places during the lab.
What you'll learn to do
Practice using gcloud commands.
Connect to compute services hosted on Google Cloud.
Setup and requirements
Labs are timed and cannot be paused. The timer starts when you click Start Lab.
The included cloud terminal is preconfigured with the gcloud SDK.
Use the terminal to execute commands and then click Check my progress to verify your work.
Pre-configured resource:
You have a pre-configured VM instance named gcelab2 in the default network for this lab.
Throughout the lab, you will use the zone:
Create an environment variable to store your zone:
export ZONE={{{project_0.default_zone | ZONE}}}
Task 1. Connecting to your VM instance
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.
SSH stands for Secure Shell. It is a network protocol that allows you to securely access and manage a virtual machine (VM).
To connect to your VM with SSH in a specific zone, run the following command:
gcloud compute ssh gcelab2 --zone $ZONE
Output:
WARNING: The private SSH key file for gcloud does not exist.
WARNING: The public SSH key file for gcloud does not exist.
WARNING: You do not have an SSH key for gcloud.
WARNING: SSH keygen will be executed to generate a key.
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
In a production environment you should set a passphrase, but for this lab it is not required. Leave the passphrase empty by pressing Enter twice.
You have connected to the virtual machine pre-created for the lab.
Did you notice how the command prompt changed?
The prompt now says something similar to sa_xxxxxxxxxxxxxxxxxxxx@gcelab2
The reference before the @ sign indicates the account being used.
After the @ sign indicates the host machine being accessed.
Install nginx web server on to the virtual machine:
sudo apt install -y nginx
You don't need to do anything here. To disconnect from SSH and exit the remote shell, run the following command:
exit
You should be back at your project's command prompt.
Task 2. Updating the firewall
When using compute resources such as virtual machines, its important to understand the associated firewall rules.
From the above you can see the default networks available, where the virtual machine gcelab2 is located.
Try to access the nginx service running on the gcelab2 virtual machine.
Send HTTP request using cURL to the nginx web server and see if the server responds:
curl http://$(gcloud compute instances list --filter=name:gcelab2 --format='value(EXTERNAL_IP)')
The nginx server will not respond and you will see a frozen remote shell. Press Ctrl-c to stop cURL.
Communication with the virtual machine will fail as it does not have an appropriate firewall rule. Nginx uses port 80 for HTTP traffic by default. The nginx web server is expecting to communicate on tcp:80.
To get communication working you need to updated a firewall rule which allows incoming traffic on TCP port 80 from any source targeting gcelab2 virtual machine.
Notice --target-tags=http-server in the above command. This firewall rule applies only to instances that have the http-servernetwork tag, which means that incoming traffic on port 80 would be allowed to those instances.
Add the http-server network tag to the gcelab2 virtual machine:
...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 January 9, 2024
Lab Last Tested November 12, 2024
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.
Les ateliers créent un projet Google Cloud et des ressources pour une durée déterminée.
Les ateliers doivent être effectués dans le délai imparti et ne peuvent pas être mis en pause. Si vous quittez l'atelier, vous devrez le recommencer depuis le début.
En haut à gauche de l'écran, cliquez sur Démarrer l'atelier pour commencer.
Utilisez la navigation privée
Copiez le nom d'utilisateur et le mot de passe fournis pour l'atelier
Cliquez sur Ouvrir la console en navigation privée
Connectez-vous à la console
Connectez-vous à l'aide des identifiants qui vous ont été attribués pour l'atelier. L'utilisation d'autres identifiants peut entraîner des erreurs ou des frais.
Acceptez les conditions d'utilisation et ignorez la page concernant les ressources de récupération des données.
Ne cliquez pas sur Terminer l'atelier, à moins que vous n'ayez terminé l'atelier ou que vous ne vouliez le recommencer, car cela effacera votre travail et supprimera le projet.
Ce contenu n'est pas disponible pour le moment
Nous vous préviendrons par e-mail lorsqu'il sera disponible
Parfait !
Nous vous contacterons par e-mail s'il devient disponible
Un atelier à la fois
Confirmez pour mettre fin à tous les ateliers existants et démarrer celui-ci
Utilisez la navigation privée pour effectuer l'atelier
Ouvrez une fenêtre de navigateur en mode navigation privée pour effectuer cet atelier. Vous éviterez ainsi les conflits entre votre compte personnel et le compte temporaire de participant, qui pourraient entraîner des frais supplémentaires facturés sur votre compte personnel.
Use the gcloud command line to connect to compute resources hosted on Google Cloud
Durée :
1 min de configuration
·
Accessible pendant 15 min
·
Terminé après 15 min