Yandex Cloud
  • Services
  • Solutions
  • Why Yandex Cloud
  • Blog
  • Pricing
  • Documentation
  • Contact us
Get started
Language / Region
Yandex project
© 2023 Intertech Services AG
Yandex Application Load Balancer
  • Getting started
  • Step-by-step guides
    • All guides
    • Target groups
      • Creating target group
      • Editing target group
      • Deleting target group
    • Backend groups
    • HTTP routers
    • L7 load balancers
    • Tools for Managed Service for Kubernetes
  • Tutorials
  • Concepts
  • Tools for Managed Service for Kubernetes
  • Access management
  • Pricing policy
  • API reference
  • Managed Service for Kubernetes tool references
  • Log reference
  1. Step-by-step guides
  2. Target groups
  3. Editing target group

Editing target group

Written by
Yandex Cloud
  • Add a VM to a target group
  • Remove a VM from a target group

You can add or remove instances from a target group.

Add a VM to a target group

To add a VM to a target group:

Management console
CLI
Terraform
API
  1. In the management console, select the folder where the target group was created.
  2. Select Application Load Balancer.
  3. On the left-hand panel, select Target groups.
  4. Click on the name of the group you need.
  5. Click Add targets.
  6. Select the appropriate VMs and click Add.

If you don't 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.

  1. View a description of the CLI command for adding resources to target groups:

    yc alb target-group add-targets --help
    
  2. Run the command, specifying the target group name, subnet name, and internal IP address of the VM:

    yc alb target-group --name <target group name> add-targets \
      --target subnet-name=<subnet name>,ip-address=<VM's internal IP address>
    

    Result:

    done (1s)
    id: a5daisped2unjsnbjhhl
    name: test-tg
    ...
    - ip_address: 10.128.0.32
      subnet_id: blt6pca13je62sqvjq5b
    created_at: "2021-02-11T11:16:27.770674538Z"
    

With Terraform, you can quickly create a cloud infrastructure in Yandex Cloud and manage it by configuration files. They store the infrastructure description in HashiCorp Configuration Language (HCL). Terraform and its providers are distributed under the Mozilla Public License.

For more information about the provider resources, see the documentation on the Terraform site or mirror site.

If you change the configuration files, Terraform automatically determines which part of your configuration is already deployed and what should be added or removed.

For more information about Terraform, see our documentation.

  1. 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   = "<internal IP address of VM 1>"
      }
    
      target {
        subnet_id    = "<subnet ID>"
        ip_address   = "<internal IP address of VM 2>"
      }
    
      target {
        subnet_id    = "<subnet ID>"
        ip_address   = "<internal IP address of VM 3>"
      }
    
      target {
        subnet_id    = "<subnet ID>"
        ip_address   = "<internal IP address of VM 4>"
      }
    }
    

    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's internal IP. You can get a list of internal IP addresses using the CLI command: yc vpc subnet list-used-addresses --id <subnet ID>.

    For more information about the yandex_alb_target_group resource parameters, see the Terraform provider documentation.

  2. Apply the changes:

    1. In the terminal, change to the folder where you edited the configuration file.

    2. 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.
      
    3. 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.

    4. Apply the configuration changes:

      terraform apply
      
    5. Confirm the changes: type yes in the terminal and press Enter.

    You can verify that the target group has been updated in the management console or using the following 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:

Management console
CLI
Terraform
API
  1. In the management console, select the folder where the target group was created.
  2. Select Application Load Balancer.
  3. On the left-hand panel, select Target groups.
  4. Click on the name of the group you need.
  5. Select the VM and click Delete at the bottom of the screen.
  6. In the window that opens, click Delete.

If you don't 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.

  1. View a description of the CLI command for removing resources from a target group:

    yc alb target-group remove-targets --help
    
  2. Run the following command with the target group name, subnet name, and internal IP address of the VM:

    yc alb target-group --name <target group name> \
    remove-targets --target subnet-name=<subnet name>,ip-address=<VM's internal IP address>
    

    Result:

    done (1s)
    id: a5daisped2unjsnbjhhl
    name: test-tg
    ...
    - ip_address: 10.129.0.30
      subnet_id: blt6pcatjje62sqvjq5b
    created_at: "2021-02-11T11:16:27.770674538Z"
    

With Terraform, you can quickly create a cloud infrastructure in Yandex Cloud and manage it by configuration files. They store the infrastructure description in HashiCorp Configuration Language (HCL). Terraform and its providers are distributed under the Mozilla Public License.

For more information about the provider resources, see the documentation on the Terraform site or mirror site.

If you change the configuration files, Terraform automatically determines which part of your configuration is already deployed and what should be added or removed.

For more information about the Terraform, see our documentation.

  1. 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   = "<internal IP address of VM 1>"
      }
    
      target {
        subnet_id    = "<subnet ID>"
        ip_address   = "<internal IP address of VM 2>"
      }
    
      target {
        subnet_id    = "<subnet ID>"
        ip_address   = "<internal IP address of VM 3>"
      }
    }
    

    For more information about the yandex_alb_target_group resource parameters, see the Terraform provider documentation.

  2. Apply the changes:

    1. In the terminal, change to the folder where you edited the configuration file.

    2. 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.
      
    3. 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.

    4. Apply the configuration changes:

      terraform apply
      
    5. Confirm the changes: type yes in the terminal and press Enter.

    You can verify that the target group has been updated in the management console or using the following 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.

Was the article helpful?

Language / Region
Yandex project
© 2023 Intertech Services AG
In this article:
  • Add a VM to a target group
  • Remove a VM from a target group