Moving a VM to a target group in a new availability zone
To move a VM behind an L7 load balancer to a target group in a new availability zone:
-
Enable traffic for the load balancer in the new availability zone:
Management consoleCLITerraformAPI- In the management console
, select the folder containing the load balancer. - Select Application Load Balancer.
- In the relevant load balancer row, click
and select Edit. - In the window that opens, under Allocation, enable traffic in the availability zone to move your VMs to.
- Click Save.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the
--folder-name
or--folder-id
parameter.-
View a description of the CLI command to enable 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 list
Result:
+----------------------+-----------------------+-------------+----------------+---------+ | 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
--zone
is the availability zone to which you want 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 configuration file for the L7 load balancer and, under
allocation_policy
, specify a 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>", "<subnet_ID_in_new_availability_zone>" ] } } } ...
Where:
zone_id
: Availability zones where the load balancer will receive traffic.subnet_id
: IDs of the subnets in the availability zones.
For more information about resource parameters in Terraform, see the provider documentation
. -
Apply the changes:
-
In the terminal, change to the folder where you edited the configuration file.
-
Make sure the configuration file is correct using the command:
terraform validate
If the configuration is correct, the following message is returned:
Success! The configuration is valid.
-
Run the command:
terraform plan
The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
in the terminal and press Enter.
The load balancer will start receiving traffic in the new availability zone. You can check this using the management console
or this CLI command:yc alb load-balancer get <load_balancer_name>
-
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 the load balancer to run properly, its security groups must allow outgoing connections to the IP addresses of the subnet in the new availability zone of your VMs.
-
Move the 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 the VM status as
HEALTHY
:Management consoleAPI- In the management console
, select the folder containing the load balancer. - Select Application Load Balancer.
- Select the appropriate load balancer.
- Go to
Health checks. - Expand the list of targets. Make sure that the VMs attached to the target group have the
HEALTHY
status.
Use the getTargetStates REST API method for the LoadBalancer resource or the LoadBalancerService/GetTargetStates gRPC API call.
The VM status is not identified as
HEALTHY
immediately after attaching them to the target group. This may take a few minutes depending on the backend settings.If the load balancer identifies the VM status as
UNHEALTHY
for a long time, check whether the load balancer's security groups are set up correctly. - In the management console