Purpose

The purpose of this post is to learn how to create a Google Cloud instance machine using gcloud binary. These are some possible scenarios:

  • Request an instance to run a website with static or dynamic content (low traffic).
  • Request an instance to run a website with static or dynamic content (medium/high traffic).
  • Request an instance to do image processing with a high RAM intensive tasks.
  • Request an instance to process data with a high CPU intensive tasks.

Before you begin

In this tutorial will learn how to use gcloud binary to create an instance machine. A Linux/Mac OS/Windows machine with gcloud binary and a Google Cloud account will be required. Otherwise, you can also request a Google Cloud Platform Free Tier with 12-month and $300 free.

Info about how to install gcloud here.

Zones and types of machines

Google has one or more regions on every continent, and every region has different zones (locations).

In case of storing customer data it is recommended to use zones within a region complying with the local regulation

Current types of machines:

Type Google Cloud Platform instance name
micro (shared vCPU) f1-micro
small (shared vCPU) g1-small
standard n1-standard-{CPUs}
highmem n1-highmem-{CPUs}
highcpu n1-highcpu-{CPUs}

micro and small types could be used to host small websites. standard machine type to host a bigger website and/or with more traffic, highmem type for computing processing with a high RAM intensive tasks as image processing and highcpu to process data with a high CPU intensive tasks.

Create an instance

Log in with gcloud:

gcloud auth login

List current instances:

gcloud compute instances list

List zones:

gcloud compute zones list

Describe specific zone:

gcloud compute zones describe us-west1-b

List current machine types by zone (machine type, zone, CPUs and RAM):

gcloud compute machine-types list | grep us-west1-b

Create an instance with zone and machine type:

gcloud compute instances create example-instance-1 \
--zone us-west1-b \
--machine-type n1-standard-1

Check new instance appears in the list:

gcloud compute instances list | grep example-instance-1

Finally, log out/revoke with gcloud:

gcloud compute instances list

More info about Google Cloud Platform locations and instances:

Bonus track: Limit CPU and RAM usage in Docker:

For development/testing purposes you might want to use a small instance or limit its own resources. With Docker is possible to limit CPU and RAM consumption of running containers.

Limit number of CPUs:

docker run -d --cpus 2 nginx:alpine

Limit memory RAM:

docker run -d --memory 256m nginx:alpine