Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
  • Blog
  • Pricing
  • Documentation
Yandex project
© 2025 Yandex.Cloud LLC
Yandex Compute Cloud
  • Yandex Container Solution
    • All tutorials
    • Configuring time synchronization using NTP
      • Overview
      • Management console
      • Terraform
    • Autoscaling an instance group to process messages from a queue
    • Updating an instance group under load
    • Deploying Remote Desktop Gateway
    • Getting started with Packer
    • Transferring logs from a VM to Yandex Cloud Logging
    • Building a VM image with infrastructure tools using Packer
    • Migrating data to Yandex Cloud using Hystax Acura
    • Fault protection with Hystax Acura
    • VM backups using Hystax Acura
    • Deploying a fault-tolerant architecture with preemptible VMs
    • Configuring a fault-tolerant architecture in Yandex Cloud
    • Creating a budget trigger that invokes a function to stop a VM
    • Creating triggers that invoke a function to stop a VM and send a Telegram notification
    • Creating a Python web application with Flask
    • Creating an SAP program in Yandex Cloud
    • Deploying a Minecraft server in Yandex Cloud
    • Automating image builds using Jenkins and Packer
    • Creating test VMs via GitLab CI
    • High-performance computing on preemptible VMs
    • Configuring an SFTP server based on CentOS 7
    • Deploying GlusterFS in high availability mode
    • Deploying GlusterFS in high performance mode
    • Backing up to Object Storage with Bacula
    • Building a CI/CD pipeline in GitLab using serverless products
    • Implementing a secure high-availability network infrastructure with a dedicated DMZ based on the Check Point NGFW
    • Cloud infrastructure segmentation with the Check Point next-generation firewall
    • Configuring a secure GRE tunnel over IPsec
    • Creating a bastion host
    • Implementing fault-tolerant scenarios for NAT VMs
    • Creating a tunnel between two subnets using OpenVPN Access Server
    • Creating an external table from a Object Storage bucket table using a configuration file
    • Setting up network connectivity between BareMetal and Virtual Private Cloud subnets
    • Working with snapshots in Managed Service for Kubernetes
    • Launching the DeepSeek-R1 language model in a Yandex Compute Cloud GPU cluster
  • Access management
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Release notes

In this article:

  • Get your cloud ready
  • Required paid resources
  • Prepare the environment
  • Create an instance group with autoscaling and a network load balancer
  • Add a network load balancer with a target group
  • Test your instance group and network load balancer
  • Test autoscaling
  • How to delete the resources you created
  1. Tutorials
  2. Running an instance group with autoscaling
  3. Management console

Running an autoscaling instance group using the management console, CLI, and API

Written by
Yandex Cloud
Updated at May 7, 2025
  • Get your cloud ready
    • Required paid resources
  • Prepare the environment
  • Create an instance group with autoscaling and a network load balancer
  • Add a network load balancer with a target group
  • Test your instance group and network load balancer
    • Test autoscaling
  • How to delete the resources you created

To configure an autoscaling instance group:

  1. Get your cloud ready.
  2. Prepare the environment.
  3. Create an instance group with autoscaling and a network load balancer.
  4. Add a network load balancer with a target group.
  5. Test your instance group and network load balancer.

If you no longer need the resources you created, delete them.

Get your cloud readyGet your cloud ready

Sign up in Yandex Cloud and create a billing account:

  1. Navigate to the management console and log in to Yandex Cloud or register a new account.
  2. On the Yandex Cloud Billing page, make sure you have a billing account linked and it has the ACTIVE or TRIAL_ACTIVE status. If you do not have a billing account, create one and link a cloud to it.

If you have an active billing account, you can navigate to the cloud page to create or select a folder for your infrastructure to operate in.

Learn more about clouds and folders.

  1. If you do not have the Yandex Cloud CLI yet, install it.

  2. To make sure the scripts from the step-by-step guide run correctly, download and install jq.

  3. To check autoscaling, install wrk.

