GcpIntermediate

Getting Started with Google Compute Engine: A Complete Guide

8 min read

TL;DR

Learn the fundamentals of Google Compute Engine (GCE), including VM instance types, disk options, networking, and best practices for managing virtual machines in GCP.

Getting Started with Google Compute Engine: A Complete Guide

Executive Summary

Compute Engine is Google Cloud's infrastructure-as-a-service layer: virtual machines you configure, patch, and operate yourself, in exchange for complete control over the operating system and runtime. This guide covers the decisions that shape a GCE deployment — machine families and sizing, disk choices, images, zonal versus regional placement, instance groups, and the networking and identity defaults that are hard to change later. After reading it, you should be able to create a VM deliberately rather than by accepting defaults, and to judge when a workload belongs on raw VMs at all instead of on a managed platform such as GKE or Cloud Run.

Why This Matters

VMs are where cloud bills and security incidents quietly accumulate. An oversized instance runs for months because nobody re-checks it; an unpatched image becomes the entry point nobody remembered owning; a VM created for a test becomes permanent, undocumented infrastructure. GCE gives you the control to run almost anything — legacy applications, licensed software, unusual kernels — but every layer a managed platform would have handled becomes your responsibility: patching, backup, scaling, and failure recovery. Understanding the fundamentals up front is what separates a fleet you operate from a fleet that operates you.

Core Concepts

Machine Families and Sizing

Machine types are grouped into families tuned for different ratios of CPU, memory, and cost:

Family groupExamplesSuited to
General purposeE2, N2, N2D, T2DWeb servers, app servers, small to medium databases — the default choice
Compute optimisedC2, C3CPU-bound work: game servers, media encoding, high-performance computing
Memory optimisedM2, M3In-memory databases and caches, SAP HANA, large JVM heaps
Accelerator optimisedA2, G2ML training and inference with attached GPUs

Start with a general-purpose type and size from measurement. GCE's built-in right-sizing recommendations flag instances whose CPU or memory utilisation stays low, and following them is the cheapest performance review you will ever run. Custom machine types let you set vCPU and memory independently when predefined shapes waste one dimension.

Creating an Instance

# Create a new VM instance
gcloud compute instances create my-instance \
  --zone=us-central1-a \
  --machine-type=e2-medium \
  --image-family=debian-11 \
  --image-project=debian-cloud \
  --boot-disk-size=10GB \
  --tags=http-server,https-server

# List all instances
gcloud compute instances list

# SSH into the instance
gcloud compute ssh my-instance --zone=us-central1-a

Two habits are worth forming immediately. Use image families (--image-family) rather than pinned image names so new instances pick up the current patched image, and prefer OS Login and SSH through IAP over exposing port 22 to the internet or distributing SSH keys by hand.

Disks and Images

