Lab 1: Google Cloud Fundamentals: Getting Started with Compute Engine - olubunmialegbeleye/GADS2020_LP2_Google_Cloud_Practice_Project GitHub Wiki
Google Cloud Fundamentals: Getting Started with Compute Engine
Objectives
- 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 2: Create a virtual machine using the GCP Console
The following commands create a VM instance named my-vm-1 using the default region and machine type. It uses Debian GNU/Linux 9 (stretch) as the boot disk image and creates a firewall rule that allows HTTP traffic. You will be asked to confirm the zone at the time of creating the instance.
gcloud compute instances create my-vm-1 --image-project "debian-cloud" --image=debian-9-stretch-v20200902 --tags=http-server
gcloud compute firewall-rules create default-allow-https --direction=INGRESS --priority=1000 --network=default --action=ALLOW --rules=tcp:80 --source-ranges=0.0.0.0/0 --target-tags=http-server
Task 3: Create a virtual machine using the gcloud command line
This command lists all the zone in the us-central1 region
gcloud compute zones list | grep us-central1
This command sets your default zone to us-central1-b
gcloud config set compute/zone us-central1-b
This command creates a VM instance called my-vm-2 in the default zone
gcloud compute instances create "my-vm-2" \
--machine-type "n1-standard-1" \
--image-project "debian-cloud" \
--image "debian-9-stretch-v20190213" \
--subnet "default"
Task 4: Connect between VM instances
This command opens an ssh terminal in my-vm-2. Use the ping command to confirm that my-vm-2 can reach my-vm-1 over the network
gcloud compute ssh my-vm-2
ping -c 3 my-vm-1
This command opens an ssh terminal in my-vm-1. Use the ping command to confirm that my-vm-1 can reach my-vm-2 over the network. The exit command closes the ssh.
gcloud compute ssh my-vm-1
ping -c 3 my-vm-2
exit
Use the ssh command to open a command prompt on my-vm-1:
ssh my-vm-1
From the shell, install the Nginx web server on my-vm-1
sudo apt-get install nginx-light -y```
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
Use the arrow keys to move the cursor to the line just below the h1
header. Add text like this after the <p>
tag.
Hi from Olubunmi
Press Ctrl+O and then press Enter to save your edited file, and then press Ctrl+X to exit the nano text editor.
Confirm that the web server is serving your new page using the curl command.
curl http://localhost/
The response will be the HTML source of the web server's home page, including your line of custom text. To exit the command prompt on my-vm-1, execute this command:
exit
You will return to the command prompt on my-vm-2
gcloud compute ssh my-vm-2
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/
The response will again be the HTML source of the web server's home page, including your line of custom text. The exit command closes the ssh
exit
To get the external IP address of my-vm-1 using either of the following commands:
gcloud compute instances list | grep my-vm-1
gcloud compute instances describe my-vm-1 | grep networkIP
You can also use a slight modification of the previous command to get its internal IP address.
gcloud compute instances describe my-vm-1 | grep natIP
Copy the External IP address for my-vm-1 and paste it into the address bar of a new browser tab. Hit enter. You will see your web server's home page, including your custom text.