Required paid resourcesRequired paid resources

The infrastructure cost includes:

  • Fee for continuously running VMs (see Compute Cloud pricing).
  • Fee for network load balancers and traffic balancing (see Network Load Balancer pricing).

Prepare the environmentPrepare the environment

  1. Create a service account named for-autoscale: To create, update, and delete VMs in the group, as well as integrate the group with an Network Load Balancer network load balancer, assign the compute.editor and load-balancer.editor roles to the service account:

    Management console
    CLI
    API
    1. In the management console, select the folder where you want to create your service account.
    2. From the list of services, select Identity and Access Management.
    3. Click Create service account. In the window that opens:
      • In the Name field, specify for-autoscale.
      • To assign the service account a role for the current folder, click Add role and select the compute.editor and load-balancer.editor roles.
      • Click Create.
    1. Create a service account:

      The folder specified when creating the CLI profile is used by default. To change the default folder, use the yc config set folder-id <folder_ID> command. You can specify a different folder using the --folder-name or --folder-id parameter.

      yc iam service-account create --name for-autoscale
      

      Result:

      id: ajelabcde12f********
      folder_id: b0g12ga82bcv********
      created_at: "2020-11-30T14:32:18.900092Z"
      name: for-autoscale
      
    2. Assign the compute.editor role to the service account:

      yc resource-manager folder add-access-binding <folder_ID> \
        --role compute.editor \
        --subject serviceAccount:<service_account_ID>
      
    3. Assign the load-balancer.editor role to the service account:

      yc resource-manager folder add-access-binding <folder_ID> \
        --role load-balancer.editor \
        --subject serviceAccount:<service_account_ID>
      

    Use the create REST API method for the ServiceAccount resource or the ServiceAccountService/Create gRPC API call.

  2. Create a network named yc-auto-network and subnets in two availability zones:

    Management console
    CLI
    API
    1. In the management console, select the folder where you want to create your network.
    2. Select Virtual Private Cloud.
    3. Click Create network.
    4. In the Name field, enter yc-auto-network as the network name.
    5. In the Advanced field, enable the Create subnets option.
    6. Click Create network.
    1. Create a network:

      yc vpc network create --name yc-auto-network
      

      Result:

      id: enpabce123hd********
      folder_id: b0g12ga82bcv********
      created_at: "2020-11-30T14:57:15Z"
      name: yc-auto-network
      
    2. Create a subnet in the ru-central1-a availability zone:

      yc vpc subnet create \
        --network-id enpabce123hd******** \
        --range 192.168.1.0/24 \
        --zone ru-central1-a
      

      Result:

      id: e1lnabc23r1c********
      folder_id: b0g12ga82bcv********
      created_at: "2020-11-30T16:23:12Z"
      network_id: enpabce123hd********
      zone_id: ru-central1-a
      v4_cidr_blocks:
      - 192.168.1.0/24
      
    3. Create a subnet in the ru-central1-b availability zone:

      yc vpc subnet create \
        --network-id enpabce123hd******** \
        --range 192.168.2.0/24 \
        --zone ru-central1-b
      

      Result:

      id: b1csa2b3clid********
      folder_id: b0g12ga82bcv********
      created_at: "2020-11-30T16:25:02Z"
      network_id: enpabce123hd********
      zone_id: ru-central1-b
      v4_cidr_blocks:
      - 192.168.2.0/24
      
    1. Create a network.

      Use the create REST API method for the Network resource or the NetworkService/Create gRPC API call.

    2. Create subnets in the ru-central1-a and ru-central1-b availability zones.

      Use the create REST API method for the Subnet resource or the SubnetService/Create gRPC API call.

  3. Create a security group:

    Management console
    1. In the management console, select Virtual Private Cloud.
    2. Open the Security groups tab.
    3. Create a security group for the load balancer:
      1. Click Create group.

      2. Enter the group Name: sg-autoscale.

      3. Select yc-auto-network for Network.

      4. Under Rules, create rules by following the steps below the table:

        Traffic
        direction
        Description Port
        range
        Protocol Source /
        target type
        Source /
        target
        Outbound any All Any CIDR 0.0.0.0/0
        Inbound ext-http 80 TCP CIDR 0.0.0.0/0
        Inbound healthchecks 80 TCP Load balancer health checks —
        1. Select the Outbound traffic or Inbound traffic tab.
        2. Click Add rule.
        3. In the Port range field of the window that opens, specify a single port or a range of ports that traffic will come to or from.
        4. In the Protocol field, specify the protocol or leave Any to allow traffic over any protocol.
        5. In the Purpose or Source field, select the purpose of the rule:
          • CIDR: Rule will apply to the range of IP addresses. In the CIDR blocks field, specify the CIDR and masks of subnets that traffic will come to or from. To add multiple CIDRs, click Add CIDR.
          • Security group: Rule will apply to the VMs from the current group or the selected security group.
          • Load balancer health checks: Rule allowing a load balancer to health check VMs.
        6. Click Save. Repeat the steps to create all rules from the table.
      5. Click Save.

