Google Cloud Cheatsheet
Compute Engine
Use this Google Cloud reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.
Create & Manage Instances
# Create a VM (minimal) gcloud compute instances create my-vm \ --zone=us-central1-a \ --machine-type=e2-micro \ --image-family=debian-12 \ --image-project=debian-cloud # Create with more options gcloud compute instances create my-vm \ --zone=us-central1-a \ --machine-type=n2-standard-4 \ --image-family=ubuntu-2204-lts \ --image-project=ubuntu-os-cloud \ --boot-disk-size=50GB \ --boot-disk-type=pd-ssd \ --tags=http-server,https-server \ --service-account=my-sa@proj.iam.gserviceaccount.com \ --scopes=cloud-platform # List instances gcloud compute instances list # Describe a VM gcloud compute instances describe my-vm --zone=us-central1-a # Start / stop / reset gcloud compute instances start my-vm --zone=us-central1-a gcloud compute instances stop my-vm --zone=us-central1-a gcloud compute instances reset my-vm --zone=us-central1-a # Delete gcloud compute instances delete my-vm --zone=us-central1-a
Machine Types
| Family | Type | vCPUs | RAM | Best for |
|---|---|---|---|---|
| E2 (economy) | e2-micro | 0.25 | 1 GB | Dev, low traffic |
| E2 | e2-standard-4 | 4 | 16 GB | General-purpose |
| N2 (balanced) | n2-standard-4 | 4 | 16 GB | Web, databases |
| C3 (compute) | c3-highcpu-8 | 8 | 16 GB | CPU-bound workloads |
| M3 (memory) | m3-ultramem-32 | 32 | 976 GB | SAP HANA, in-mem DB |
| A2/A3 (accelerator) | a2-highgpu-1g | 12 | 85 GB | ML training (GPU) |
| Custom | n1-custom-6-20480 | 6 | 20 GB | Fine-grained sizing |
Spot VMs add
--provisioning-model=SPOT— up to 91% discount, can be preempted.
SSH & File Transfer
# SSH (connects via the VM's external IP by default) gcloud compute ssh my-vm --zone=us-central1-a # Tunnel through IAP — required for VMs with no external IP # (gcloud also falls back to IAP automatically when the VM has none) gcloud compute ssh my-vm --zone=us-central1-a --tunnel-through-iap # Run a command remotely gcloud compute ssh my-vm --zone=us-central1-a --command="df -h" # SCP gcloud compute scp ./local.txt my-vm:/home/user/ --zone=us-central1-a gcloud compute scp my-vm:/var/log/syslog ./syslog.txt --zone=us-central1-a
Startup Scripts
# Inline startup script gcloud compute instances create my-vm \ --metadata=startup-script='#!/bin/bash apt-get update apt-get install -y nginx systemctl start nginx' # Script from file gcloud compute instances create my-vm \ --metadata-from-file=startup-script=startup.sh # Script from GCS gcloud compute instances create my-vm \ --metadata=startup-script-url=gs://my-bucket/startup.sh
Disks
# Create a persistent disk gcloud compute disks create my-disk \ --size=100GB \ --type=pd-ssd \ --zone=us-central1-a # Attach to VM gcloud compute instances attach-disk my-vm \ --disk=my-disk \ --zone=us-central1-a # Detach gcloud compute instances detach-disk my-vm \ --disk=my-disk \ --zone=us-central1-a # Snapshot a disk gcloud compute disks snapshot my-disk \ --snapshot-names=my-snap \ --zone=us-central1-a # Create disk from snapshot gcloud compute disks create restored-disk \ --source-snapshot=my-snap \ --zone=us-central1-a
Disk Types
| Type | Latency | Throughput | Use case |
|---|---|---|---|
pd-standard | High | Moderate | Boot disks, cold storage |
pd-balanced | Medium | Good | General-purpose |
pd-ssd | Low | High | Databases, high IOPS |
pd-extreme | Very low | Very high | SAP HANA, top-tier DB |
hyperdisk-extreme | Lowest | Highest | OLTP at scale |
Instance Templates & Managed Groups
# Create instance template gcloud compute instance-templates create my-template \ --machine-type=e2-standard-2 \ --image-family=debian-12 \ --image-project=debian-cloud \ --tags=http-server # Create a Managed Instance Group (MIG) gcloud compute instance-groups managed create my-mig \ --template=my-template \ --size=3 \ --zone=us-central1-a # Enable autoscaling gcloud compute instance-groups managed set-autoscaling my-mig \ --zone=us-central1-a \ --min-num-replicas=1 \ --max-num-replicas=10 \ --target-cpu-utilization=0.6 # Rolling update gcloud compute instance-groups managed rolling-action start-update my-mig \ --version=template=new-template \ --zone=us-central1-a
Firewall Rules
# Allow HTTP/HTTPS to tagged VMs gcloud compute firewall-rules create allow-http \ --direction=INGRESS \ --action=ALLOW \ --rules=tcp:80,tcp:443 \ --target-tags=http-server # Allow SSH from specific IP gcloud compute firewall-rules create allow-ssh-office \ --direction=INGRESS \ --action=ALLOW \ --rules=tcp:22 \ --source-ranges=203.0.113.0/24 # List rules gcloud compute firewall-rules list
Metadata & Serial Console
# Set instance metadata gcloud compute instances add-metadata my-vm \ --metadata=key=value,env=prod # Read metadata from inside the VM curl -H "Metadata-Flavor: Google" \ http://metadata.google.internal/computeMetadata/v1/instance/ # View serial console output (boot logs) gcloud compute instances get-serial-port-output my-vm --zone=us-central1-a