We will launch two VM instances on both us-central1 and us-east1 by using the following configuration:
VM Instance name |
Target VPC |
zone (see the following steps) |
Target Subnet |
Assign Network Tag |
chap7-public |
chap7 |
us-central1-a |
chap7-us-central1 |
public |
chap7-private |
chap7 |
us-east1-b |
chap7-us-east1 |
private |
- Check the available zones in us-central1 and us-east1 by using the following command:
$ gcloud compute zones list --filter='name:(us-east1,us-central1)'
NAME REGION STATUS NEXT_MAINTENANCE TURNDOWN_DATE
us-east1-b us-east1 UP
us-east1-c us-east1 UP
us-east1-d us-east1 UP
us-central1-c us-central1 UP
us-central1-a us-central1 UP
us-central1-f us-central1 UP
us-central1-b us-central1 UP
So, let's choose us-central1-a for chap7-public and us-east1-b for chap7-private:
- Type the following command to create two VM instances:
$ gcloud compute instances create chap7-public --network=chap7 --subnet=chap7-us-central1 --zone=us-central1-a --tags=public --machine-type=f1-micro
$ gcloud compute instances create chap7-private --network=chap7 --subnet=chap7-us-east1 --zone=us-east1-b --tags=private --machine-type=f1-micro
- Check the VM instance external IP address via the following command:
$ gcloud compute instances list
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
chap7-public us-central1-a f1-micro 192.168.1.2 35.224.14.45 RUNNING
chap7-private us-east1-b f1-micro 192.168.2.2 35.229.95.179 RUNNING
- Run ssh-agent to remember your ssh key:
$ ssh-add ~/.ssh/id_rsa
- ssh from your machine to chap7-public using the -A option (forward authentication) and using an external IP address:
- ssh from chap7-public to chap7-private via the internal IP address:
- Type the exit command to go back to the chap7-public host, then install nginx by using the apt-get command:
- Launch nginx by using the following command:
$ sudo systemctl start nginx
- Access chap7-public (via the external IP) using your web browser:
Congratulations! You have finished setting up a GCP VPC, Subnet, and firewall rules, and launch VM instances! These are very basic and common usages of Google Compute Engine. You can login and install software in these machines, or even build a Kubernetes cluster from scratch. However, GCP also has a managed Kubernetes product called Kubernetes Engine. We will explore it in this chapter.