Create an instance group with autoscaling and a network load balancerCreate an instance group with autoscaling and a network load balancer

  1. All instance groups are created from Container Optimized Image. Each instance contains a Docker container running a web server that emulates the service utilization.

    Find out the ID of the latest version of the public Container Optimized Image.

    A Container Optimized Image in a Container Registry registry may be updated and changed with new releases. This will not automatically update the VM image to the latest version. To create an instance group with the latest Container Optimized Image version, you need to check whether it is available yourself:

    CLI
    Yandex Cloud Marketplace
    yc compute image get-latest-from-family container-optimized-image --folder-id standard-images
    

    Result:

    id: <ID_of_latest_COI_version>
    folder_id: standard-images
    ...
    
    1. Go to the Cloud Marketplace page and select the image with the configuration you need:
      • Container Optimized Image.
      • Container Optimized Image GPU.
    2. Under Product IDs, copy the value of image_id.
  2. Save the specification of the instance group with the network load balancer to the specification.yaml file:

    name: auto-group
    service_account_id: <service_account_ID>
    scale_policy:
      auto_scale:
        min_zone_size: 1
        max_size: 6
        measurement_duration: 60s
        warmup_duration: 120s
        stabilization_duration: 60s
        initial_size: 2
        cpu_utilization_rule:
          utilization_target: 40
    deploy_policy:
      max_unavailable: 1
    allocation_policy:
      zones:
        - zone_id: ru-central1-a
        - zone_id: ru-central1-b
    load_balancer_spec:
      target_group_spec:
        name: auto-group-tg
    instance_template:
      service_account_id: <service_account_ID>
      platform_id: standard-v3
      resources_spec:
        memory: 2G
        cores: 2
        core_fraction: 100
      metadata:
        docker-container-declaration: |-
          spec:
            containers:
            - image: cr.yandex/yc/demo/web-app:v1
              securityContext:
                privileged: false
              tty: false
              stdin: false
      boot_disk_spec:
        mode: READ_WRITE
        disk_spec:
          type_id: network-hdd
          size: 30G
          image_id: fd8iv792kira******** # ID of the public Container Optimized Image
      network_interface_specs:
        - network_id: <cloud_network_ID>
          primary_v4_address_spec: { one_to_one_nat_spec: { ip_version: IPV4 }}
    
  3. In specification.yaml, replace the values in angle brackets with the real values you got at the previous steps.

  4. Create an instance group named auto-group using the specification.yaml spec:

    CLI
    API

    Run this command:

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

    Result:

    done (2m45s)
    id: cl0hmabc1nd2********
    folder_id: b0g12ga82bcv********
    ...
      target_group_id: enpoi5jhfps3********
    ...
        name: auto-group-tg
    service_account_id: ajelabcde12f********
    status: ACTIVE
    

    For the InstanceGroup resource, use the CreateFromYaml method.

  5. Make sure the instance group was created:

    Management console
    CLI
    API
    1. In the management console, select the folder where you created the instance group.
    2. Select Compute Cloud.
    3. In the left-hand panel, click Instance groups.
    4. Select auto-group.
    yc compute instance-group list-instances auto-group
    

    Result:

    +----------------------+---------------------------+----------------+--------------+------------------------+----------------+
    |     INSTANCE ID      |           NAME            |  EXTERNAL IP   | INTERNAL IP  |         STATUS         | STATUS MESSAGE |
    +----------------------+---------------------------+----------------+--------------+------------------------+----------------+
    | epdab0c1ji2a******** | cl0habce1nd2********-fned | 84.201.163.202 | 192.168.1.34 | RUNNING_ACTUAL [4m26s] |                |
    | ef0uabc1s2fb******** | cl0habce1nd2********-craq | 130.193.56.102 | 192.168.2.19 | RUNNING_ACTUAL [4m14s] |                |
    +----------------------+---------------------------+----------------+--------------+------------------------+----------------+
    

    To view the list of the instance groups you created, use the list REST API method for the InstanceGroup resource or the InstanceGroupService/List gRPC API call.

