How can an autoscaling managed instance group be added to a target pool?
It's easy enough to add existing instances to a target pool via
$ gcloud compute target-pools create mypool --region us-central1
$ gcloud compute target-pools add-instances mypool \
--instances existing-instance1 existing-instance2 --zone us-central1-b
However, I want all the instances that appear in my autoscaling group to automatically be added to my target pool.
There are four different types of resources in your setup:
To make sure that all the instances in your managed instance group (that is all the instances in your autoscaling group) are automatically in your target pool, you need to tell the managed instance group about the target pool. As @Faizan correctly mentioned, the command to do it is:
gcloud compute instance-groups managed set-target-pools instance-group-name --target-pools your-target-pool
The help page for this command seems more useful than the online documentation:
gcloud compute instance-groups managed set-target-pools --help
Please note that this help page seems to be out of date though. Setting a new target pool now DOES apply to existing instances in the group (when using the API version v1
or later). It was not the case in the beta versions (v1beta2
).