Objectives
In this lab, you will learn how to
perform the following tasks:
·
Create a Compute Engine virtual
machine using the Google Cloud Platform (GCP) 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 Platform (GCP)
Console
For each lab, you get a new GCP
project and set of resources for a fixed time at no cost.
1. Make sure you signed into Qwiklabs using an incognito
window.
2. Note the lab's access time (for example, and make
sure you can finish in that time block.
There is no pause feature. You can restart if
needed, but you have to start at the beginning.
3. When ready, click .
4. Note your lab credentials. You will use them to
sign in to Cloud Platform 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 get errors
or incur charges.
7. Accept the terms and skip the recovery resource
page.
Do not click End Lab unless you
are finished with the lab or want to restart it. This clears your work and
removes the project.
Task 2: Create a virtual machine using the GCP
Console
1. In the Navigation menu (),
click Compute Engine > VM instances.
2. Click Create.
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 Qwiklabs.
5. For Machine type, accept the default.
6. For Boot disk, if the Image shown
is not Debian GNU/Linux 9 (stretch), click Change and
select Debian GNU/Linux 9 (stretch).
7. Leave the defaults for Identity and API
access unmodified.
8. For Firewall, click Allow HTTP traffic.
9. Leave all other defaults unmodified.
10.
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 GCP Console
Check my progress
Task 3: Create a virtual machine using the gcloud
command line
1. In GCP console, on the top right toolbar, click the
Open Cloud Shell button.
2. Click Continue.
3. To display a list of all the zones in the region to
which Qwiklabs assigned you, enter this partial command gcloud compute zones list | grep followed by the region that Qwiklabs or your
instructor assigned you to.
Your
completed command will look like this:
gcloud compute zones list | grep us-central1
4. Choose a zone from that list other than the zone to
which Qwiklabs assigned you. For example, if Qwiklabs assigned you to
region us-central1 and zone us-central1-a you might choose zone us-central1-b.
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 us-central1-b
6. To create a VM instance called my-vm-2 in
that zone, execute this command:
7. gcloud compute instances create
"my-vm-2" \
8. --machine-type
"n1-standard-1" \
9. --image-project "debian-cloud"
\
10.--image
"debian-9-stretch-v20190213" \
11.--subnet "default"
Note:
The VM can take about two minutes to launch and be fully available for use.
7. To close the Cloud Shell, execute the following
command:
8. exit
Click Check my progress to verify
the objective.
Create a virtual machine using the gcloud command
line
Check my progress
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:
4. ping my-vm-1
Notice
that the output of the ping command
reveals that the complete hostname of my-vm-1 is my-vm-1.c.PROJECT_ID.internal,
where PROJECT_ID is the name of your Google Cloud Platform project. GCP
automatically supplies Domain Name Service (DNS) resolution for the internal IP
addresses of VM instances.
5. Press Ctrl+C to abort the ping
command.
6. Use the ssh command to open a
command prompt on my-vm-1:
7. ssh my-vm-1
If
you are prompted about whether you want to continue connecting to a host with
unknown authenticity, enter yes to confirm that you do.
8. At the command prompt on my-vm-1,
install the Nginx web server:
9. sudo apt-get install nginx-light -y
10.
Use the nano text
editor to add a custom message to the home page of the web server:
11.sudo nano
/var/www/html/index.nginx-debian.html
12.
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:
13.Hi from YOUR_NAME
14.
Press Ctrl+O and
then press Enter to save your edited file, and then
press Ctrl+X to exit the nano text editor.
15.
Confirm that the web server is
serving your new page. At the command prompt on my-vm-1, execute
this command:
16.curl http://localhost/
The
response will be the HTML source of the web server's home page, including your
line of custom text.
17.
To exit the command prompt on my-vm-1,
execute this command:
18.exit
You
will return to the command prompt on my-vm-2
19.
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:
20.curl http://my-vm-1/
The
response will again be the HTML source of the web server's home page, including
your line of custom text.
21.
In the Navigation menu (),
click Compute Engine > VM instances.
22.
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.
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!
0 comments:
Post a Comment