Add a network load balancer with a target groupAdd a network load balancer with a target group

  1. Create a network load balancer named group-balancer and connect it to the instance group you created:

    Management console
    CLI
    API
    1. In the management console, select the folder where you want to create a load balancer.
    2. Select Network Load Balancer.
    3. Click Create a network load balancer.
    4. Enter group-balancer as the name.
    5. In the Public address field, specify Auto.
    6. Under Listeners, click Add listener. In the window that opens, specify:
      • Name: http
      • Port (port the load balancer will receive incoming traffic at): 80
      • Target port (port the load balancer will route traffic to): 80
      • Click Add.
    7. Under Target groups, click Add target group.
    8. In the Target group field, select auto-group-tg and click Configure. In the window that opens, specify:
      • Name: tcp
      • Type: TCP
      • Port: 80
      • Click Apply.
    9. Click Create.
    yc load-balancer network-load-balancer create \
      --listener external-ip-version=ipv4,name=http,port=80,protocol=tcp,target-port=80 \
      --name group-balancer \
      --target-group healthcheck-name=tcp,healthcheck-tcp-port=80,target-group-id=enpoi5jhfps3********
    

    Result:

    done (16s)
    id: b0rbabc1m2ed********
    folder_id: b0g12ga82bcv********
    ...
        healthy_threshold: "2"
        tcp_options:
          port: "80"
    
    1. Create a load balancer using the create REST API method for the NetworkLoadBalancer resource or the NetworkLoadBalancerService/Create gRPC API call.
    2. Add a listener to the load balancer using the addListener REST API method for the NetworkLoadBalancer resource or the NetworkLoadBalancerService/AddListener gRPC API call.
    3. Connect the target group to the load balancer using the attachTargetGroup REST API method for the NetworkLoadBalancer resource or the NetworkLoadBalancerService/AttachTargetGroup gRPC API call.
    4. Add the load balancer to the instance group using the addTargets REST API method for the TargetGroup resource or the TargetGroupService/AddTargets gRPC API call.
  2. Make sure you created the network load balancer named group-balancer and linked it to the instance group:

    Management console
    CLI
    API
    1. In the management console, select the folder where you created the load balancer.
    2. Select Network Load Balancer.
    3. Select group-balancer.
    yc load-balancer network-load-balancer list
    

    Result:

    +----------------------+----------------+-----------------+----------+----------------+------------------------+--------+
    |          ID          |      NAME      |    REGION ID    |   TYPE   | LISTENER COUNT | ATTACHED TARGET GROUPS | STATUS |
    +----------------------+----------------+-----------------+----------+----------------+------------------------+--------+
    | b0rbabc1m2ed******** | group-balancer | ru-central1 | EXTERNAL |              1 | b0rdabckribe********   | ACTIVE |
    +----------------------+----------------+-----------------+----------+----------------+------------------------+--------+
    

    Use the list REST API method for the NetworkLoadBalancer resource or the NetworkLoadBalancerService/List gRPC API call.

