You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/virtual-machine-scale-sets/tutorial-autoscale-cli.md
+9-42Lines changed: 9 additions & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,16 +6,12 @@ ms.author: jushiman
6
6
ms.topic: tutorial
7
7
ms.service: virtual-machine-scale-sets
8
8
ms.subservice: autoscale
9
-
ms.date: 11/22/2022
9
+
ms.date: 12/16/2022
10
10
ms.reviewer: mimckitt
11
11
ms.custom: avverma, devx-track-azurecli
12
12
13
13
---
14
14
# Tutorial: Automatically scale a Virtual Machine Scale Set with the Azure CLI
15
-
16
-
> [!NOTE]
17
-
> This tutorial uses Uniform Orchestration mode. We recommend using Flexible Orchestration for new workloads. For more information, see [Orchesration modes for Virtual Machine Scale Sets in Azure](virtual-machine-scale-sets-orchestration-modes.md).
18
-
19
15
When you create a scale set, you define the number of VM instances that you wish to run. As your application demand changes, you can automatically increase or decrease the number of VM instances. The ability to autoscale lets you keep up with customer demand or respond to application performance changes throughout the lifecycle of your app. In this tutorial you learn how to:
20
16
21
17
> [!div class="checklist"]
@@ -31,28 +27,26 @@ When you create a scale set, you define the number of VM instances that you wish
31
27
- This tutorial requires version 2.0.32 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is already installed.
32
28
33
29
## Create a scale set
34
-
35
-
Create a resource group with [az group create](/cli/azure/group) as follows:
30
+
Create a resource group with [az group create](/cli/azure/group).
36
31
37
32
```azurecli-interactive
38
33
az group create --name myResourceGroup --location eastus
39
34
```
40
35
41
-
Now create a Virtual Machine Scale Set with [az vmss create](/cli/azure/vmss). The following example creates a scale set with an instance count of *2*, and generates SSH keys if they do not exist:
36
+
Now create a Virtual Machine Scale Set with [az vmss create](/cli/azure/vmss). The following example creates a scale set with an instance count of *2*, and generates SSH keys if they don't exist.
42
37
43
38
```azurecli-interactive
44
39
az vmss create \
45
40
--resource-group myResourceGroup \
46
41
--name myScaleSet \
47
42
--image UbuntuLTS \
48
-
--upgrade-policy-mode automatic \
43
+
--orchestration-mode Flexible \
49
44
--instance-count 2 \
50
45
--admin-username azureuser \
51
46
--generate-ssh-keys
52
47
```
53
48
54
49
## Define an autoscale profile
55
-
56
50
To enable autoscale on a scale set, you first define an autoscale profile. This profile defines the default, minimum, and maximum scale set capacity. These limits let you control cost by not continually creating VM instances, and balance acceptable performance with a minimum number of instances that remain in a scale-in event. Create an autoscale profile with [az monitor autoscale create](/cli/azure/monitor/autoscale#az-monitor-autoscale-create). The following example sets the default, and minimum, capacity of *2* VM instances, and a maximum of *10*:
57
51
58
52
```azurecli-interactive
@@ -67,10 +61,9 @@ az monitor autoscale create \
67
61
```
68
62
69
63
## Create a rule to autoscale out
64
+
If your application demand increases, the load on the VM instances in your scale set increases. If this increased load is consistent, rather than just a brief demand, you can configure autoscale rules to increase the number of VM instances in the scale set. When these VM instances are created and your applications are deployed, the scale set starts to distribute traffic to them through the load balancer. You control what metrics to monitor, how long the application load must meet a given threshold, and how many VM instances to add to the scale set.
70
65
71
-
If your application demand increases, the load on the VM instances in your scale set increases. If this increased load is consistent, rather than just a brief demand, you can configure autoscale rules to increase the number of VM instances in the scale set. When these VM instances are created and your applications are deployed, the scale set starts to distribute traffic to them through the load balancer. You control what metrics to monitor, such as CPU or disk, how long the application load must meet a given threshold, and how many VM instances to add to the scale set.
72
-
73
-
Let's create a rule with [az monitor autoscale rule create](/cli/azure/monitor/autoscale/rule#az-monitor-autoscale-rule-create) that increases the number of VM instances in a scale set when the average CPU load is greater than 70% over a 5-minute period. When the rule triggers, the number of VM instances is increased by three.
66
+
Create a rule with [az monitor autoscale rule create](/cli/azure/monitor/autoscale/rule#az-monitor-autoscale-rule-create) that increases the number of VM instances in a scale set when the average CPU load is greater than 70% over a 5-minute period. When the rule triggers, the number of VM instances is increased by three.
74
67
75
68
```azurecli-interactive
76
69
az monitor autoscale rule create \
@@ -81,10 +74,9 @@ az monitor autoscale rule create \
81
74
```
82
75
83
76
## Create a rule to autoscale in
84
-
85
77
On an evening or weekend, your application demand may decrease. If this decreased load is consistent over a period of time, you can configure autoscale rules to decrease the number of VM instances in the scale set. This scale-in action reduces the cost to run your scale set as you only run the number of instances required to meet the current demand.
86
78
87
-
Create another rule with [az monitor autoscale rule create](/cli/azure/monitor/autoscale/rule#az-monitor-autoscale-rule-create) that decreases the number of VM instances in a scale set when the average CPU load then drops below 30% over a 5-minute period. The following example defines the rule to scale in the number of VM instances by one:
79
+
Create another rule with [az monitor autoscale rule create](/cli/azure/monitor/autoscale/rule#az-monitor-autoscale-rule-create) that decreases the number of VM instances in a scale set when the average CPU load then drops below 30% over a 5-minute period. The following example defines the rule to scale in the number of VM instances by one.
88
80
89
81
```azurecli-interactive
90
82
az monitor autoscale rule create \
@@ -95,31 +87,9 @@ az monitor autoscale rule create \
95
87
```
96
88
97
89
## Generate CPU load on scale set
98
-
99
90
To test the autoscale rules, generate some CPU load on the VM instances in the scale set. This simulated CPU load causes the autoscales to scale out and increase the number of VM instances. As the simulated CPU load is then decreased, the autoscale rules scale in and reduce the number of VM instances.
100
91
101
-
First, list the address and ports to connect to VM instances in a scale set with [az vmss list-instance-connection-info](/cli/azure/vmss):
102
-
103
-
```azurecli-interactive
104
-
az vmss list-instance-connection-info \
105
-
--resource-group myResourceGroup \
106
-
--name myScaleSet
107
-
```
108
-
109
-
The following example output shows the instance name, public IP address of the load balancer, and port number that the Network Address Translation (NAT) rules forward traffic to:
110
-
111
-
```json
112
-
{
113
-
"instance 1": "13.92.224.66:50001",
114
-
"instance 3": "13.92.224.66:50003"
115
-
}
116
-
```
117
-
118
-
SSH to your first VM instance. Specify your own public IP address and port number with the `-p` parameter, as shown from the preceding command:
To connect to an individual instance, see [Tutorial: Connect to Virtual Machine Scale Set instances](tutorial-connect-to-instances-cli.md)
123
93
124
94
Once logged in, install the **stress** utility. Start *10***stress** workers that generate CPU load. These workers run for *420* seconds, which is enough to cause the autoscale rules to implement the desired action.
125
95
@@ -166,7 +136,6 @@ exit
166
136
```
167
137
168
138
## Monitor the active autoscale rules
169
-
170
139
To monitor the number of VM instances in your scale set, use **watch**. It takes 5 minutes for the autoscale rules to begin the scale-out process in response to the CPU load generated by **stress** on each of the VM instances:
171
140
172
141
```azurecli-interactive
@@ -193,21 +162,19 @@ Every 2.0s: az vmss list-instances --resource-group myResourceGroup --name mySca
193
162
Once **stress** stops on the initial VM instances, the average CPU load returns to normal. After another 5 minutes, the autoscale rules then scale in the number of VM instances. Scale in actions remove VM instances with the highest IDs first. When a scale set uses Availability Sets or Availability Zones, scale in actions are evenly distributed across those VM instances. The following example output shows one VM instance deleted as the scale set autoscales in:
Exit *watch* with `Ctrl-c`. The scale set continues to scale in every 5 minutes and remove one VM instance until the minimum instance count of two is reached.
200
169
201
170
## Clean up resources
202
-
203
171
To remove your scale set and additional resources, delete the resource group and all its resources with [az group delete](/cli/azure/group). The `--no-wait` parameter returns control to the prompt without waiting for the operation to complete. The `--yes` parameter confirms that you wish to delete the resources without an additional prompt to do so.
204
172
205
173
```azurecli-interactive
206
174
az group delete --name myResourceGroup --yes --no-wait
207
175
```
208
176
209
177
## Next steps
210
-
211
178
In this tutorial, you learned how to automatically scale in or out a scale set with the Azure CLI:
> This tutorial uses Uniform Orchestration mode. We recommend using Flexible Orchestration for new workloads. For more information, see [Orchestration modes for Virtual Machine Scale Sets in Azure](virtual-machine-scale-sets-orchestration-modes.md).
When you create a scale set, you define the number of VM instances that you wish to run. As your application demand changes, you can automatically increase or decrease the number of VM instances. The ability to autoscale lets you keep up with customer demand or respond to application performance changes throughout the lifecycle of your app. In this tutorial you learn how to:
22
20
23
21
> [!div class="checklist"]
@@ -244,7 +242,6 @@ To remove your scale set and additional resources, delete the resource group and
0 commit comments