Create a target group

    To create a new target group:

    1. Open the Load Balancer section in the folder where you want to create a target group.

    2. Open the Target group tab.

    3. Click Create target group.

    4. Enter the name of the target group.

      The name must be unique within the folder. The name may contain lowercase Latin letters, numbers, and hyphens. The first character must be a letter. The last character can't be a hyphen. The maximum length of the name is 63 characters.

    5. Select the VMs to add to the target group.

    6. Click Create target group.

    If you don't have the Yandex.Cloud command line interface yet, install 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. See the description of the CLI's create target group command:

      $ yc load-balancer target-group create --help
    2. Get a list of VMs:

      $ yc compute instance list
      |          ID          |    NAME    |    ZONE ID    | STATUS  |
      | fhmajnpl7cvhl6v1s12i | test-vm-1  | ru-central1-a | RUNNING |
      | fhmajv6f27n0a4a1sbml | test-vm-2  | ru-central1-a | RUNNING |
    3. Choose the ID of the VM to add to a target group and get information about it:

      $ yc compute instance get fhmajnpl7cvhl6v1s12i
        subnet_id: e9bhjah6j3k7e6v8t5fa
    4. Create a target group and add the appropriate VM to it as a target by specifying the subnet-id and address of the VM in the --target flag:

      $ yc load-balancer target-group create \
      --region-id ru-central1 \
      --name test-tg-1 \
      --target subnet-id=e9bhjah6j3k7e6v8t5fa,address=

    You can create a new target group using the create API method.

    Once the target group has been created, add targets that the load will be distributed across. You can use the [addTargets](../ api-ref/TargetGroup/addTargets) method to add targets to a group.