GCP for DevOps — Machine Types & Images
Machine Types & Images
Choosing the right machine type and image is critical for cost, performance, and reliability. GCP offers a wide range of predefined and custom machine types, plus public and custom images.
Machine Type Families
┌─────────────────────────────────────────────────────┐
│ Machine Type Families │
├───────────┬───────────┬───────────┬─────────────────┤
│ General │ Compute │ Memory │ Accelerator │
│ Purpose │ Optimized │ Optimized │ Optimized │
├───────────┼───────────┼───────────┼─────────────────┤
│ E2 │ C2 │ M1 │ A2 (GPU) │
│ N2 │ C2D │ M2 │ G2 (GPU) │
│ N2D │ C3 │ M3 │ │
│ N1 │ H3 │ │ │
│ T2D │ │ │ │
│ T2A (Arm) │ │ │ │
├───────────┼───────────┼───────────┼─────────────────┤
│ Web apps │ CI/CD │ Databases │ ML training │
│ Dev/test │ Gaming │ In-memory │ Rendering │
│ APIs │ HPC │ caching │ │
└───────────┴───────────┴───────────┴─────────────────┘
Common Machine Types for DevOps
| Machine Type | vCPUs | Memory (GB) | Use Case |
|---|---|---|---|
e2-micro |
0.25 | 1 | Free tier, tiny workloads |
e2-small |
0.5 | 2 | Small dev servers |
e2-medium |
1 | 4 | Dev/test, light services |
e2-standard-2 |
2 | 8 | General purpose |
e2-standard-4 |
4 | 16 | Build agents, CI/CD |
e2-standard-8 |
8 | 32 | Medium workloads |
n2-standard-4 |
4 | 16 | Production workloads |
c2-standard-8 |
8 | 32 | Compute-intensive builds |
# List available machine types in a zone
$ gcloud compute machine-types list --zones=us-central1-a \
--filter="name~'^e2'" \
--format="table(name,guestCpus,memoryMb)"
NAME GUEST_CPUS MEMORY_MB
e2-highcpu-16 16 16384
e2-highcpu-2 2 2048
e2-highcpu-32 32 32768
e2-highcpu-4 4 4096
e2-highcpu-8 8 8192
e2-medium 1 4096
e2-micro 2 1024
e2-small 2 2048
e2-standard-16 16 65536
e2-standard-2 2 8192
e2-standard-32 32 131072
e2-standard-4 4 16384
e2-standard-8 8 32768
Custom Machine Types
When predefined types don’t fit, create a custom machine type with exact CPU and memory.
# Create a VM with a custom machine type (6 vCPUs, 24 GB RAM)
$ gcloud compute instances create custom-vm \
--zone=us-central1-a \
--custom-cpu=6 \
--custom-memory=24GB \
--image-family=debian-12 \
--image-project=debian-cloud
# Custom with extended memory (more memory per CPU than standard)
$ gcloud compute instances create high-mem-vm \
--zone=us-central1-a \
--custom-cpu=4 \
--custom-memory=40GB \
--custom-extensions \
--image-family=debian-12 \
--image-project=debian-cloud
Public Images
GCP provides maintained images for popular operating systems.
# List available image families
$ gcloud compute images list --format="table(family,name,project)" \
--filter="family~'debian|ubuntu|centos|rocky'" | head -20
FAMILY NAME PROJECT
debian-11 debian-11-bullseye-v20260301 debian-cloud
debian-12 debian-12-bookworm-v20260301 debian-cloud
ubuntu-2004-lts ubuntu-2004-focal-v20260301 ubuntu-os-cloud
ubuntu-2204-lts ubuntu-2204-jammy-v20260301 ubuntu-os-cloud
ubuntu-2404-lts ubuntu-2404-noble-v20260301 ubuntu-os-cloud
rocky-linux-8 rocky-linux-8-v20260301 rocky-linux-cloud
rocky-linux-9 rocky-linux-9-v20260301 rocky-linux-cloud
# List Container-Optimized OS images (for running containers)
$ gcloud compute images list --filter="family:cos" \
--format="table(family,name,project)"
FAMILY NAME PROJECT
cos-stable cos-stable-109-17800-xxx cos-cloud
cos-beta cos-beta-113-18244-xxx cos-cloud
Custom Images
Create reusable images with your tools pre-installed.
# Step 1: Create a VM and install your software
$ gcloud compute instances create image-builder \
--zone=us-central1-a \
--machine-type=e2-standard-2 \
--image-family=ubuntu-2204-lts \
--image-project=ubuntu-os-cloud
# Step 2: SSH in and install software
$ gcloud compute ssh image-builder --zone=us-central1-a
# (Inside VM)
$ sudo apt-get update && sudo apt-get install -y docker.io kubectl helm
$ exit
# Step 3: Stop the VM
$ gcloud compute instances stop image-builder --zone=us-central1-a
# Step 4: Create an image from the stopped VM's disk
$ gcloud compute images create devops-base-v1 \
--source-disk=image-builder \
--source-disk-zone=us-central1-a \
--family=devops-base \
--description="Ubuntu 22.04 with Docker, kubectl, Helm"
Created [devops-base-v1].
# Step 5: Use the custom image family
$ gcloud compute instances create build-agent \
--zone=us-central1-a \
--machine-type=e2-standard-4 \
--image-family=devops-base \
--image-project=my-project
Boot Disk Types
| Disk Type | ID | IOPS (Read) | Throughput | Use Case |
|---|---|---|---|---|
| Standard PD | pd-standard |
0.75/GB | 120 MB/s | Dev/test, low cost |
| Balanced PD | pd-balanced |
6/GB | 240 MB/s | General purpose |
| SSD PD | pd-ssd |
30/GB | 480 MB/s | High performance |
| Extreme PD | pd-extreme |
Configurable | 2,400 MB/s | Databases |
# Create a VM with an SSD boot disk
$ gcloud compute instances create fast-vm \
--zone=us-central1-a \
--machine-type=e2-standard-4 \
--boot-disk-size=100GB \
--boot-disk-type=pd-ssd \
--image-family=debian-12 \
--image-project=debian-cloud
Machine Type Recommender
GCP automatically analyses VM usage and recommends right-sizing.
# View recommendations
$ gcloud recommender recommendations list \
--project=my-project \
--recommender=google.compute.instance.MachineTypeRecommender \
--location=us-central1-a \
--format="table(content.overview.resourceName,content.overview.recommendedMachineType.machineType,primaryImpact.costProjection.cost.units)"
RESOURCE_NAME RECOMMENDED_MACHINE_TYPE COST_SAVINGS
build-agent e2-standard-2 -$24/month
web-server e2-medium -$12/month
Common Mistakes
| Mistake | Why It’s Wrong | Fix |
|---|---|---|
| Using N1 for new workloads | E2/N2 are newer and cheaper | Use E2 for general, N2 for production |
| Over-provisioning machine types | Wasting money | Use Recommender to right-size |
| Not using image families | You pin to a specific image version | Use --image-family for latest |
Using pd-standard for CI/CD |
Slow disk = slow builds | Use pd-ssd or pd-balanced |
| Not creating custom images | Reinstalling software every time | Bake images with required tools |
Quick Reference
| Command | Description |
|---|---|
gcloud compute machine-types list --zones=ZONE |
List machine types |
gcloud compute images list |
List public images |
gcloud compute images create NAME --source-disk=DISK |
Create custom image |
gcloud compute images list --project=my-project |
List custom images |
--custom-cpu=N --custom-memory=MGB |
Custom machine type |
--boot-disk-type=pd-ssd |
SSD boot disk |
Next → Firewall Rules