Google Cloud VM#

Today we’re going to start using your Google Cloud credits so you can have your own VM. You’ll also learn to connect to your VM (and Opus) with vscode.

Warning

Before you do this you should get your $50 cloud credit!

Labs#

In class I do a walk-through of these publicly available labs and tutorials. If you learn nothing else from the class you should learn how to use publicly available resources to gain new skills. The cloud is ever changing, knowing how to use the manuals will keep you current.

Setup gcloud on Opus#

The gcloud command from Google is installed on Opus. It’s really the easiest way to create, manage and access cloud instances (VMs). To do the next part of the lab you should authenticate your Opus account to your Google account by running this command and following the instructions:

$ gcloud auth login 

You’ll need to copy and paste the URL it gives you into a browser. Once connected you need to select a project. If you’ve never used gcloud before, the next command will configure the gcloud command to use your starter project by default:

$ gcloud config set project $(gcloud projects list  --format 'value(projectId)' | head -n 1)

Note

If you have a particular project you’d like to use run:

$ gcloud config set project you-project-id-here

Create a VM#

Run these two commands to create a new VM and configure the firewall to let browsers connect over the internet:

$ gcloud compute instances create my-debian-vm  \
    --machine-type=e2-small \
    --image-family=debian-12 \
    --image-project=debian-cloud \
    --zone=us-central1-a \
    --tags=http-server 

$ gcloud compute firewall-rules create allow-http-https-on-tagged-servers \
    --network=default \
    --allow=tcp:80,tcp:443 \
    --target-tags=http-server \
    --source-ranges=0.0.0.0/0 \
    --description="Allow incoming HTTP and HTTPS traffic to servers with the http-server tag" \
    --direction=INGRESS

Note

Make a note of the external IP address of your vm.

Install Apache2#

On your new VM install the Apache web server. To do that you have to first SSH into the machine:

$ gcloud compute ssh my-debian-vm --zone=us-central1-a

On the machine run the following commands to install Apache using the apt package manager:

user@my-debian-vm:~$ sudo apt update 
user@my-debian-vm:~$ sudo apt install apache2

View and Change Your Page#

Using the browser on your desktop visit the eternal IP address of your VM. You might need to type the complete URL like this:

http://xx.xx.xx.x/

Replace the `xx.xx.xx.xx with your VM’s external IP address. The page you are looking at is written in HTML and CSS. You can view its source code using the context menu on your browser (Right Click -> View Source).

Turn In#

  1. A screenshot of your VM’s web page that shows the IP address

  2. A screenshot of you SSH’ed into the VM

Cleanup#

These commands delete your VM and the firewall rules you created in the first part of this lab:

$ gcloud compute instances delete my-debian-vm --zone=us-central1-a
$ gcloud compute firewall-rules delete allow-http-https-on-tagged-servers

Warning

Failure to delete the VM after this lab will cost you money!