Storage choice drives both performance and failure behaviour:

  • Standard persistent disk — network-attached HDD-backed storage; cheapest, adequate for boot disks and low-I/O workloads.
  • Balanced and SSD persistent disk — network-attached flash; the right default for databases and anything latency-sensitive. Persistent disks survive instance deletion if you let them, are snapshotted for backup, and can be resized online.
  • Local SSD — physically attached to the host, fastest, and gone when the instance stops or is deleted. Use it for scratch space, caches, and temporary data you can rebuild, never as the only copy of anything.
  • Snapshots give you point-in-time, incremental backups of persistent disks; scheduled snapshots are the minimum viable backup policy. Images are the other half of the story: build a hardened golden image with your agents and baseline configuration, and stamp instances from it instead of hand-configuring each VM.

    Placement: Zones, Regions, and Instance Groups

    A single VM in one zone is a single point of failure. For anything that matters, run a managed instance group (MIG): a template-defined set of identical instances with autoscaling, autohealing health checks, and rolling updates. Zonal MIGs are simpler; regional MIGs spread instances across zones in a region so a zonal outage does not take the service down. Unmanaged groups exist for heterogeneous fleets but give up most of the automation. The decision to make early is not the group size — it is accepting that pets (individually named, hand-maintained VMs) do not scale operationally, and cattle (template-defined, replaceable instances) do.

    Networking

    Instances live in a VPC network; subnets are regional, and firewall rules control traffic by tag or service account:

    # Create a VPC network
    gcloud compute networks create my-vpc \
      --subnet-mode=custom
    
    # Create a subnet
    gcloud compute networks subnets create my-subnet \
      --network=my-vpc \
      --region=us-central1 \
      --range=10.0.0.0/24
    
    # Create firewall rules
    gcloud compute firewall-rules create allow-http \
      --network=my-vpc \
      --allow=tcp:80 \
      --source-ranges=0.0.0.0/0

    Prefer custom-mode VPCs over the auto-mode default network for production: you choose the IP ranges, which matters the day you must peer with another network or connect on-premises and discover overlapping ranges. Give instances private IPs only where possible and put them behind load balancers; a public IP on every VM is attack surface you do not need.

    Identity

    Each VM runs as a service account and receives its credentials from the metadata server. Create a dedicated service account per workload with only the roles it needs, rather than using the default Compute Engine service account, which historically carries broad editor access to the project. Scope discipline here is the difference between a compromised web server and a compromised project.

    Decision Framework

    SituationRecommendation
    Standard web or app tierManaged instance group of general-purpose (E2/N2) instances behind a load balancer
    Legacy or licensed software needing a specific OS/kernelCompute Engine — this is what it is for
    Stateful database you must operate yourselfSSD persistent disks, regional placement or replication, scheduled snapshots
    Interruptible batch or CI workersSpot VMs for a steep discount, with work designed to resume after preemption
    Containerised workload with no special host needsGKE or Cloud Run instead of hand-managed VMs
    Temporary experimentSmall E2 instance with a calendar reminder to delete it

    Implementation Checklist

  • [ ] Machine family and size chosen from measured CPU/memory needs, with right-sizing recommendations reviewed monthly
  • [ ] Instances stamped from a maintained golden image via an instance template
  • [ ] Production workloads run in managed instance groups with health checks and autoscaling bounds
  • [ ] Boot and data disks use persistent disk; local SSD only for rebuildable data
  • [ ] Scheduled snapshots enabled and a restore actually tested
  • [ ] Custom-mode VPC, private IPs by default, firewall rules scoped by service account or tag
  • [ ] Dedicated least-privilege service account per workload; default service account not used
  • [ ] SSH via IAP or OS Login; no project-wide SSH keys, no open port 22
  • [ ] Labels on every instance for ownership and cost attribution
  • Trade-offs

    Every advantage of GCE is the mirror of a cost. Full OS control means you own patching, hardening, and kernel upgrades forever. MIGs automate replacement but demand stateless or externally-stateful design; software that writes precious data to its local disk fights the model. VMs also bill while idle and size in coarse steps compared with per-request platforms, so steady low-traffic workloads pay for capacity they rarely use. And unlike a managed database or container platform, there is no control plane making your fleet consistent — drift between supposedly identical instances is your problem to detect.

    When Not to Use

  • Stateless HTTP services and APIs: Cloud Run gives you the same container with no patching, no sizing, and scale to zero.
  • Container orchestration at any real scale: GKE manages scheduling, upgrades, and node repair better than hand-rolled VM fleets.
  • Databases you have no specific reason to self-manage: Cloud SQL, AlloyDB, Firestore, or Bigtable remove backup, failover, and patching work.
  • Short-lived event handlers: Cloud Functions or Cloud Run jobs avoid a permanently running VM for sporadic work.
  • Conclusion

    Compute Engine is the foundation layer of Google Cloud: maximum control, maximum responsibility. Use it deliberately — golden images, instance templates, managed groups, least-privilege identity, tested backups — and it will run almost anything reliably. Reach for it when a workload genuinely needs a machine, and let managed platforms carry everything else.

    References

  • Compute Engine documentation
  • Why This Matters

    Understanding the business and technical context helps you make informed decisions rather than blindly following patterns.

    Trade-offs to Consider

    Every architectural decision involves trade-offs. Consider your specific requirements, team expertise, and scale when evaluating options.

    When NOT to Use This

    Knowing when a solution doesn't apply is as valuable as knowing when it does. Consider alternatives for your specific situation.

    Decision Framework

    Use this framework to evaluate whether this approach is right for your use case based on your specific constraints and requirements.

    Share this articleShare on XShare on LinkedIn

    Keep the decision frameworks coming

    One practical architecture guide a week — patterns, trade-offs, and when not to use them. No spam, unsubscribe anytime.