Updating an instance group under load
In this step-by-step tutorial, you will configure an instance group and check how it operates when updating the configuration. To do this:
- Get your cloud ready.
- Set up your environment.
- Create an instance group from a Container Optimized Image.
- Create a load on a VM.
- Update the instance group under load.
- Stop the load and get the results.
If you no longer need the resources you created, delete them.
Get your cloud ready
-
If you do not have the Yandex Cloud CLI yet, install it.
-
To make sure the scripts from the step-by-step guide run correctly, download and install jq
. -
To check autoscaling, install wrk
.
Required paid resources
The support cost for a Yandex Cloud instance group includes fees for:
- Disks and continuously running VMs as per Yandex Compute Cloud pricing.
- Using a dynamic or static public IP address as per Yandex Virtual Private Cloud pricing.
Prepare the environment
-
Create a service account named
for-load
. To be able to create, update, and delete VMs in the group, as well as integrate the group with a Network Load Balancer network load balancer, assign the compute.editor and load-balancer.editor roles to the service account:Management consoleCLIAPI- In the management console
, select the folder where you want to create your service account. - From the list of services, select Identity and Access Management.
- Click Create service account.
- In the Name field, specify
for-load
. - Click
Add role. To be able to create, update, and delete VMs in the group, as well as integrate the group with a Network Load Balancer network load balancer, assign the compute.editor and load-balancer.editor roles to the service account. - Click Create.
-
Create a service account:
The folder specified in the CLI profile is used by default. You can specify a different folder through the
--folder-name
or--folder-id
parameter.yc iam service-account create --name for-load
Result:
id: ajeab0cnib1p******** folder_id: b0g12ga82bcv******** created_at: "2021-02-09T17:31:32.561702Z" name: for-load
-
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>
-
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>
- Create a service account named
for-load
:
Use the create REST API method for the ServiceAccount resource or the ServiceAccountService/Create gRPC API call. - To be able to create, update, and delete VMs in the group, as well as integrate the group with a Network Load Balancer network load balancer, assign the compute.editor and load-balancer.editor roles to the service account:
Use the setAccessBindings REST API method for the Folder resource or the FolderService/SetAccessBindings gRPC API call.
- In the management console
-
Create a network named
yc-auto-network
and subnets in two availability zones:Management consoleCLIAPI- In the management console
, select the folder where you want to create a network. - From the list of services, select Virtual Private Cloud.
- Click Create network.
- In the Name field, specify
yc-auto-network
. - Select Create subnets.
- Click Create network.
-
Create a network:
yc vpc network create --name yc-auto-network
Result:
id: enpabce123hd******** folder_id: b0g12ga82bcv******** created_at: "2021-02-09T17:33:32.561702Z" name: yc-auto-network
-
Create a subnet in the
ru-central1-d
availability zone:yc vpc subnet create --network-id enpabce123hd******** --range 192.168.1.0/24 --zone ru-central1-d
Result:
id: e1lnabc23r1c******** folder_id: b0g12ga82bcv******** created_at: "2021-02-09T17:34:32.561702Z" network_id: enpabce123hd******** zone_id: ru-central1-d v4_cidr_blocks: - 192.168.1.0/24
-
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: "2021-02-09T17:35:32.561702Z" network_id: enpabce123hd******** zone_id: ru-central1-b v4_cidr_blocks: - 192.168.2.0/24
- Create a network:
Use the create REST API method for the Network resource or the NetworkService/Create gRPC API call. - Create subnets in the
ru-central1-d
andru-central1-b
availability zones:
Use the create REST API method for the Subnet resource or the SubnetService/Create gRPC API call.
- In the management console
Create a Container Optimized Image instance group
-
You will be creating all instance groups from Container Optimized Images. Each VM will have a Docker container running a web server that emulates the load.
Management consoleCLIAPI- In the management console
, select a folder where your instance group will reside. - From the list of services, select Compute Cloud.
- In the left-hand panel, select
Instance groups. - Click Create group of virtual machines.
- Under Basic parameters:
- In the Name field, specify
group-for-load
. - Select Service account
for-load
.
- In the Name field, specify
- Under Allocation, select
ru-central1-d
andru-central1-b
in the Availability zone field. - Under Instance template, click Define and do the following in the window that opens:
- Under Boot disk image, select the Container Solution tab.
- Click Configure.
- In the Docker container settings window:
- In the Name field, specify
nginx
. - In the Docker image field, click Enter link and enter
cr.yandex/yc/demo/autoscaling-example-app:v1
. - Click Apply.
- In the Name field, specify
- Under Disks and file storages:
- For the boot disk, specify a Size of
30 GB
.
- For the boot disk, specify a Size of
- Under Network settings:
- In the Network field, select
for-load
.
- In the Network field, select
- Under Access:
- In the Service account field, select
for-load
. - In the Login field, enter the name of the user to create on the VM.
- In the SSH key field, paste the contents of the public key file.
- In the Service account field, select
- Click Save.
- Under Changes during creation and updates:
- In the Reduce below target value field, enter
4
.
- In the Reduce below target value field, enter
- Under Scaling:
- In the Type field, select
Fixed
. - Set the Size to
6
.
- In the Type field, select
- Under Integration with Network Load Balancer:
- Enable Create target group.
- In the Name of the target group field, specify
load-generator
.
- Click Create.
-
Get the ID of the latest version of the public Container Optimized Image.
A Container Optimized Image in Yandex Container Registry may get updates and modifications that come with new releases. Such modifications will not automatically update the VM image to the latest version. To create an instance group with the latest Container Optimized Image version, check whether it is available on your own:
yc compute image get-latest-from-family container-optimized-image --folder-id standard-images
Result:
id: fd8iv792kira******** folder_id: standard-images created_at: "2021-01-29T13:30:22Z" ... status: READY os: type: LINUX
-
Save the specification of the instance group with a network load balancer to the
specification.yaml
file:name: group-for-load # VM group name, unique within the folder. service_account_id: ajeab0cnib1p******** # Service account ID. allocation_policy: # VM allocation policy for the group. zones: - zone_id: ru-central1-d - zone_id: ru-central1-b instance_template: service_account_id: ajeab0cnib1p******** # ID of the service account to access private Docker images. platform_id: standard-v1 # Platform ID. resources_spec: memory: 2G # Amount of memory (RAM). cores: 2 # Number of processor cores (vCPUs). boot_disk_spec: mode: READ_WRITE # Disk access mode (read and write). disk_spec: image_id: <latest_COI_version_ID> type_id: network-ssd # Disk type. size: 30G # Disk size. network_interface_specs: - network_id: enplhg4nncc7******** # Network ID. subnet_ids: - e1lnabc23r1c******** # Subnet ID. - b1csa2b3clid******** primary_v4_address_spec: { one_to_one_nat_spec: { ip_version: IPV4 # IPv4 specification for public access to the VM. } } metadata: # Values to send to the VM metadata. docker-container-declaration: |- # Key in the VM metadata that is used with the Docker Container specification. spec: containers: - image: cr.yandex/yc/demo/autoscaling-example-app:v1 name: nginx securityContext: privileged: false restartPolicy: Always tty: false stdin: false ssh-keys: | # Parameter for providing an SSH key to the VM. yc-user:ssh-ed25519 ABC...d01 user@desktop.ru # Username for connecting to the VM. deploy_policy: # VM deployment policy for the group. max_unavailable: 4 scale_policy: # Instance scaling policy for the group. fixed_scale: size: 6 load_balancer_spec: # Network load balancer. target_group_spec: name: load-generator
Note
You can provide an SSH key in the VM metadata using the
ssh-keys
parameter or in theuser-data
string. This tutorial features the first option. -
Create an instance group named
group-for-load
usingspecification.yaml
:yc compute instance-group create --file=specification.yaml
Result:
done (2m18s) id: cl0kabcquk1g******** folder_id: b0g12ga82bcv******** ... service_account_id: ajeab0cnib1p******** status: ACTIVE application_load_balancer_state: {}
-
Get the ID of the latest
container-optimized-image
version in thestandard-images
family:
Use the getLatestByFamily REST API method for the Image resource or the ImageService/GetLatestByFamily gRPC API call. -
Create an instance group based on this spec:
name: group-for-load # VM group name, unique within the folder. service_account_id: ajeab0cnib1p******** # Service account ID. allocation_policy: # VM allocation policy for the group. zones: - zone_id: ru-central1-d - zone_id: ru-central1-b instance_template: service_account_id: ajeab0cnib1p******** # ID of the service account to access private Docker images. platform_id: standard-v1 # Platform ID. resources_spec: memory: 2G # Amount of memory (RAM). cores: 2 # Number of processor cores (vCPUs). boot_disk_spec: mode: READ_WRITE # Disk access mode (read and write). disk_spec: image_id: <latest_COI_version_ID> type_id: network-ssd # Disk type. size: 30G # Disk size. network_interface_specs: - network_id: enplhg4nncc7******** # Network ID. subnet_ids: - e1lnabc23r1c******** # Subnet ID. - b1csa2b3clid******** primary_v4_address_spec: { one_to_one_nat_spec: { ip_version: IPV4 # IPv4 specification for public access to the VM. } } metadata: # Values to send to the VM metadata. docker-container-declaration: |- # Key in the VM metadata that is used with the Docker Container specification. spec: containers: - image: cr.yandex/yc/demo/autoscaling-example-app:v1 name: nginx securityContext: privileged: false restartPolicy: Always tty: false stdin: false ssh-keys: | # Parameter for providing an SSH key to the VM. yc-user:ssh-ed25519 ABC...d01 user@desktop.ru # Username for connecting to the VM. deploy_policy: # VM deployment policy for the group. max_unavailable: 4 scale_policy: # Instance scaling policy for the group. fixed_scale: size: 6 load_balancer_spec: # Network load balancer. target_group_spec: name: load-generator
Use the createFromYaml REST API method for the InstanceGroup resource or the InstanceGroupService/CreateFromYaml gRPC API call.
- In the management console
-
Make sure you have created the instance group:
Management consoleCLIAPI- In the management console
, select the folder where you created the instance group. - From the list of services, select Compute Cloud.
- In the left-hand panel, select
Instance groups. - Click
group-for-load
.
yc compute instance-group list-instances group-for-load
Result:
+----------------------+---------------------------+-----------------+-------------+----------------------+----------------+ | INSTANCE ID | NAME | EXTERNAL IP | INTERNAL IP | STATUS | STATUS MESSAGE | +----------------------+---------------------------+-----------------+-------------+----------------------+----------------+ ... | fhmab0cfsfd1******** | cl0kabcquk1g********-oxig | 178.154.226.108 | 10.130.0.8 | RUNNING_ACTUAL [49m] | | | epdabchpdef0******** | cl0kabcquk1g********-aqyg | 130.193.40.55 | 10.129.0.20 | RUNNING_ACTUAL [43m] | | +----------------------+---------------------------+-----------------+-------------+----------------------+----------------+
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.
- In the management console
Add a network load balancer to the instance group you created
-
Create a network load balancer named
load-generator
and connect it to the instance group you created:Management consoleCLIAPI- In the management console
, select the folder where you want to create a load balancer. - From the list of services, select Network Load Balancer.
- Click Create a network load balancer.
- In the Name field, specify
load-generator
. - In the Public address field, select
Auto
. - Under Listeners, click Add listener.
- In the window that opens:
- In the Name field, specify
http
. - In the Port field, enter
80
as the port where the balancer will receive inbound traffic. - In the Target port field, enter
80
as the port to which the balancer will redirect traffic. - Click Add.
- In the Name field, specify
- Under Target groups, click Add target group.
- In the Target group list, select
load-generator
. - Under Health check, click Configure:
- In the window that opens, specify:
/hello
as the Path. The load balancer will use this path to send health check requests to the target group VMs. - Click Apply.
- In the window that opens, specify:
- Click Create.
-
Get the ID of the
load-generator
target group:yc load-balancer target-group get load-generator | grep "^id"
Result:
id: enpsa475ej51********
-
Create a network load balancer:
yc load-balancer network-load-balancer create \ --name load-generator \ --listener external-ip-version=ipv4,name=http,port=80,protocol=tcp,target-port=80 \ --target-group healthcheck-http-port=80,healthcheck-http-path=/hello,target-group-id=<target_group_ID>
Result:
done (14s) id: b0ruab1ccvpd******** folder_id: b1csa2b3clid******** ... healthy_threshold: "2" http_options: port: "80" path: /hello
- Create a load balancer using the create REST API method for the NetworkLoadBalancer resource or the NetworkLoadBalancerService/Create gRPC API call.
- Add a listener to the load balancer using the addListener REST API method for the
NetworkLoadBalancer
resource or the NetworkLoadBalancerService/AddListener gRPC API call. - 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. - 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.
- In the management console
-
Make sure you have created the network load balancer named
load-generator
and linked it to the instance group:Management consoleCLIAPI- In the management console
, select the folder where you created the load balancer. - From the list of services, select Network Load Balancer.
- Click
load-generator
.
yc load-balancer network-load-balancer list
Result:
+----------------------+----------------+-----------------+----------+----------------+------------------------+--------+ | ID | NAME | REGION ID | TYPE | LISTENER COUNT | ATTACHED TARGET GROUPS | STATUS | +----------------------+----------------+-----------------+----------+----------------+------------------------+--------+ | b0ruab1ccvpd******** | load-generator | ru-central1 | EXTERNAL | 1 | b0r1tabcphde******** | ACTIVE | +----------------------+----------------+-----------------+----------+----------------+------------------------+--------+
Use the list REST API method for the NetworkLoadBalancer resource or the NetworkLoadBalancerService/List gRPC API call.
- In the management console
Create a load on a VM
-
Get the IP address of the load balancer you created:
Management consoleCLIAPI- In the management console
, select the load balancer folder. - From the list of services, select Network Load Balancer.
- Copy the IP address of the
load-generator
load balancer.
yc load-balancer network-load-balancer get load-generator | grep "address"
Result:
address: 84.252.133.110
Use the get REST API method for the NetworkLoadBalancer resource or the NetworkLoadBalancerService/Get gRPC API call.
- In the management console
-
Run this command to create a load:
wrk -t20 -c20 -d20m --timeout 20s http://<load_balancer_IP_address>/sleep
The command will launch the
wrk
utility that will send requests to 20 threads using 20 connections to the network load balancer for 20 minutes. The request timeout is 20 seconds. The load balancer will distribute the load it gets among the group’s VMs.After you launch
wrk
, a testing start message will appear on the screen:Running 20m test @ http://84.252.133.110/sleep 20 threads and 20 connections
Proceed to the next step without waiting for the command to complete.
Update the instance group under load
- In the management console
, select the folder where you created the instance group. - Select Compute Cloud.
- In the left-hand panel, select
Instance groups. - Click
group-for-load
. - Click
Edit. - Under Instance template, click
and select Edit.- Under Disks and file storages, enter the new disk size of
35 GB
. - Click Save.
- Under Disks and file storages, enter the new disk size of
- Click Save.
- Under VM states, you will see the disk size modifications for all VMs in the instance group, one by one.
-
In
specification.yaml
, enter the new disk size of 35 GB and save the file:... size: 35G ...
-
Update the instance group:
yc compute instance-group update --name=group-for-load --file=specification.yaml
Result:
done (9m24s) id: cl10kktrjcn8******** folder_id: b1g7gvsi89m3******** ... name: load-generator service_account_id: ajehbk07uus3******** status: ACTIVE
-
In the spec, enter the new disk size of 35 GB:
... size: 35G ...
-
To update the
load-generator
instance group based on the new spec, use the updateFromYaml REST API method for the InstanceGroup resource or the InstanceGroupService/UpdateFromYaml gRPC API call.
Stop the load and get the results
Stop wrk
by pressing Ctrl + C.
Result:
Thread Stats Avg Stdev Max +/- Stdev
Latency 10.00s 1.70ms 10.01s 68.21%
Req/Sec 0.00 0.00 0.00 100.00%
1148 requests in 17.47m, 211.89KB read
Requests/sec: 1.09
Transfer/sec: 206.94B
If the result contains no error line, such asSocket errors
, it means the system has processed all requests.
How to delete the resources you created
To delete the created resources:
- Delete the load balancer:
- In the management console
, select the folder where you created the load balancer. - From the list of services, select Network Load Balancer.
- To the right of the
load-generator
line, click and select Delete. - In the window that opens, click Delete.
- In the management console
- Delete the instance group:
- In the management console
, select the folder where you created the instance group. - From the list of services, select Compute Cloud.
- In the left-hand panel, select
Instance groups. - To the right of the
load-generator
line, click and select Delete. - In the window that opens, click Delete.
- In the management console
- Delete the service account:
- In the management console
, select the folder where you created the service account. - From the list of services, select Identity and Access Management.
- In the left-hand panel, select
Service accounts. - In the list that opens, click
and select Delete in the row with theyc-auto-sa
service account. - In the window that opens, click Delete.
- In the management console
- Delete the network and subnets:
- In the management console
, select the folder where you created the network and subnets. - From the list of services, select Virtual Private Cloud.
- Select
yc-auto-network
. - Under Subnets:
- To the right of the
yc-auto-subnet-1
line, click and select Delete. - In the window that opens, click Delete.
- Delete the
yc-auto-subnet-2
subnet as well.
- To the right of the
- In the top-right corner, click Delete.
- In the management console
Run these commands one by one:
yc load-balancer network-load-balancer delete load-generator
yc compute instance-group delete load-generator
yc iam service-account delete yc-auto-sa
yc vpc subnet delete yc-auto-subnet-1
yc vpc subnet delete yc-auto-subnet-2
yc vpc network delete yc-auto-network
- Delete the
load-generator
load balancer using the delete REST API method for the NetworkLoadBalancer resource or the NetworkLoadBalancerService/Delete gRPC API call. - Delete the
load-generator
instance group using the delete REST API method for the InstanceGroup resource or the InstanceGroupService/Delete gRPC API call. - Delete the
yc-auto-sa
service account using the delete REST API method for the ServiceAccount resource or the ServiceAccountService/Delete gRPC API call. - Delete the
yc-auto-subnet-1
andyc-auto-subnet-2
subnets using the delete REST API method for the Subnet resource or the SubnetService/Delete gRPC API call. - Delete the
yc-auto-network
network using the delete REST API method for the Network resource or the NetworkService/Delete gRPC API call.