Skip to content
Intermediate CloudLesson 9 of 13 3 min read

Compute Engine VMs

Create, inspect, stop, and SSH into virtual machines - machine types, public images, and what a stopped VM still costs.

On this page7 sections

Compute Engine is Google Cloud's infrastructure-as-a-service: virtual machines (called instances) running on Google's hardware. Underneath, each one is just a Linux or Windows machine. Everything from the Linux track applies once you are logged in.

Machine types

A machine type fixes the vCPU and memory of a VM. Names follow a family-and-size pattern:

Machine typevCPUsMemoryTypical use
e2-micro2 (shared)1 GBTiny services, experiments
e2-medium2 (shared)4 GBSmall web servers
e2-standard-4416 GBGeneral-purpose workloads
n2-standard-4416 GBSteadier, higher performance

The E2 family is the cost-optimised general-purpose choice. Start small and resize when monitoring shows you need more. Guessing high "to be safe" just costs money.

Images

A VM boots from an image. Public images live in their own projects, so you name both the image family and the image project. Using a family always gives you the latest, non-deprecated image in it:

bash
gcloud compute instances create web-1 \
  --zone=us-central1-a \
  --machine-type=e2-medium \
  --image-family=debian-12 \
  --image-project=debian-cloud

VMs are zonal: web-1 and its boot disk live in us-central1-a. If you set a default zone with gcloud config set compute/zone, you can leave --zone off.

Everyday operations

bash
gcloud compute instances list
gcloud compute instances describe web-1 --zone=us-central1-a
gcloud compute instances stop web-1 --zone=us-central1-a
gcloud compute instances start web-1 --zone=us-central1-a
gcloud compute instances delete web-1 --zone=us-central1-a

A stopped VM no longer bills for vCPUs and memory, but its persistent disks and any reserved static IP addresses are still charged. Delete what you no longer need.

SSH

bash
gcloud compute ssh web-1 --zone=us-central1-a

gcloud compute ssh generates an SSH key pair if you do not have one, publishes the public key to the VM, and connects. You never copy keys around by hand. Connecting also needs a firewall rule that allows TCP port 22, which the networking lesson covers.

Treat VMs as cattle

For anything that has to scale or self-heal, put identical VMs in a managed instance group built from an instance template. The group recreates unhealthy VMs and adds or removes VMs with load. Keep state that must survive (databases, uploads) off the VM's boot disk.

Try it

Run these in the practice terminal (opens in a new tab). It opens in a new tab, so you keep your place here.
bash
gcloud compute machine-types list
gcloud compute instances create web-1 --zone=us-central1-a --machine-type=e2-medium
gcloud compute instances list
gcloud compute ssh web-1 --zone=us-central1-a

When you're ready, hit Mark complete and move to the next lesson.

Further reading

Challenge

Create a VM named web-1 in zone us-central1-a with the e2-medium machine type.

Want to experiment first? Try things in the practice terminal (opens in a new tab), then enter the command that solves the task here.

Quiz

Lock in the concepts. Score at least 80% to mark the lesson complete.

0 of 3 answered

Done with this one?

Skipped the challenge? You can mark the lesson complete by hand.

Your notes

Kept on this browser only.