user14717
user14717

Reputation: 5181

How to add managed instance group to target pool?

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.

Upvotes: 4

Views: 2502

Answers (2)

Grzenio
Grzenio

Reputation: 36689

There are four different types of resources in your setup:

  • instance is a virtual machine
  • a target pool is a pool of instances used only for the purpose of L3 (e.g. IP) level network load balancing
  • managed instance group is a group of instances, used among others as a target for your autoscaler
  • autoscaler looks at a managed instance group and adds/deletes instances in this group as appropriate according to load (and your policy)

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).

Upvotes: 4

Faizan
Faizan

Reputation: 1967

You can use gcloud compute instance-groups managed set-target-pools command to set the target pool for an existing manged instance group. You can refer to this link for more information.

Upvotes: 5

Related Questions