You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Instance templates and instance groups are foundational building blocks for scalable, resilient architectures on Compute Engine. Instance templates define a VM configuration that can be reused, while instance groups manage collections of VM instances as a single unit.
An instance template is a resource that defines the properties of a VM instance — machine type, boot disk image, network configuration, labels, metadata, service account, and more. Templates are immutable — once created, they cannot be modified. To change a configuration, you create a new template.
gcloud compute instance-templates create web-template-v1 \
--machine-type=e2-standard-2 \
--image-family=debian-12 \
--image-project=debian-cloud \
--boot-disk-size=20GB \
--boot-disk-type=pd-balanced \
--tags=http-server,https-server \
--metadata=startup-script='#!/bin/bash
apt-get update && apt-get install -y nginx' \
--service-account=web-sa@my-project.iam.gserviceaccount.com \
--scopes=cloud-platform \
--labels=app=web,env=production
| Property | Description |
|---|---|
| Immutable | Cannot be edited after creation — create a new version instead |
| Global resource | Not tied to a specific zone or region |
| Reusable | Can be used by multiple instance groups |
| Versionable | Use a naming convention like web-template-v1, web-template-v2 |
| No cost | Templates themselves are free — you only pay for VMs created from them |
Regional instance templates restrict usage to a specific region and can reference regional resources (e.g., regional disks, subnet):
gcloud compute instance-templates create web-template-regional \
--region=europe-west2 \
--machine-type=e2-standard-2 \
--image-family=debian-12 \
--image-project=debian-cloud \
--subnet=projects/my-project/regions/europe-west2/subnetworks/web-subnet
An instance group is a collection of VM instances that are managed as a single entity. There are two types:
| Type | Description |
|---|---|
| Managed Instance Group (MIG) | Automatically creates and manages identical VMs from an instance template |
| Unmanaged Instance Group | A collection of heterogeneous existing VMs grouped for load balancing |
Managed instance groups are the recommended approach for most production workloads because they provide autoscaling, autohealing, rolling updates, and integration with load balancers.
Unmanaged instance groups are simply a way to group existing VMs for use with a load balancer. They do not provide autoscaling, autohealing, or rolling updates. Each VM can have a different machine type, image, and configuration.
# Create an unmanaged instance group
gcloud compute instance-groups unmanaged create legacy-group \
--zone=europe-west2-a
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.