Skip to content

Commit 9052639

Browse files
Merge pull request #193742 from ramiMSFT/container-apps/auto-scaling
Keda scalers
2 parents 5147a7e + 475baee commit 9052639

File tree

7 files changed

+172
-10
lines changed

7 files changed

+172
-10
lines changed
84.5 KB
Loading
74.8 KB
Loading
25.1 KB
Loading
80.5 KB
Loading
32 KB
Loading
32.7 KB
Loading

articles/container-apps/scale-app.md

Lines changed: 172 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ ms.custom: ignite-fall-2021
1212

1313
# Set scaling rules in Azure Container Apps
1414

15-
Azure Container Apps manages automatic horizontal scaling through a set of declarative scaling rules. As a container app scales out, new instances of the container app are created on-demand. These instances are known as replicas.
15+
Azure Container Apps manages automatic horizontal scaling through a set of declarative scaling rules. As a container app scales out, new instances of the container app are created on-demand. These instances are known as replicas. When you first create a container app, the scale rule is set to zero. No charges are incurred when an application scales to zero.
1616

17-
Scaling rules are defined in `resources.properties.template.scale` section of the [configuration](overview.md). There are two scale properties that apply to all rules in your container app.
17+
Scaling rules are defined in `resources.properties.template.scale` section of the JSON configuration file. When you add or edit existing scaling rules, a new revision of your container is automatically created with the new configuration. A revision is an immutable snapshot of your container app and it gets created automatically when certain aspects of your application are updated (scaling rules, Dapr settings, template configuration etc.). See the [Change types](./revisions.md#change-types) section to learn about the type of changes that do or don't trigger a new revision.
18+
19+
There are two scale properties that apply to all rules in your container app:
1820

1921
| Scale property | Description | Default value | Min value | Max value |
2022
|---|---|---|---|---|
@@ -25,25 +27,29 @@ Scaling rules are defined in `resources.properties.template.scale` section of th
2527
- Individual scale rules are defined in the `rules` array.
2628
- If you want to ensure that an instance of your application is always running, set `minReplicas` to 1 or higher.
2729
- Replicas not processing, but that remain in memory are billed in the "idle charge" category.
28-
- Changes to scaling rules are a [revision-scope](overview.md) change.
30+
- Changes to scaling rules are a [revision-scope](./revisions.md#revision-scope-changes) change.
2931
- When using non-HTTP event scale rules, setting the `activeRevisionMode` to `single` is recommended.
3032

3133
> [!IMPORTANT]
3234
> Replica quantities are a target amount, not a guarantee. Even if you set `maxReplicas` to `1`, there is no assurance of thread safety.
3335
3436
## Scale triggers
3537

36-
Container Apps supports a large number of scale triggers. For more information about supported scale triggers, see [KEDA Scalers](https://keda.sh/docs/scalers/).
38+
Azure Container Apps supports the following scale triggers:
3739

38-
The KEDA documentation shows code examples in YAML, while the Container Apps ARM template is in JSON. As you transform examples from KEDA for your needs, make sure to switch property names from [kebab](https://en.wikipedia.org/wiki/Naming_convention_(programming)#Delimiter-separated_words) case to [camel](https://en.wikipedia.org/wiki/Naming_convention_(programming)#Letter_case-separated_words) casing.
40+
- [HTTP traffic](#http): Scaling based on the number of concurrent HTTP requests to your revision.
41+
- [Event-driven](#event-driven): Event-based triggers such as messages in an Azure Service Bus.
42+
- [CPU](#cpu) or [Memory](#memory) usage: Scaling based on the amount of CPU or memory consumed by a replica.
3943

4044
## HTTP
4145

4246
With an HTTP scaling rule, you have control over the threshold that determines when to scale out.
4347

4448
| Scale property | Description | Default value | Min value | Max value |
4549
|---|---|---|---|---|
46-
| `concurrentRequests`| Once the number of requests exceeds this value, then more replicas are added, up to the `maxReplicas` amount. | 50 | 1 | n/a |
50+
| `concurrentRequests`| Once the number of requests exceeds this then another replica is added. Replicas will continue to be added up to the `maxReplicas` amount as the number of concurrent requests increase. | 100 | 1 | n/a |
51+
52+
In the following example, the container app scales out up to five replicas and can scale down to zero. The scaling threshold is set to 100 concurrent requests per second.
4753

4854
```json
4955
{
@@ -72,7 +78,30 @@ With an HTTP scaling rule, you have control over the threshold that determines w
7278
}
7379
```
7480

75-
In this example, the container app scales out up to five replicas and can scale down to zero instances. The scaling threshold is set to 100 concurrent requests per second.
81+
### Add an HTTP scale trigger to a Container App in single-revision mode
82+
83+
> [!NOTE]
84+
> Revisions are immutable. Changing scale rules automatically generates a new revision.
85+
86+
1. Open Azure portal, and navigate to your container app.
87+
88+
1. Select **Scale**, then select your revision from the dropdown menu.
89+
90+
:::image type="content" source="media/scalers/scale-revisions.png" alt-text="A screenshot showing revisions scale.":::
91+
92+
1. Select **Edit and deploy**.
93+
94+
1. Select **Scale**, and then select **Add**.
95+
96+
:::image type="content" source="media/scalers/add-scale-rule.png" alt-text="A screenshot showing how to add a scale rule.":::
97+
98+
1. Select **HTTP scaling** and enter a **Rule name** and the number of **Concurrent requests** for your scale rule and then select **Add**.
99+
100+
:::image type="content" source="media/scalers/http-scale-rule.png" alt-text="A screenshot showing how to add an h t t p scale rule.":::
101+
102+
1. Select **Create** when you are done.
103+
104+
:::image type="content" source="media/scalers/create-http-scale-rule.png" alt-text="A screenshot showing the newly created http scale rule.":::
76105

77106
## Event-driven
78107

@@ -82,6 +111,11 @@ Each event type features different properties in the `metadata` section of the K
82111

83112
The following example shows how to create a scale rule based on an [Azure Service Bus](https://keda.sh/docs/scalers/azure-service-bus/) trigger.
84113

114+
The container app scales according to the following behavior:
115+
116+
- For every 20 messages placed in the queue, a new replica is created.
117+
- The connection string to the queue is provided as a parameter to the configuration file and referenced via the `secretRef` property.
118+
85119
```json
86120
{
87121
...
@@ -117,10 +151,135 @@ The following example shows how to create a scale rule based on an [Azure Servic
117151
}
118152
```
119153

120-
In this example, the container app scales according to the following behavior:
154+
> [!NOTE]
155+
> Upstream KEDA scale rules are defined using Kubernetes YAML, while Azure Container Apps supports ARM templates, Bicep Templates and Container Apps specific YAML. The following example uses an ARM template and therefore the rules need to switch property names from [kebab](https://en.wikipedia.org/wiki/Naming_convention_(programming)#Delimiter-separated_words) case to [camel](https://en.wikipedia.org/wiki/Naming_convention_(programming)#Letter_case-separated_words) when translating from existing KEDA manifests.
121156

122-
- As the messages count in the queue exceeds 20, new replicas are created.
123-
- The connection string to the queue is provided as a parameter to the configuration file and referenced via the `secretRef` property.
157+
### Set up a connection string secret
158+
159+
To create a custom scale trigger, first create a connection string secret to authenticate with the different custom scalers.
160+
161+
1. In Azure portal, navigate to your container app and then select **Secrets**.
162+
163+
1. Select **Add**, and then enter your secret key/value information.
164+
165+
1. Select **Add** when you are done.
166+
167+
:::image type="content" source="media/scalers/connection-string.png" alt-text="A screenshot showing how to create a connection string.":::
168+
169+
### Add a custom scale trigger
170+
171+
1. In Azure portal, select **Scale** and then select your revision from the dropdown menu.
172+
173+
:::image type="content" source="media/scalers/scale-revisions.png" alt-text="A screenshot showing the revisions scale page.":::
174+
175+
1. Select **Edit and deploy**.
176+
177+
1. Select **Scale**, and then select **Add**.
178+
179+
:::image type="content" source="media/scalers/add-scale-rule.png" alt-text="A screenshot showing how to add a scale rule.":::
180+
181+
1. Enter a **Rule name**, select **Custom** and enter a **Custom rule type**. Enter your **Secret reference** and **Trigger parameter** and then add your **Metadata** parameters. select **Add** when you are done.
182+
183+
:::image type="content" source="media/scalers/custom-scaler.png" alt-text="A screenshot showing how to configure a custom scale rule.":::
184+
185+
1. Select **Create** when you are done.
186+
187+
> [!NOTE]
188+
> In multiple revision mode, adding a new scale trigger creates a new revision of your application but your old revision remains available with the old scale rules. Use the **Revision management** page to manage their traffic allocations.
189+
190+
### KEDA scalers conversion
191+
192+
Azure Container Apps supports KEDA ScaledObjects and all of the available [KEDA scalers](https://keda.sh/docs/scalers/). To convert KEDA templates, it's easier to start with a custom JSON template and add the parameters you need based on the scenario and the scale trigger you want to set up.
193+
194+
```json
195+
{
196+
...
197+
"resources": {
198+
...
199+
"properties": {
200+
"configuration": {
201+
"secrets": [{
202+
"name": "<YOUR_CONNECTION_STRING_NAME>",
203+
"value": "<YOUR-CONNECTION-STRING>"
204+
}],
205+
},
206+
"template": {
207+
...
208+
"scale": {
209+
"minReplicas": "0",
210+
"maxReplicas": "10",
211+
"rules": [
212+
{
213+
"name": "<YOUR_TRIGGER_NAME>",
214+
"custom": {
215+
"type": "<TRIGGER_TYPE>",
216+
"metadata": {
217+
},
218+
"auth": [{
219+
"secretRef": "<YOUR_CONNECTION_STRING_NAME>",
220+
"triggerParameter": "<TRIGGER_PARAMETER>"
221+
}]
222+
}
223+
}]
224+
}
225+
```
226+
227+
The following is an example of setting up an [Azure Storage Queue](https://keda.sh/docs/scalers/azure-storage-queue/) scaler that you can configure to auto scale based on Azure Storage Queues.
228+
229+
Below is the KEDA trigger specification for an Azure Storage Queue. To set up a scale rule in Azure Container Apps, you will need the trigger `type` and any other required parameters. You can also add other optional parameters which vary based on the scaler you are using.
230+
231+
In this example, you need the `accountName` and the name of the cloud environment that the queue belongs to `cloud` to set up your scaler in Azure Container Apps.
232+
233+
```yml
234+
triggers:
235+
- type: azure-queue
236+
metadata:
237+
queueName: orders
238+
queueLength: '5'
239+
connectionFromEnv: STORAGE_CONNECTIONSTRING_ENV_NAME
240+
accountName: storage-account-name
241+
cloud: AzureUSGovernmentCloud
242+
```
243+
244+
Now your JSON config file should look like this:
245+
246+
```json
247+
{
248+
...
249+
"resources": {
250+
...
251+
"properties": {
252+
"configuration": {
253+
"secrets": [{
254+
"name": "my-connection-string",
255+
"value": "*********"
256+
}],
257+
},
258+
"template": {
259+
...
260+
"scale": {
261+
"minReplicas": "0",
262+
"maxReplicas": "10",
263+
"rules": [
264+
{
265+
"name": "queue-trigger",
266+
"custom": {
267+
"type": "azure-queue",
268+
"metadata": {
269+
"accountName": "my-storage-account-name",
270+
"cloud": "AzurePublicCloud"
271+
},
272+
"auth": [{
273+
"secretRef": "my-connection-string",
274+
"triggerParameter": "connection"
275+
}]
276+
}
277+
}]
278+
}
279+
```
280+
281+
> [!NOTE]
282+
> KEDA ScaledJobs are not supported. See [KEDA scaling Jobs](https://keda.sh/docs/concepts/scaling-jobs/#overview) for more details.
124283

125284
## CPU
126285

@@ -201,9 +360,12 @@ The following example shows how to create a memory scaling rule.
201360
## Considerations
202361

203362
- Vertical scaling is not supported.
363+
204364
- Replica quantities are a target amount, not a guarantee.
205365
- Even if you set `maxReplicas` to `1`, there is no assurance of thread safety.
206366

367+
- If you are using [Dapr actors](https://docs.dapr.io/developing-applications/building-blocks/actors/actors-overview/) to manage states, you should keep in mind that scaling to zero is not supported. Dapr uses virtual actors to manage asynchronous calls which means their in-memory representation is not tied to their identity or lifetime.
368+
207369
## Next steps
208370

209371
> [!div class="nextstepaction"]

0 commit comments

Comments
 (0)