Creating a fixed-size instance group with a network load balancer

    You can create a group of fixed-size instances along with a network load balancer that will evenly distribute the load across cloud resources. For more information, see Network load balancer in the Yandex Load Balancer documentation.

    Warning

    When creating a group, keep the limits in mind. Not to disrupt the component Instance Groups, do not update or delete manually created resources: target group Load Balancer, virtual machines and disks. To do this, update or delete the instance group.

    By default, all operations in Instance Groups are performed on behalf of a service account. If you don't have a service account, create one.

    To create an instance group with a load balancer:

    1. In the management console, select the folder where you want to create an instance group.

    2. Select Yandex Compute Cloud.

    3. On the Virtual machines page, go to the Instance groups tab.

    4. Click Create group.

    5. In the Basic parameters section:

      • Enter the name and description of the 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.

      • Select a service account from the list or create a new one. Service accounts must have the editor role to create, update, and delete instances in a group.

    6. In the Allocation section, select the desired availability zones. Group instances may reside in different availability zones and regions. Learn more about Yandex.Cloud geography.

    7. In the Instance template section, click Set to set the basic instance configuration:

      • Select a public image.

      • In the Disks section:

        • Select the disk type.

        • Specify the disk size.

          To add more disks, click Add disk.

      • Under Computing resources:

      • Under Network settings:

        • Select the cloud network and the subnet. If the necessary subnet is not in the list, create it.

        • Specify if a public IP address is required.

      • In the Access section, specify the data required to access the VM:

        • Enter the username in the Login field.

        • Under SSH key, paste the contents of the public key file. Create a key pair for connecting to an instance over SSH on your own.

      • Click Add.

    8. Under Allow when creating and updating, specify:

      • The number of instances that can be additionally allocated in order to expand the group size.

      • The number of instances the group size can be reduced by.

      • The number of instances that can be created simultaneously.

      • The number of instances that can be deleted simultaneously.

        For more information, see Deployment policy.

    9. In the Scalability section:

      • Select the scaling type. Currently, you can only create fixed-size groups.

      • Specify the group size.

    10. Under Integration with Load Balancer, toggle the switch to the right of the Create target group field.

    11. Enter a custom name and description of the target group.

    12. Click Create.

    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. View a description of the create instance group command in the CLI:

      $ yc compute instance-group create --help
      
    2. Check whether there are networks in the folder:

      $ yc vpc network list
      

      If there aren't any, create one.

    3. Select one of the public images (for example, CentOS 7).

      To get a list of available images, run the following command:

      $ yc compute image list --folder-id standard-images
      +----------------------+-------------------------------------+--------------------------+----------------------+--------+
      |          ID          |                NAME                 |          FAMILY          |     PRODUCT IDS      | STATUS |
      +----------------------+-------------------------------------+--------------------------+----------------------+--------+
      ...
      | fdvk34al8k5nltb58shr | centos-7-1549279494                 | centos-7                 | dqni65lfhvv2den5gtv9 | READY  |
      | fdv7ooobjfl3ts9gqp0q | windows-2016-gvlk-1548913814        | windows-2016-gvlk        | dqnnc72gj2ist3ktjj1p | READY  |
      | fdv4f5kv5cvf3ohu4flt | ubuntu-1604-lts-1549457823          | ubuntu-1604-lts          | dqnnb6dc7640c5i968ro | READY  |
      ...
      +----------------------+-------------------------------------+--------------------------+----------------------+--------+
      
    4. Create a YAML file with any name (for example, specification.yaml).

    5. In the created file, indicate the following:

      • General information about the group:

        name: first-fixed-group-with-balancer
        service_account_id: <ID>
        description: "This instance group was created from YAML config"
        

        Keys:

        Key Value
        name A name for the instance 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.
        service_account_id ID of the service account.
        description A description of the instance group.
      • Instance template:

        instance_template:
            platform_id: standard-v1
            resources_spec:
                memory: 4g
                cores: 1
            boot_disk_spec:
                mode: READ_WRITE
                disk_spec:
                    image_id: fdvk34al8k5nltb58shr
                    type_id: network-hdd
                    size: 32g
            network_interface_specs:
                - network_id: c64mknqgnd8avp6edhbt
                  primary_v4_address_spec: {}
        

        The disk size is specified in bytes by default. You can specify a different unit of measurement using the applicable suffix.

        Name Example of a YAML file entry:
        Kilobyte 1073741824k
        Megabyte 1048576m
        Gigabyte 1024g
        Terabyte 1t

        Keys (the table contains the keys that directly define the instance parameters):

        Key Value
        platform_id ID of the platform.
        memory Amount of memory (RAM).
        cores Number of processor cores (vCPUs).
        mode Disk access mode.
        - READ_ONLY: read-only access.
        - READ_WRITE: read/write access.
        image_id CentOS 7 public image ID.
        type_id Disk type.
        size Disk size.
        network_id The default-net ID.
        primary_v4_address_spec IPv4 specification. Only IPv4 is currently available. You can allow public access to group instances by specifying the IP version for the public IP address. For more information, see Template description in a YAML file.
      • Policies:

        deploy_policy:
            max_unavailable: 1
            max_expansion: 0
        scale_policy:
            fixed_scale:
                size: 3
        allocation_policy:
            zones:
                - zone_id: ru-central1-a
        

        Keys:

        Key Value
        deploy_policy Deployment policy for instances in the group.
        scale_policy Scaling policy for instances in the group.
        allocation_policy Policy for allocating instances across zones and regions.
      • Load Balancer target group:

        load_balancer_spec:
            target_group_spec:
                name: first-target-group
        

        Keys:

        Key Value
        target_group_spec Specification of the Load Balancer target group associated with the instance group.
        name A name for the Load Balancer 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.

        Full code for the specification.yaml file:

        name: first-fixed-group-with-balancer
        service_account_id: <ID>
        description: "This instance group was created from YAML config"
        instance_template:
            platform_id: standard-v1
            resources_spec:
                memory: 4g
                cores: 1
            boot_disk_spec:
                mode: READ_WRITE
                disk_spec:
                    image_id: fdvk34al8k5nltb58shr
                    type_id: network-hdd
                    size: 32g
            network_interface_specs:
                - network_id: c64mknqgnd8avp6edhbt
                  primary_v4_address_spec: {}
        deploy_policy:
            max_unavailable: 1
            max_expansion: 0
        scale_policy:
            fixed_scale:
                size: 3
        allocation_policy:
            zones:
                - zone_id: ru-central1-a
        load_balancer_spec:
            target_group_spec:
                name: first-target-group
        
    6. Create an instance group in the default folder:

      $ yc compute instance-group create --file specification.yaml
      

      This command creates a group of three similar instances with the following characteristics:

      • Named first-fixed-group-with-balancer.
      • Running CentOS 7.
      • In the default-net network.
      • In the ru-central1-a availability zone.
      • With a single vCPU and 4 GB RAM.
      • With a 32 GB network HDD.
      • With a target group named first-target-group.
    7. Create a load balancer and add the first-target-group target group to it .

    Use the API method create.