Creating an Application Load Balancer target group
Create VMs in the working folder by following this guide.
To create a target group:
- In the management console
, select the folder to create your target group in. - In the list of services, select Application Load Balancer.
- In the left-hand panel, select
Target groups. - Click Create target group.
- Enter a name and description for the target group.
- Under Targets, select a VM from the list or add the target manually:
-
In the IP address field, specify the target's IP and select the subnet.
-
Optionally, 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 Create.
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 create a target group:
yc alb target-group create --help
-
Run the following command, specifying the target group name, subnet name, and internal IP addresses of the VM as parameters:
yc alb target-group create \ --name <target_group_name> \ --target subnet-name=<subnet_name>,ip-address=<VM_1_internal_IP_address> \ --target subnet-name=<subnet_name>,ip-address=<VM_2_internal_IP_address> \ --target subnet-name=<subnet_name>,ip-address=<VM_3_internal_IP_address>
Result:
id: a5d751meibht******** name: <target_group_name> folder_id: aoerb349v3h4******** targets: - ip_address: <VM_1_internal_IP_address> subnet_id: fo2tgfikh3he******** - ip_address: <VM_2_internal_IP_address> subnet_id: fo2tgfikh3he******** - ip_address: <VM_3_internal_IP_address> subnet_id: fo2tgfikh3he******** created_at: "2021-02-11T11:16:27.770674538Z
You can also create a target group with target resources residing 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 addresses as parameters:
yc alb target-group create \ --name <target_group_name> \ --target private-ip-address=true,ip-address=<resource_1_IPv4_private_address> \ --target private-ip-address=true,ip-address=<resource_2_IPv4_private_address> \ --target private-ip-address=true,ip-address=<resource_3_IPv4_private_address>
Result:
id: ds7s2dld2usr******** name: <target_group_name> folder_id: aoerb349v3h4******** targets: - ip_address: <resource_1_IPv4_private_address> private_ipv4_address: true - ip_address: <resource_2_IPv4_private_address> private_ipv4_address: true - ip_address: <resource_3_IPv4_private_address> private_ipv4_address: true created_at: "2023-07-25T08:55:14.172526884Z"
Terraform
For more information about the provider resources, see the documentation on the Terraform
If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
If you don't have Terraform, install it and configure the Yandex Cloud provider.
-
In the Terraform configuration file, describe the parameters of the resource to create:
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>" } }
Where
yandex_alb_target_group
specifies the target group parameters:name
: Target group name.target
: Target resource parameters:subnet_id
: ID of the subnet hosting the VM. You can get the list of available subnets using theyc vpc subnet list
CLI command.ip_address
: VM internal IP address. You can get the list of internal IP addresses using the following CLI command:yc vpc subnet list-used-addresses --id <subnet_ID>
.
You can also create a target group with target resources residing 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 = "<resource_1_IPv4_private_address>" } target { private_ipv4_address = true ip_address = "<resource_2_IPv4_private_address>" } target { private_ipv4_address = true ip_address = "<resource_3_IPv4_private_address>" } }
Where
yandex_alb_target_group
specifies the target group parameters:name
: Target group name.target
: Target resource parameters:private_ipv4_address
: Indicates that the IP address is outside Virtual Private Cloud.ip_address
: Private IPv4 address of the resource. 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 properties, see the Terraform provider documentation . -
Create resources:
-
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.
Terraform will create all the required resources. You can check the new resources using the management console
or this CLI command:yc alb target-group list
-
Use the create REST API method for the TargetGroup resource or the TargetGroupService/Create gRPC API call.