Editing a target group
You can add or remove VMs from a target group.
Add a VM to a target group
To add a VM to a target group:
- In the management console
, select the folder where the target group was created. - Select Application Load Balancer.
- In the left-hand panel, select
Target groups. - Click the name of the target group you need.
- Click Add targets.
- Select a VM from the list or add the target manually:
-
In the IP address field, specify the target's IP address and select the subnet.
-
(Optional) If the target's IP address does not belong to Yandex Virtual Private Cloud, select Outside VPC.
For example, specify a private IPv4 address belonging to your data center connected to Yandex Cloud through Yandex Cloud Interconnect. The IP address must be within the RFC 1918 private ranges
. For more information, see Subnets. -
Click Add target resource.
-
- Click Add.
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.
-
See the description of the CLI command to add resources to target groups:
yc alb target-group add-targets --help
-
Run the command, specifying the target group name, subnet name, and the internal IP address of the VM:
yc alb target-group add-targets \ --name <target_group_name> \ --target subnet-name=<subnet_name>,ip-address=<VM_internal_IP_address>
Result:
done (1s) id: a5d751meibht******** name: <target_group_name> targets: ... - ip_address: <VM_internal_IP_address> subnet_id: fo2tgfikh3he******** created_at: "2021-02-11T11:16:27.770674538Z"
You can also add targets to a target group that reside outside Yandex Virtual Private Cloud, e.g., in your data center connected to Yandex Cloud via Yandex Cloud Interconnect. The IP addresses of targets must be within the RFC 1918 private ranges
. For more information, see Subnets.Run the following command, specifying the target group name and private IPv4 address of the target as parameters:
yc alb target-group add-targets \ --name <target_group_name> \ --target private-ip-address=true,ip-address=<target_private_IPv4_address>
Result:
done (1s) id: a5d751meibht4ev26... name: <target_group_name> targets: ... - ip_address: <target_private_IPv4_address> private_ipv4_address: true created_at: "2023-07-25T08:55:14.172526884Z"
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the documentation on the Terraform
If you don't have Terraform, install it and configure the Yandex Cloud provider.
-
Open the Terraform configuration file and add the target section with
target
parameters to the fragment describing the target group:resource "yandex_alb_target_group" "foo" { name = "<target_group_name>" target { subnet_id = "<subnet_ID>" ip_address = "<VM_1_internal_IP_address>" } target { subnet_id = "<subnet_ID>" ip_address = "<VM_2_internal_IP_address>" } target { subnet_id = "<subnet_ID>" ip_address = "<VM_3_internal_IP_address>" } target { subnet_id = "<subnet_ID>" ip_address = "<VM_4_internal_IP_address>" } }
Where
yandex_alb_target_group
specifies the target group parameters:name
: Target group name.target
: Target parameters:subnet_id
: ID of the subnet hosting the VM. You can get a list of available subnets using the CLI command:yc vpc subnet list
.ip_address
: VM internal IP address. You can get a list of internal IP addresses using the following CLI command:yc vpc subnet list-used-addresses --id <subnet_ID>
.
You can also add targets to a target group that reside outside Yandex Virtual Private Cloud, e.g., in your data center connected to Yandex Cloud via Yandex Cloud Interconnect:
resource "yandex_alb_target_group" "foo" { name = "<target_group_name>" target { private_ipv4_address = true ip_address = "<private_IPv4_address_of_target_1>" } target { private_ipv4_address = true ip_address = "<private_IPv4_address_of_target_2>" } target { private_ipv4_address = true ip_address = "<private_IPv4_address_of_target_3>" } }
Where
yandex_alb_target_group
specifies the target group parameters:name
: Target group name.target
: Target parameters:private_ipv4_address
: Parameter indicating that the IP is outside Virtual Private Cloud.ip_address
: Private IPv4 address of the target. The IP addresses must be within the RFC 1918 private ranges . For more information, see Subnets.
For more information about the
yandex_alb_target_group
resource parameters, see the Terraform 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.
You can check the target group update using the management console
or this CLI command:yc alb target-group get --name <target_group_name>
-
Use the addTargets REST API method for the TargetGroup resource or the TargetGroupService/AddTargets gRPC API call.
Remove a VM from a target group
To remove a VM from a target group:
- In the management console
, select the folder where the target group was created. - Select Application Load Balancer.
- In the left-hand panel, select
Target groups. - Click the name of the target group you need.
- To the right of the VM, click
and select Delete. - In the window that opens, click Delete.
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 for removing resources from a target group:
yc alb target-group remove-targets --help
-
Run the following command with the target group name, subnet name, and internal IP address of the VM:
yc alb target-group remove-targets \ --name <target_group_name> \ --target subnet-name=<subnet_name>,ip-address=<VM_internal_IP_address>
Result:
id: ds7urm6dn6cm******** name: <target_group_name> folder_id: aoerb349v3h4******** created_at: "2023-06-10T13:14:55.239094324Z"
To remove a target residing outside Virtual Private Cloud, e.g., in your data center connected to Yandex Cloud via Cloud Interconnect, from your target group, run the following command, specifying the target group name and the private IPv4 address of the target:
yc alb target-group remove-targets \ --name <target_group_name> \ --target private-ip-address=true,ip-address=<target_private_IPv4_address>
Result:
id: ds7urm6dn6cm******** name: <target_group_name> folder_id: aoerb349v3h4******** created_at: "2023-06-10T13:14:55.239094324Z"
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the documentation on the Terraform
If you don't have Terraform, install it and configure the Yandex Cloud provider.
-
Open the Terraform configuration file and delete the
target
section with the IP address of the VM to be removed in the fragment describing the target group:Sample target group description in the Terraform configuration:
resource "yandex_alb_target_group" "foo" { name = "<target_group_name>" target { subnet_id = "<subnet_ID>" ip_address = "<VM_1_internal_IP_address>" } target { subnet_id = "<subnet_ID>" ip_address = "<VM_2_internal_IP_address>" } target { subnet_id = "<subnet_ID>" ip_address = "<VM_3_internal_IP_address>" } }
For more information about the
yandex_alb_target_group
resource parameters, see the Terraform 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.
You can check the target group update using the management console
or this CLI command:yc alb target-group get --name <target_group_name>
-
Use the removeTargets REST API method for the TargetGroup resource or the TargetGroup/RemoveTargets gRPC API call.