GCP VM instance how-to

Published:

Provision a simple GCP VM instance

This is a simple how-to for provisioning a VM instance on the Google Cloud Platform. This is intended for example purposes and the VM will mostly have default configuration. The VM size chosen fits into the Always Free usage tier.

We’re using the gcloud CLI tool here from the Cloud SDK. Refer to quickstarts documentation to get it installed and setup.

If you haven’t yet used the gcloud tool, take a few minutes to get familiar with it. Most importantly, note that you can almost always get detailed help on available commands and parameters they take by appending --help to the end of the command.

For example, you can get a list of all groups and commands with:

gcloud --help

To then read the documentation for the Google Compute Engine group, run:

gcloud compute --help

And of course you can get detailed help on any gcloud compute command:

gcloud compute instance --help

This makes GCP one of the best-documented CLI tools around and the documentation quality resembles that of the BSDs.

Going back to creating a VM, you can probably guess where you can read help on what parameters are available when creating a VM:

gcloud compute instances create --help

Lets get started, here’s a complete command, we’ll go over it next::

gcloud compute instances create vm-01 --description=vm-01 \
    --boot-disk-size=30GB --boot-disk-type=pd-standard \
    --image-project=debian-cloud --machine-type=f1-micro \
    --metadata=env=dev --image-family=debian-8 --zone=us-west1-a
  • Debian 8 (Jessie) VM called vm-01
  • with a 30GB persistent storage HDD
  • of size `f1-micro
  • metadata key env with value dev
  • in us-west1-a availability zone

Note that the Debian 8 image is 10GB in size and by allocating a larger disk to this VM, the image will automatically expand the root partition to the size of the disk.

When the command finishes, you’ll see a summary:

Created [https://www.googleapis.com/compute/v1/projects/<name_of_your_project>/zones/us-west1-a/instances/vm-01].
NAME  ZONE        MACHINE_TYPE  PREEMPTIBLE  INTERNAL_IP  EXTERNAL_IP     STATUS
vm-01 us-west1-a  f1-micro                   10.138.0.2   104.196.xxx.xx  RUNNING

At this point the VM is ready for action and you can ssh into it by using the gcloud compute ssh command:

gcloud compute ssh vm-01

This will generate an SSH keypair, stored under $HOME/.ssh/google_compute_engine by default, and upload it to the VM so it can be used for authentication.

That’s it, we’re up and running.

Since the Always Free tier only allows instances in US region, I’m curious to see how much bandwidth I’ll have from my home and Digital Ocean VM in Singapore. International bandwith in Asia is often congested and its not uncommon to have very poor bandwidth to both US and Europe (by “very poor” I mean under 20mbps).

Lets install iperf3 and see what we get, but before we proceed, we first need to open a firewall port to allow iperf3 traffic, which is 5201 by default. Again this is easily accomplished with gcloud tool:

gcloud compute firewall-rules create allow-iperf --allow tcp:5201

Test from my MyRepublic home connection (1gbps down, 500mbps up):

iperf3 -c 104.196.xxx.xx
Connecting to host 104.196.xxx.xx, port 5201
[  4] local 66.96.xxx.xx port 64870 connected to 104.196.xxx.xx port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec   270 KBytes  2.21 Mbits/sec    0    102 MBytes       
[  4]   1.00-2.00   sec  2.68 MBytes  22.5 Mbits/sec    0   1.06 GBytes       
[  4]   2.00-3.00   sec  9.22 MBytes  77.4 Mbits/sec    0   -1184092356.00 Bytes       
[  4]   3.00-4.00   sec  11.1 MBytes  93.3 Mbits/sec    0   -1184092356.00 Bytes       
[  4]   4.00-5.00   sec  11.2 MBytes  93.6 Mbits/sec    0   -1184092356.00 Bytes       
[  4]   5.00-6.00   sec  10.7 MBytes  89.4 Mbits/sec    0   -1184092356.00 Bytes       
[  4]   6.00-7.00   sec  10.6 MBytes  88.5 Mbits/sec    0   -1184092356.00 Bytes       
[  4]   7.00-8.00   sec  10.7 MBytes  90.2 Mbits/sec    0   -1184092356.00 Bytes       
[  4]   8.00-9.00   sec  10.8 MBytes  90.6 Mbits/sec    0   -1184092356.00 Bytes       
[  4]   9.00-10.00  sec  10.7 MBytes  89.4 Mbits/sec    0   -1184092356.00 Bytes       
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-10.00  sec  87.9 MBytes  73.7 Mbits/sec    0             sender
[  4]   0.00-10.00  sec  87.9 MBytes  73.7 Mbits/sec                  receiver

iperf Done.

73.7mbps is actually really good. Lets see how Digital Ocean Singapore VM compares to this:

iperf3 -c 104.196.xxx.xx
Connecting to host 104.196.xxx.xx, port 5201
[  4] local 128.199.xxx.xxx port 41077 connected to 104.196.xxx.xx port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec  1.40 MBytes  11.7 Mbits/sec    0    440 KBytes       
[  4]   1.00-2.00   sec  16.2 MBytes   136 Mbits/sec    0   4.23 MBytes       
[  4]   2.00-3.00   sec  12.5 MBytes   105 Mbits/sec    0   4.23 MBytes       
[  4]   3.00-4.00   sec  10.0 MBytes  83.9 Mbits/sec   50   2.96 MBytes       
[  4]   4.00-5.00   sec  11.2 MBytes  94.4 Mbits/sec  161   2.07 MBytes       
[  4]   5.00-6.00   sec  12.5 MBytes   105 Mbits/sec    0   2.10 MBytes       
[  4]   6.00-7.00   sec  10.0 MBytes  83.8 Mbits/sec    0   2.10 MBytes       
[  4]   7.00-8.00   sec  12.5 MBytes   105 Mbits/sec    0   2.10 MBytes       
[  4]   8.00-9.00   sec  12.5 MBytes   105 Mbits/sec    0   2.10 MBytes       
[  4]   9.00-10.00  sec  12.5 MBytes   105 Mbits/sec    0   2.10 MBytes       
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-10.00  sec   111 MBytes  93.4 Mbits/sec  211             sender
[  4]   0.00-10.00  sec   105 MBytes  87.9 Mbits/sec                  receiver

iperf Done.

~90mbps is also a nice result. Sure, nowhere near my maximum advertised throughput, but way beyond the rest of the networks in Asia. No doubt this is completely due to Google (together with several other companies) actually owning the cables and the network all the way from Singapore to US west cost (and many other places).