Compute Engine Fundamentals: Machine Types, Images, Disks, Startup Scripts, Spot VMs and Sole-Tenant Nodes
What Is Compute Engine?
Compute Engine (GCE) gives you virtual machines running on Google's infrastructure. It is IaaS: you choose the size and operating system, and you manage the software.
Machine Families
| Family | Series examples | Best for |
|---|---|---|
| General purpose | E2 (low cost), N2, N4, C4, Tau T2D | Web servers, apps, small databases. Start here |
| Compute optimized | C2, H3 | High-performance computing, gaming, batch |
| Memory optimized | M-series | In-memory databases like SAP HANA |
| Storage optimized | Z3 | Large local SSD workloads |
| Accelerator optimized | A-series, G-series (GPUs) | Machine learning and graphics |
- Names look like
e2-standard-4: familye2, shapestandard, 4 vCPUs - Shapes: standard (about 4 GB per vCPU), highmem (8 GB), highcpu (1 GB)
- Custom machine types let you pick exact vCPU and memory so you do not pay for extra
- Shared-core types (
e2-micro,e2-small) are cheap for tiny jobs
bash
gcloud compute machine-types list --zones=asia-south1-a --filter="name~^e2-standard"
gcloud compute instances create custom-vm --zone=asia-south1-a --custom-cpu=3 --custom-memory=10GB --custom-vm-type=n2
Images and Boot Disks
- An image is a template with the operating system (Debian, Ubuntu, Windows, Rocky and more)
- A custom image is made from your own configured disk. Group versions in an image family
- The boot disk is a Persistent Disk or Hyperdisk created from the image
Launch a Web Server With a Startup Script
bash
cat > startup.sh <<'EOF'
#!/bin/bash
apt-get update && apt-get install -y nginx
echo "Hello from $(hostname)" > /var/www/html/index.html
EOF
gcloud compute instances create web-1 --zone=asia-south1-a --machine-type=e2-small \
--image-family=debian-12 --image-project=debian-cloud --tags=http-server \
--metadata-from-file=startup-script=startup.sh
gcloud compute firewall-rules create allow-http --allow=tcp:80 --target-tags=http-server --source-ranges=0.0.0.0/0
gcloud compute instances describe web-1 --zone=asia-south1-a --format="get(networkInterfaces[0].accessConfigs[0].natIP)"
- Metadata are key-value settings available to the VM at
metadata.google.internal - Network tags link firewall rules to VMs
- VMs get an attached service account so code needs no keys
Pricing Options for VMs
| Option | Idea | Use for |
|---|---|---|
| Standard (on-demand) | Pay per second (minimum 1 minute) | Normal workloads |
| Spot VMs | Spare capacity at a large discount. Google can stop them any time (30-second warning). No maximum runtime | Batch, CI, rendering, fault-tolerant work |
| Committed use discounts (CUDs) | Commit to 1 or 3 years for a discount | Steady workloads |
| Sustained use discounts | Automatic discount for long monthly use on some families | Nothing to do |
| Sole-tenant nodes | Physical server only for you | License rules, compliance, isolation |
bash
gcloud compute instances create batch-worker --zone=asia-south1-a --machine-type=e2-standard-4 \
--provisioning-model=SPOT --instance-termination-action=STOP
Access and Management
- OS Login: SSH access controlled by IAM roles (
roles/compute.osLogin) - IAP TCP forwarding: SSH to VMs with no public IP
- Live migration: Google moves running VMs during maintenance, so most VMs do not reboot
- Snapshots and machine images back up VMs
- Instance schedules start and stop VMs automatically to save cost
Choosing Compute Engine
| Choose it when | Think about another option when |
|---|---|
| Need full OS control, special software or lift-and-shift | A container or function can do the job (GKE, Cloud Run) |
| Licensed software or custom kernel | You do not want to patch servers (use managed services) |
Practice
- Create a VM with the nginx startup script and open it in a browser
- Create a custom machine type with 3 vCPU and 10 GB memory
- Create a Spot VM and stop it
- SSH using IAP with no external IP
- Delete everything you created
Conclusion
Compute Engine provides VMs in many machine families. Choose the smallest type that fits, automate setup with startup scripts, use Spot or committed use discounts to save, and use OS Login with IAP for safe access.
Quick Summary: what; families; images; startup; pricing; access; choosing.

