I'm trying to automate a process I'm currently doing manually. I have an TCP load balancer, and I need to change the instance group it's directing the traffic to. When doing it manually, it's pretty simple and straight forward, I just edit the LB setting in the web interface, and under "Backend configuration" switch between the instance groups: Manually changing via web interface
I'm trying to replicate the process using gcloud, using the following command:
gcloud compute backend-services update-backend BACKEND-SERVICE-NAME --instance-group=INSTANCE-GROUP-NAME --instance-group-region=us-east4 --project=PROJECT
But get the following error:
(gcloud.compute.backend-services.update-backend) At least one property must be modified.
In the documentation of gcloud compute backend-services update-backend it says:
To add, remove, or swap backends, use the gcloud compute backend-services remove-backend and gcloud compute backend-services add-backend commands.
Does that mean it's not possible to replicate the process using gcloud? I have first to remove the instance group, and then add the new one, it will mean a partial traffic loss from LB. How can I do the swap between backends without any downtime, as possible doing so via the web GUI?
gcloud compute backend-services update-backend updates attributes of a backend that is already associated with a backend service as per the GCP official documentation. It can not remove instance group or add new instance group to the LB backend service. To do that the following commands would help you to achieve this scenario but as you mentioned there will be a traffic loss from LB.
gcloud compute backend-services remove-backend BACKEND_SERVICE_NAME --instance-group=INSTANCE_GROUP --instance-group-zone=INSTANCE_GROUP_ZONE --region=REGION --project=PROJECT
gcloud compute backend-services add-backend BACKEND_SERVICE_NAME --instance-group=INSTANCE_GROUP --instance-group-zone=INSTANCE_GROUP_ZONE --region=REGION --project=PROJECT
gcloud compute backend-services list.
To avoid down time you can use the rolling update feature in the GCE instance group. This document explains how to Automatically roll out updates to instances in a MIG.