Test your instance group and network load balancerTest your instance group and network load balancer

  1. Create a load on an instance.

    To do this, save the script named request.sh to the home directory. The script will send a request to one of the VMs through the group-balancer load balancer. The request will utilize 100% CPU for 30 seconds.

    EXTERNAL_IP=$(yc load-balancer network-load-balancer get group-balancer --format=json | jq -r .listeners[0].address)
    
    curl "http://$EXTERNAL_IP/burn-cpu?time=30000&load=100"
    
  2. Run the script:

    CLI
    sh request.sh
    

    Result:

    projects/b0g12ga82bcv********/zones/ru-central1-b
    
  3. View the instance utilization:

    Management console
    1. In the management console, select the folder where you created the instance group.

    2. Select Compute Cloud.

    3. In the left-hand panel, click Instance groups.

    4. Select auto-group.

    5. Go to the Monitoring tab.

      The load balancer sent the request to an instance in the group. In the availability zone this instance belongs to, the average CPU utilization is higher than in other zones (see the Average CPU utilization in zone chart).

Test autoscalingTest autoscaling

To test autoscaling for your instance group, increase the CPU utilization of each instance. In the specification.yaml file, the scale_policy.auto_scale.cpu_utilization_rule.utilization_target parameter is set to 40: it means that the target utilization level is 40% CPU. If you exceed the target utilization, the number of VMs in the group will increase.

  1. Increase the utilization for the instance group.

    To do this, save the script named load.sh to the home directory. The script sends requests to the instance group through 12 threads for 10 minutes. Each VM instance utilizes 20% CPU on each core that processes the request. The instance group utilization is 240% CPU at any given time. To be sure that requests are evenly distributed across the instances in the group, the script executes multiple parallel requests utilizing 20% CPU rather than one request utilizing 240% CPU.

    EXTERNAL_IP=$(yc load-balancer network-load-balancer get group-balancer --format=json | jq -r .listeners[0].address)
    
    wrk -H "Connection: close" -t12 -c12 -d10m "http://$EXTERNAL_IP/burn-cpu?time=5000&load=20"
    
  2. Run the script:

    CLI
    sh load.sh
    

    Result:

    Running 10m test @ http://130.193.56.111/burn-cpu?time=5000&load=20
      12 threads and 12 connections
      Thread Stats   Avg      Stdev     Max   +/- Stdev
    ...
    Requests/sec: 15.04
    Transfer/sec: 3.20KB
    
  3. View the utilization levels:

    Management console
    1. In the management console, select the folder where you created the auto-group instance group.
    2. Select Compute Cloud.
    3. In the panel on the left, click Instance groups.
    4. Select auto-group.
    5. Go to the Monitoring tab.
      The chart Number of instances in zone shows how the number of instances changed in each availability zone. The chart Average CPU utilization in zone shows average CPU utilization in each availability zone.
    6. Go to the Logs tab.
      The page displays messages relating to the instance group autoscaling.

    The total utilization of 240% CPU was evenly distributed between two instances in two availability zones and exceeded the target utilization of 40% CPU. Yandex Compute Cloud created one instance more in each availability zone to result in four instances in the group. When the script stopped utilizing the CPU, Compute Cloud automatically decreased the number of instances in the group to two.

How to delete the resources you createdHow to delete the resources you created

To stop paying for the resources you created:

  1. Delete the network load balancer.
  2. Delete the instance group.

See alsoSee also

  • Running anautoscaling instance group with Terraform

Was the article helpful?

Previous
Overview
Next
Terraform
Yandex project
© 2025 Yandex.Cloud LLC