Creating new instance template from another template and overriding the container image

88 Views Asked by At

Is it possible in Google cloud engine to clone an existing instance template AND override the container image in the clone ?

the concrete situation is as follows:

We have a GCP project that consists of several gcp components including a managed instances group (MIG) which references an intance template.

In order to deploy (by a separeted CI/CD pipeline) new container image versions in the MIG we woud like (if possible) to clone the existing instance template, just overwrite the container-image in the clone and update the MIG with the clone.

Hence the questions:
is it possible to create an instance template by cloning an existing one and just overriding the container-image in the clone (without specifying all the other template settings)?
What is the best way to deploy a new container-image version in an existing MIG without creating a new instance template from scratch?

Thanks in advance for any answer!

1

There are 1 best solutions below

1
Dion V On

As per GAllan, they use an equivalent version of the cli:

gcloud compute instance-templates create-with-container $myTemplateName \
--container-image=$myrepo/$myimage \
--boot-disk-size 10GB --boot-disk-device-name exchange-template \
--boot-disk-type=pd-balanced  --project=$myproject \
--machine-type=e2-medium \
--network-interface=network=default,network-tier=PREMIUM,address="" \
--maintenance-policy=MIGRATE \
--service-account=$myServiceAccount --scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append \
--tags=http-server,https-server,allowport8080 \
--container-restart-policy=always \
--no-shielded-secure-boot --shielded-vtpm --shielded-integrity-monitoring

Removing the --create-disk option and replacing that with some boot disk options.

The cmd also needed the addition of ',address=""' to the network interface option to get an external ip address.

-tags may differ based on your firewall tags. The --boot-disk-device-name can be any name.