Compute Engine & GKE
Choose between VMs, managed Kubernetes, and serverless on Google Cloud.
Theory
GCP offers a spectrum of compute, from most to least control:
- Compute Engine — VMs (IaaS); supports preemptible/Spot VMs and managed instance groups for autoscaling
- GKE — managed Kubernetes; Autopilot mode runs pods without you managing nodes
- Cloud Run — serverless containers, scale to zero, pay per request
- Cloud Functions — event-driven functions
- App Engine — managed app platform (PaaS)
The decision: full OS control → Compute Engine; container orchestration → GKE; stateless containers without cluster ops → Cloud Run.
Real-World Example
# A VM
gcloud compute instances create web1 \
--zone=europe-west1-b --machine-type=e2-small --image-family=debian-12 \
--image-project=debian-cloud
# A serverless container on Cloud Run
gcloud run deploy myapp --image=gcr.io/my-project/myapp --region=europe-west1 Hands-On Exercise
- Map three workloads to Compute Engine, GKE, and Cloud Run.
- Explain what a managed instance group adds over a single VM.
- Describe when Cloud Run is preferable to GKE.
- What is a preemptible/Spot VM and when would you use one?
Cheat Sheet▾
| Service | Use |
|---|---|
| Compute Engine | VMs, full control (IaaS) |
| Managed instance group | Autoscaling VMs |
| GKE (Autopilot) | Managed Kubernetes |
| Cloud Run | Serverless containers, scale to zero |
| Cloud Functions | Event-driven functions |
| App Engine | Managed app platform |
Common Interview Questions▾
When would you choose Cloud Run over GKE?
When you have stateless containers and want serverless scaling (including to zero) without managing a Kubernetes cluster. GKE fits when you need full orchestration control, complex networking, or stateful workloads.
What is a managed instance group?
A group of identical Compute Engine VMs that supports autoscaling, autohealing, and rolling updates behind a load balancer — GCP’s equivalent of an autoscaling group.
Official Documentation
📝 My notes on this topic
Auto-saves as you type