Task 3. Configure instance templates and create instance groups
A managed instance group uses an instance template to create a group of identical instances. Use these to create the backends of the internal load balancer.
On the Navigation menu (Navigation menu), click Compute Engine -- Instance templates.
Click Create instance template.
For Name, type instance-template-1
Under Machine configuration, For Series, Select N1.
Machine type f1-micro(1 vCPU).
Click Management, security, disks, networking, sole tenancy.
Click Management.
Under Metadata, specify the following:
Key Value
startup-script-url gs://cloud-training/gcpnet/ilb/startup.sh
The startup-script-url specifies a script that is executed when instances are started. This script installs Apache and changes the welcome page to include the client IP and the name, region, and zone of the VM instance. You can explore this script here.
Click Networking.
For Network interfaces, specify the following, and leave the remaining settings as their defaults:
Property Value (type value or select option as specified)
Network my-internal-app
Subnet subnet-a
Network tags backend-service
External IP None
The network tag backend-service ensures that the firewall rule to allow traffic from any sources in the 10.10.0.0/16 subnet and the Health Check firewall rule applies to these instances.
Click Create. Wait for the instance template to be created.
Create another instance template for subnet-b by copying instance-template-1:
Select the instance-template-1 and click Copy.
Click Management, security, disks, networking, sole tenancy.
Click Networking.
For Network interfaces, select subnet-b as the Subnet.
Click Create.
Create the managed instance groups
Create a managed instance group in subnet-a (us-central1-a) and subnet-b (us-central1-b).
On the Navigation menu (Navigation menu), click Compute Engine -- Instance groups.
Click Create Instance group.
Specify the following, and leave the remaining settings as their defaults:
Property Value (type value or select option as specified)
Name instance-group-1
Location Single zone
Region us-central1
Zone us-central1-a
Instance template instance-template-1
Autoscaling -- metrics type (Click the pencil edit icon) CPU utilization
Target CPU utilization 80, click Done.
Cool-down period 45
Minimum number of instances 1
Maximum number of instances 5
Managed instance groups offer autoscaling capabilities that allow you to automatically add or remove instances from a managed instance group based on increases or decreases in load. Autoscaling helps your applications gracefully handle increases in traffic and reduces cost when the need for resources is lower. Just define the autoscaling policy, and the autoscaler performs automatic scaling based on the measured load.
Click Create.
Repeat the same procedure for instance-group-2 in us-central1-b:
Click Create Instance group.
Specify the following, and leave the remaining settings as their defaults:
Property Value (type value or select option as specified)
Name instance-group-2
Location Single zone
Region us-central1
Zone us-central1-b
Instance template instance-template-2
Autoscaling -- metric type (Click the pencil edit icon) CPU utilization
Target CPU utilization 80, click Done.
Cool-down period 45
Minimum number of instances 1
Maximum number of instances 5
Click Create.
Verify the backends
Verify that VM instances are being created in both subnets and create a utility VM to access the backends' HTTP sites.
On the Navigation menu, click Compute Engine -- VM instances. Notice two instances that start with instance-group-1 and instance-group-2.
These instances are in separate zones, and their internal IP addresses are part of the subnet-a and subnet-b CIDR blocks.
Click Create Instance.
Specify the following, and leave the remaining settings as their defaults:
Property Value (type value or select option as specified)
Name utility-vm
Region us-central1
Zone us-central1-f
Series N1
Machine type f1-micro (1 vCPU)
Boot disk Debian GNU/Linux 10 (buster)
Click Management, security, disks, networking, sole tenancy.
Click Networking.
For Network interfaces, click the pencil icon to edit.
Specify the following, and leave the remaining settings as their defaults:
Property Value (type value or select option as specified)
Network my-internal-app
Subnetwork subnet-a
Primary internal IP Ephemeral (Custom)
Custom ephemeral IP address 10.10.20.50
External IP None
Click Done.
Click Create.
Note that the internal IP addresses for the backends are 10.10.20.2 and 10.10.30.2.
If these IP addresses are different, replace them in the two curl commands below