An instance template with more than one NIC obviously can't be created in the GCP web console. But it could easily be achieved using the gcloud
CLI with consecutive --network-interface
options.
gcloud compute --project=YOUR_PROJECT instance-templates create multi-nic-vm-template --machine-type=e2-micro --network-interface=subnet=projects/YOUR_PROJECT/regions/europe-west3/subnetworks/my-subnet-1,no-address --network-interface=subnet=projects/YOUR_PROJECT/regions/europe-west3/subnetworks/my-subnet-2,no-address --maintenance-policy=MIGRATE --image=my-image-1 --image-project=YOUR_PROJECT --boot-disk-size=10GB --boot-disk-type=pd-standard --boot-disk-device-name=instance-template-1 --no-shielded-secure-boot --shielded-vtpm --shielded-integrity-monitoring --reservation-affinity=any --tags=allow-health-check
In this example I specified two subnets that belong to different VPC's.
Assumptions for the example:
- ID of the project:
YOUR_PROJECT
- region:
europe-west-3
- subnet for first network interface:
my-subnet-1
- subnet for second network interface:
my-subnet-2
- both NIC's should not have a public IP (
no_address
) - template created from image:
my-image-1
- a firewall rule tagged with
allow-health-check
is in place for the VPC network assigned to the first NIC to allow traffic for TCP port 80 from sources130.211.0.0/22
and35.191.0.0/16
to enable GCP health checks for auto-scaling instance groups (see health-check firewall rules)
For more details refer to the documentation of the network-interface option.