Moving a VM to a target group in a new availability zone
To move an L7 load balancer backend VM to a target group in a new availability zone:
-
Enable load balancer traffic in the new availability zone:
Management consoleCLITerraformAPI- In the management console
, select the folder with your load balancer. - Select Application Load Balancer.
- Click
next to the load balancer you need, then select Edit. - In the window that opens, under Allocation, enable traffic in the availability zone where you plan to move your VM.
- Click Save.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the
yc config set folder-id <folder_ID>command. You can also set a different folder for any specific command using the--folder-nameor--folder-idparameter.-
See the description of the CLI command for enabling load balancer traffic:
yc application-load-balancer load-balancer enable-traffic --help -
Get a list of all L7 load balancers in the default folder:
yc application-load-balancer load-balancer listResult:
+----------------------+-----------------------+-------------+----------------+---------+ | ID | NAME | REGION ID | LISTENER COUNT | STATUS | +----------------------+-----------------------+-------------+----------------+---------+ | ds732hi8pn9n******** | sample-alb1 | ru-central1 | 1 | ACTIVE | | f3da23i86n2v******** | sample-alb2 | ru-central1 | 1 | ACTIVE | +----------------------+-----------------------+-------------+----------------+---------+ -
Enable traffic in the new availability zone:
yc application-load-balancer load-balancer enable-traffic <load_balancer_name> \ --zone <availability_zone>Where
--zoneis the availability zone where you plan to move your VMs.Result:
id: ds7pmslal3km******** name: sample-alb1 folder_id: b1gmit33ngp3******** status: ACTIVE region_id: ru-central1 network_id: enpn46stivv8******** allocation_policy: locations: - zone_id: ru-central1-a subnet_id: e9bavnqlbiuk******** disable_traffic: true - zone_id: ru-central1-b subnet_id: e2lgp8o00g06******** - zone_id: ru-central1-d subnet_id: b0cv501fvp13******** log_group_id: ckgah4eo2j0r******** security_group_ids: - enpdjc5bitmj******** created_at: "2023-08-09T08:34:24.887765763Z" log_options: {}
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
-
Open the Terraform L7 load balancer configuration file and, under
allocation_policy, specify the new availability zone and the ID of the previously created subnet:... allocation_policy { location { zone_id = [ "<previous_availability_zone>", "<new_availability_zone>" ] subnet_id = [ "<subnet_ID_in_previous_availability_zone>", "<ID_of_subnet_in_new_availability_zone>" ] } } } ...Where:
zone_id: Availability zones where the load balancer will receive traffic.subnet_id: IDs of the subnets in these availability zones.
For more information about resource properties in Terraform, see the relevant provider documentation.
-
Apply the changes:
-
In the terminal, go to the directory where you edited the configuration file.
-
Make sure the configuration file is correct using this command:
terraform validateIf the configuration is correct, you will get this message:
Success! The configuration is valid. -
Run this command:
terraform planYou will see a detailed list of resources. No changes will be made at this step. If the configuration contains any errors, Terraform will show them.
-
Apply the changes:
terraform apply -
Type
yesand press Enter to confirm the changes.
The load balancer will start receiving traffic in the new availability zone. You can check this in the management console
or using this CLI command:yc alb load-balancer get <load_balancer_name>Timeouts
The Terraform provider limits operations with Application Load Balancer load balancers to 10 minutes.
Operations in excess of this time will be interrupted.
How do I modify these limits?
Add the
timeoutssection to the load balancer description, e.g.:resource "yandex_alb_load_balancer" "<load_balancer_name>" { ... timeouts { create = "60m" update = "60m" delete = "60m" } } -
Use the update REST API method for the LoadBalancer resource or the LoadBalancerService/Update gRPC API call.
- In the management console
-
Set up a security group for the load balancer if needed. For proper load balancer operation, its security groups must allow outbound connections to the subnet addresses in your VM’s new availability zone.
-
Move your VM to the new availability zone.
-
Add new VMs to the load balancer's target group and delete the old ones.
-
Make sure the load balancer identifies your VM status as
HEALTHY:Management consoleAPI- In the management console
, select the folder with your load balancer. - Select Application Load Balancer.
- Select the load balancer you need.
- Navigate to the
Health checks tab. - Expand the list of targets. Make sure the target group VMs have the
HEALTHYstatus.
Use the getTargetStates REST API method for the LoadBalancer resource or the LoadBalancerService/GetTargetStates gRPC API call.
The load balancer will not recognize a VM status as
HEALTHYimmediately after adding it to the target group. This may take a few minutes depending on your backend settings.If the load balancer consistently identifies your VM status as
UNHEALTHYover an extended period, check its security group configuration. - In the management console