Yandex.Cloud
  • Services
  • Why Yandex.Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Yandex Compute Cloud
  • Getting started
    • Overview
    • Creating a Linux VM
    • Creating a Windows VM
    • Creating instance groups
  • Step-by-step instructions
    • All instructions
    • Creating VMs
      • Creating a Linux VM
      • Creating a Windows VM
      • Creating a VM from a set of disks
      • Create a VM with disks restored from snapshots
      • Creating a VM from a custom image
      • Creating a preemptible VM
      • Creating a VM with a GPU
    • DSVM
      • Overview
      • Creating a VM from a public DSVM image
    • Placement groups
      • Creating a placement group
      • Deleting a placement group
      • Creating a VM instance in a placement group
      • Adding a VM to a placement group
      • Removing a VM instance from a placement group
    • Images with pre-installed software
      • Creating a VM from a public image
      • Configuring software
      • Working with a VM based on a public image
      • Getting a list of public images
    • Getting information about a VM
      • Getting information about a VM
      • Viewing serial port output
    • Managing VMs
      • Stopping and starting a VM
      • Attaching a disk to a VM
      • Detaching a disk from a VM
      • Moving a VM to a different availability zone
      • Making a VM's public IP address static
      • Updating a VM
      • Changing VM computing resources
      • Deleting a VM
    • Working on VMs
      • Connecting to a VM via SSH
      • Connecting to a VM via RDP
      • Working with Yandex.Cloud from inside a VM
      • Installing NVIDIA drivers
    • Creating new disks
      • Creating an empty disk
    • Disk management
      • Creating a disk snapshot
      • Updating a disk
      • Deleting a disk
      • Deleting a disk snapshot
    • Creating new images
      • Uploading your image
    • Managing images
      • Deleting a disk image
    • Managing the serial console
      • Getting started
      • Connecting to a serial console via SSH
      • Connecting to a serial console via CLI
      • Start your terminal in the Windows SAC
      • Disabling access to the serial console
    • Creating instance groups
      • Creating a fixed-size instance group
      • Creating a fixed-size instance group with a load balancer
      • Creating an automatically scaled instance group
      • Creating an instance group from Container Optimized Image
    • Getting information about instance groups
      • Getting a list of groups
      • Getting information about a group
      • Getting a list of instances in a group
    • Managing instance groups
      • Update a group
      • Configure application health check on the VM
      • Update a group
        • Incremental update
        • Updating without downtime
      • Stop a group
      • Start a group
      • Delete a group
    • Dedicated hosts
      • Creating a VM in a group of dedicated hosts
      • Creating a VM on a dedicated host
  • Yandex Container Optimized Solutions
  • Scenarios
    • Configuring NTP time synchronization
    • Running instance groups with auto scaling
  • Concepts
    • Relationship between resources
    • Virtual machines
      • Overview
      • Platforms
      • vCPU performance levels
      • Graphics accelerators (GPUs)
      • Preemptible VMs
      • Network on a VM
      • Live migration
      • Placement groups
      • Statuses
      • Metadata
    • Disks
      • Overview
      • Disk snapshots
    • Images
    • Instance groups
      • Overview
      • Access
      • Instance template
      • Variables in an instance template
      • Policies
        • Overview
        • Allocation policy
        • Deployment policy
        • Scaling policy
      • Scaling types
      • Auto-healing
      • Update
        • Overview
        • Allocating instances across zones
        • Deployment algorithm
        • Rules for updating instance groups
      • Statuses
    • Dedicated host
    • Backups
    • Quotas and limits
  • Access management
  • Pricing policy
    • Current pricing policy
    • Archive
      • Before January 1, 2019
      • From January 1 to March 1, 2019
      • From March 1 to May 1, 2019
  • Compute API reference
    • Authentication in the API
    • gRPC
      • Overview
      • DiskPlacementGroupService
      • DiskService
      • DiskTypeService
      • HostGroupService
      • HostTypeService
      • ImageService
      • InstanceService
      • PlacementGroupService
      • SnapshotService
      • ZoneService
      • InstanceGroupService
      • OperationService
    • REST
      • Overview
      • Disk
        • Overview
        • create
        • delete
        • get
        • list
        • listOperations
        • update
      • DiskPlacementGroup
        • Overview
        • create
        • delete
        • get
        • list
        • listDisks
        • listOperations
        • update
      • DiskType
        • Overview
        • get
        • list
      • HostGroup
        • Overview
        • create
        • delete
        • get
        • list
        • listHosts
        • listInstances
        • listOperations
        • update
      • HostType
        • Overview
        • get
        • list
      • Image
        • Overview
        • create
        • delete
        • get
        • getLatestByFamily
        • list
        • listOperations
        • update
      • Instance
        • Overview
        • addOneToOneNat
        • attachDisk
        • create
        • delete
        • detachDisk
        • get
        • getSerialPortOutput
        • list
        • listOperations
        • removeOneToOneNat
        • restart
        • start
        • stop
        • update
        • updateMetadata
        • updateNetworkInterface
      • PlacementGroup
        • Overview
        • create
        • delete
        • get
        • list
        • listInstances
        • listOperations
        • update
      • Snapshot
        • Overview
        • create
        • delete
        • get
        • list
        • listOperations
        • update
      • Zone
        • Overview
        • get
        • list
      • Operation
        • Overview
        • get
      • InstanceGroup
        • Overview
        • createFromYaml
        • update
        • list
        • get
        • delete
        • start
        • stop
        • create
        • listAccessBindings
        • setAccessBindings
        • updateFromYaml
        • listLogRecords
        • listInstances
        • updateAccessBindings
        • listOperations
  • Questions and answers
    • General questions
    • Virtual machines
    • Disks and snapshots
    • Licensing
    • All questions on the same page
  1. Step-by-step instructions
  2. Creating instance groups
  3. Creating a fixed-size instance group with a load balancer

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:

    Management console
    CLI
    API
    Terraform
    1. In management console, select the folder where you want to create your instance group.
    2. From the list of services, select Compute Cloud.
    3. On the Virtual machines page, go to the Instance groups tab.
    4. Click Create group.
    5. Under Basic parameters:
      • Enter the Name and Description of the instance group. Naming requirements:

        • 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.

        Note

        The VM name is used to generate the FQDN only once, when creating the VM. If the FQDN is important to you, choose an appropriate name for the VM at the creation stage.

      • Select a service account from the list or create a new one. To be able to create, update, and delete group instances, assign the editor role to the service account. All operations in Instance Groups are performed on behalf of the service account.

    6. In the Allocation section, select the desired availability zones. Group instances may reside in different availability zones and regions. More about the geo scope of Yandex.Cloud.
    7. In the Instance template section, click Set to set the basic instance configuration:
      • Under Basic parameters, enter the template Description:
      • Under Images from Cloud Marketplace, select a public image.
      • In the Disks section:
        • Select the disk type.
        • Specify the Size of the disk.
        • To add more disks, click Add disk.
      • Under Computing resources:
        • Choose a platform.
        • Specify the required number of vCPUs, guaranteed vCPU performance, and the amount of RAM.
        • If necessary, make your VM preemptible.

          When creating a preemptible instance group, keep in mind that the virtual machines will terminate after 24 hours of continuous operation or earlier. It's possible that Instance Groups won't be able to restart them immediately due to insufficient resources. This may occur in the event of a drastic increase in Yandex.Cloud computing resource usage.

      • Under Network settings:
        • Select the cloud network from the list, or specify its ID. If you don't have a network, click Create a new network to create one:
          • In the window that opens, enter a name for the new network and choose the Subnet in the zone to connect the instance to. Each network must have at least one subnet (if there's no subnet, create one.
        • In the Public IP field, choose a method for assigning an IP address:
          • Auto: Assign a random IP address from the Yandex.Cloud IP pool.
          • No address: Don't assign a public IP address.
      • Under Access, specify the data required to access the VM:
        • Specify a Service account to be linked to the instance.
        • Enter the username in the Login field.
        • In the SSH key field, paste the contents of the public key file.
        • If needed, Grant access to the serial console.
      • Click Save.
    8. Under Allow when creating and updating:
      • In the Add above target value field, specify the number of instances you can exceed the group size by.
      • In the field Reduce below target value, specify the number of instances you can reduce the group size by.
      • In the Create simultaneously field, specify how many instances can be created at the same time.
      • In the Stop simultaneously field, specify how many instances can be stopped at the same time.
      • In the Stop VMs by strategy field, specify one of the strategies:
        • Proactive: Instance Groups selects which instances to stop when updating or reducing the group on its own.
        • Opportunistic: Instance Groups waits for the instances to stop on their own or by the user.
    9. In the Scalability section:
      • Select the Proactive type of scaling.
      • Specify the group size.
    10. Under Integration with Load Balancer, toggle the switch to the right of the Create target group field.
    11. Enter any Name of the target group and Description of the target group.
    12. If needed, enable the Health check to get information about the state of instances and their automatic recovery on failure.
      • In the Type field, select the protocol for the health checks: HTTP or TCP.
      • In the Port field, specify the port number from 1 to 32767 for Instance Groups to send the health check requests to.
      • In the Path field (for the HTTP type), specify the URL path for the HTTP check requests sent from Instance Groups.
      • In the Waiting time, s field, specify the response wait time from 1 to 60 seconds.
      • In the Interval in sec field, specify the interval between the repeat checks from 1 to 60 seconds. The interval must be at least 1 second longer than the timeout.
      • In the Performance threshold field, specify the number of successful health checks required for the instance to be considered healthy.
      • In the Failure threshold field, specify the number of failed health checks for the instance to be considered unhealthy.
    13. Click Create.

    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 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
      

      Command execution result:

      +----------------------+-------------------------------------+--------------------------+----------------------+--------+
      |          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, for example:

        instance_template:
            platform_id: standard-v1
            resources_spec:
                memory: 2g
                cores: 2
            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: {}
            scheduling_policy:
                preemptible: false
        

        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 Platform ID.
        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 ID of the public image.
        type_id Disk type.
        size Disk size.
        network_id The default-net ID.
        primary_v4_address_spec IPv4 specification. 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.
        scheduling_policy Scheduling policy configuration.
        preemptible A flag that enables the creation of preemptible instances. If the value is true, a preemptible instance is created, if false (default), a regular instance is created.
        When creating a preemptible instance group, keep in mind that the instances will terminate after 24 hours of continuous operation or earlier. It's possible that Instance Groups won't be able to restart them immediately due to insufficient resources. This may occur in the event of a drastic increase of the computing resource utilization in Yandex.Cloud.
      • 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 a group.
        scale_policy Scaling policy for instances in a group.
        allocation_policy Allocation policy for 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: 2g
                cores: 2
            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 2 vCPUs and 2 GB of 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 create.

    If you don't have Terraform, install it and configure the Yandex.Cloud provider.

    1. In the configuration file, describe the parameters of resources that you want to create:

      Note

      If you already have suitable resources, such as a service account, cloud network, and subnet, you don't need to describe them again. Use their names and IDs in the appropriate parameters.

      • yandex_iam_service_account: Description of a service account. All operations in Instance Groups are performed on behalf of the service account.

      • yandex_resourcemanager_folder_iam_binding: Description of access rights to the folder that the service account belongs to. To be able to create, update, and delete group instances, assign to the service account the role editor.

      • yandex_compute_instance_group: Description of an instance group:

        • General information about the group:

          Field Description
          name Name of the instance group.
          folder_id Folder ID.
          service_account_id ID of the service account.
        • Instance template:

          Field Description
          platform_id Platform.
          resources The number of vCPU cores and RAM available to the instance. The values must match the selected platform.
          boot_disk Boot disk settings. Specify:
          - ID of the selected image. You can get the image ID from the list of public images.
          - Disk access mode: READ_ONLY (read) or READ_WRITE (read and write).
          network_interface Network configuration. Specify the network ID and subnet ID.
          metadata In the metadata, pass the public key for accessing the instance via SSH. For more information, see VM instance metadata.
        • Policies:

          Field Description
          deploy_policy Deployment policy for instances in a group.
          scale_policy Scaling policy for instances in a group.
          allocation_policy Allocation policy for instances across zones and regions.
        • Load Balancer target group:

          Field Description
          target_group_name Name of the Load Balancer target group.
          target_group_description Description of the Load Balancer target group.
      • yandex_vpc_network: Description of the cloud network.

      • yandex_vpc_subnet: Description of the subnet that the instance group will be connected to.

      Example configuration file structure:

      resource "yandex_iam_service_account" "ig-sa" {
        name        = "ig-sa"
        description = "service account to manage IG"
      }
      
      resource "yandex_resourcemanager_folder_iam_binding" "editor" {
        folder_id = "<folder ID>"
        role      = "editor"
        members   = [
          "serviceAccount:${yandex_iam_service_account.ig-sa.id}",
        ]
      }
      
      resource "yandex_compute_instance_group" "ig-1" {
        name               = "fixed-ig-with-balancer"
        folder_id          = "<folder ID>"
        service_account_id = "${yandex_iam_service_account.ig-sa.id}"
        instance_template {
          platform_id = "standard-v1"
          resources {
            memory = <RAM in GB>
            cores  = <number of vCPU cores>
          }
      
          boot_disk {
            mode = "READ_WRITE"
            initialize_params {
              image_id = "<image ID>"
            }
          }
      
          network_interface {
            network_id = "${yandex_vpc_network.network-1.id}"
            subnet_ids = ["${yandex_vpc_subnet.subnet-1.id}"]
          }
      
          metadata = {
            ssh-keys = "<user name>:<SSH key contents>"
          }
        }
      
        scale_policy {
          fixed_scale {
            size = <number of instances in a group>
          }
        }
      
        allocation_policy {
          zones = ["ru-central1-a"]
        }
      
        deploy_policy {
          max_unavailable = 1
          max_expansion   = 0
        }
      
        load_balancer {
          target_group_name        = "target-group"
          target_group_description = "load balancer target group"
        }
      }
      
      resource "yandex_vpc_network" "network-1" {
        name = "network1"
      }
      
      resource "yandex_vpc_subnet" "subnet-1" {
        name           = "subnet1"
        zone           = "ru-central1-a"
        network_id     = "${yandex_vpc_network.network-1.id}"
        v4_cidr_blocks = ["192.168.10.0/24"]
      }
      

      For more information about the resources you can create using Terraform, see the provider documentation.

    2. Make sure that the configuration files are correct.

      1. In the command line, go to the directory where you created the configuration file.

      2. Run the check using the command:

        terraform plan
        

      If the configuration is described correctly, the terminal displays a list of created resources and their parameters. If there are errors in the configuration, Terraform points them out.

    3. Deploy the cloud resources.

      1. If the configuration doesn't contain any errors, run the command:

        terraform apply
        
      2. Confirm that you want to create the resources.

      Afterwards, all the necessary resources are created in the specified folder. You can check resource availability and their settings in management console.

    Language
    Careers
    Privacy policy
    Terms of use
    © 2021 Yandex.Cloud LLC