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 type | vCPUs | Memory | Typical use |
|---|---|---|---|
e2-micro | 2 (shared) | 1 GB | Tiny services, experiments |
e2-medium | 2 (shared) | 4 GB | Small web servers |
e2-standard-4 | 4 | 16 GB | General-purpose workloads |
n2-standard-4 | 4 | 16 GB | Steadier, 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:
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
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
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
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
- Create and start a VM (opens in a new tab) - the full set of creation options.
- Create a VM from a public image (opens in a new tab) - image families and image projects.
- Machine families resource guide (opens in a new tab) - choosing between E2, N2, C3, and the rest.
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.
Done with this one?
Skipped the challenge? You can mark the lesson complete by hand.