Skip to content
Back to Cloud Services

GCP Compute Engine VMs

Scalable VMs with custom machine types, live migration, and per-second billing.

GCPIntermediate

Why

Compute Engine offers custom machine types (exact vCPU/GB), live migration (no downtime for maintenance), and per-second billing. e2-micro free tier: 1 always-on + 1 preemptible. GCP holds 12% cloud market share and is the fastest-growing cloud (Synergy Research Q4 2024).

GCP's BigQuery processes exabyte-scale analytics, and Vertex AI offers first-party TPU v5 pods for ML training at 2-3x cost-efficiency vs GPU.

When

Use for custom software, GPU workloads, and apps needing OS access. Use Cloud Run for containers, Cloud Functions for events.

How

1. Create — gcloud compute instances create web --machine-type e2-medium --zone us-central1-a 2. Custom type — --custom-cpu 4 --custom-memory 16 (exact resources) 3. Startup script — --metadata startup-script= installs on boot 4. Spot — --provisioning-model SPOT, 60-91% off, 30s notice 5. Live migration — automatic, no downtime for host maintenance 6. Snapshots — gcloud compute snapshots create, incremental backups 7. MIG — Managed Instance Group, auto-scaling + auto-healing 8. Sole-tenant — dedicated physical host for licensing/compliance

Example

gcloud compute instances create web-server \ --machine-type e2-medium \ --image-family debian-12 --image-project debian-cloud \ --metadata startup-script="#!/bin/bash\napt update && apt install -y nginx" \ --tags http-server \ --zone us-central1-a # Managed Instance Group with auto-scaling gcloud compute instance-templates create web-template \ --machine-type e2-medium --image-family debian-12 gcloud compute instance-groups managed create web-mig \ --template web-template --size 3 --zone us-central1-a gcloud compute instance-groups managed set-autoscaling web-mig \ --max-num-replicas 10 --min-num-replicas 2 \ --target-cpu-utilization 0.7

Common Problems

  • ⚠Spot preemption 30s notice — checkpoint work, use MIG for auto-replace
  • ⚠Default network too open — create custom VPC with firewall rules
  • ⚠Egress cost high — use Cloud CDN or compress responses

Best Practices

  • ✓Use MIG not individual VMs — auto-scaling, auto-healing, rolling updates
  • ✓Custom machine types — pay for exact resources, no rounding up
  • ✓Use Spot for batch — 60-91% off, MIG handles preemption

FAQ

What is GCP Compute Engine VMs and what problem does it solve?

Scalable VMs with custom machine types, live migration, and per-second billing. It lets developers deploy, store, and scale without self-managing infrastructure — a core reference for cloud service selection.

How do I get started with GCP Compute Engine VMs in 5 minutes?

Two steps to run it: (1) Create — gcloud compute instances create web --machine-type e2-medium --zone us-central1-a; (2) Custom type — --custom-cpu 4 --custom-memory 16 (exact resources). Validate on the free tier first, then wire into production.

What is the #1 pitfall with GCP Compute Engine VMs?

The most frequent issue is: Spot preemption 30s notice — checkpoint work, use MIG for auto-replace. Run a pre-launch checklist item by item, and add policy/config scanning in CI.

What are the best practices for GCP Compute Engine VMs?

Best practices for GCP Compute Engine VMs include: Use MIG not individual VMs — auto-scaling, auto-healing, rolling updates; Custom machine types — pay for exact resources, no rounding up; Use Spot for batch — 60-91% off, MIG handles preemption. The first one — "Use MIG not individual VMs — auto-scaling, auto-healing, rolling updates" — should be a team default baked into your IaC templates.

How do I control cost and avoid bill surprises with GCP Compute Engine VMs?

Three ways to prevent overspend: (1) tag every resource with env/team and enable billing alarms; (2) set budget thresholds to trigger Slack/email alerts; (3) review idle resources in Cost Explorer regularly and clean them up. Most GCP Compute Engine VMs options offer a free tier — validate within free quota before scaling.