Skip to content

Commit 358d0fd

Browse files
committed
[ACA] [375448] Add Bicep scale rules.
1 parent d4b9d77 commit 358d0fd

File tree

4 files changed

+284
-10
lines changed

4 files changed

+284
-10
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
...
2+
rules: [
3+
{
4+
name: 'azure-servicebus-queue-rule'
5+
custom: {
6+
type: 'azure-servicebus'
7+
metadata: {
8+
queueName: 'my-queue'
9+
namespace: 'service-bus-namespace'
10+
messageCount: '5'
11+
}
12+
}
13+
}
14+
]
15+
...
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
resource symbolicname 'Microsoft.App/containerApps@2025-02-02-preview' = {
2+
...
3+
properties: {
4+
...
5+
configuration: {
6+
...
7+
secrets: [
8+
{
9+
name: 'connection-string-secret'
10+
value: '<SERVICE_BUS_CONNECTION_STRING>'
11+
}
12+
]
13+
}
14+
template: {
15+
...
16+
scale: {
17+
maxReplicas: 0
18+
minReplicas: 5
19+
rules: [
20+
{
21+
name: 'azure-servicebus-queue-rule'
22+
custom: {
23+
type: 'azure-servicebus'
24+
metadata: {
25+
queueName: 'my-queue'
26+
namespace: 'service-bus-namespace'
27+
messageCount: '5'
28+
}
29+
auth: [
30+
{
31+
secretRef: 'connection-string-secret'
32+
triggerParameter: 'connection'
33+
}
34+
]
35+
}
36+
}
37+
]
38+
}
39+
}
40+
}
41+
}

articles/container-apps/scale-app.md

Lines changed: 215 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ author: craigshoemaker
66
ms.service: azure-container-apps
77
ms.custom: devx-track-azurecli
88
ms.topic: conceptual
9-
ms.date: 04/17/2025
9+
ms.date: 05/19/2025
1010
ms.author: cshoe
11-
zone_pivot_groups: arm-azure-cli-portal
11+
zone_pivot_groups: arm-azure-cli-portal-bicep
1212
---
1313

1414
# Set scaling rules in Azure Container Apps
@@ -71,6 +71,45 @@ In the following example, the revision scales out up to five replicas and can sc
7171

7272
### Example
7373

74+
::: zone pivot="container-apps-bicep"
75+
76+
The `http` section defines an HTTP scale rule.
77+
78+
| Scale property | Description | Default value | Min value | Max value |
79+
|---|---|---|---|---|
80+
| `concurrentRequests`| When the number of HTTP requests exceeds this value, then another replica is added. Replicas continue to add to the pool up to the `maxReplicas` amount. | 10 | 1 | n/a |
81+
82+
```bicep
83+
resource symbolicname 'Microsoft.App/containerApps@2025-02-02-preview' = {
84+
...
85+
properties: {
86+
...
87+
template: {
88+
...
89+
scale: {
90+
maxReplicas: 0
91+
minReplicas: 5
92+
rules: [
93+
{
94+
name: 'http-rule'
95+
http: {
96+
metadata: {
97+
concurrentRequests: '100'
98+
}
99+
}
100+
}
101+
]
102+
}
103+
}
104+
}
105+
}
106+
```
107+
108+
> [!NOTE]
109+
> Set the `properties.configuration.activeRevisionsMode` property of the container app to `single`, when using non-HTTP event scale rules.
110+
111+
::: zone-end
112+
74113
::: zone pivot="azure-resource-manager"
75114

76115
The `http` section defines an HTTP scale rule.
@@ -166,13 +205,49 @@ In the following example, the container app revision scales out up to five repli
166205

167206
### Example
168207

208+
::: zone pivot="container-apps-bicep"
209+
210+
The `tcp` section defines an TCP scale rule.
211+
212+
| Scale property | Description | Default value | Min value | Max value |
213+
|---|---|---|---|---|
214+
| `concurrentConnections`| When the number of concurrent TCP connections exceeds this value, then another replica is added. Replicas continue to be added up to the `maxReplicas` amount as the number of concurrent connections increases. | 10 | 1 | n/a |
215+
216+
```bicep
217+
resource symbolicname 'Microsoft.App/containerApps@2025-02-02-preview' = {
218+
...
219+
properties: {
220+
...
221+
template: {
222+
...
223+
scale: {
224+
maxReplicas: 0
225+
minReplicas: 5
226+
rules: [
227+
{
228+
name: 'tcp-rule'
229+
http: {
230+
metadata: {
231+
concurrentConnections: '100'
232+
}
233+
}
234+
}
235+
]
236+
}
237+
}
238+
}
239+
}
240+
```
241+
242+
::: zone-end
243+
169244
::: zone pivot="azure-resource-manager"
170245

171246
The `tcp` section defines a TCP scale rule.
172247

173248
| Scale property | Description | Default value | Min value | Max value |
174249
|---|---|---|---|---|
175-
| `concurrentConnections`| When the number of concurrent TCP connections exceeds this value, then another replica is added. Replicas continue to be added up to the `maxReplicas` amount as the number of concurrent connections increase. | 10 | 1 | n/a |
250+
| `concurrentConnections`| When the number of concurrent TCP connections exceeds this value, then another replica is added. Replicas continue to be added up to the `maxReplicas` amount as the number of concurrent connections increases. | 10 | 1 | n/a |
176251

177252
```json
178253
{
@@ -231,7 +306,7 @@ az containerapp create \
231306

232307
::: zone pivot="azure-portal"
233308

234-
Not supported in the Azure portal. Use the [Azure CLI](scale-app.md?pivots=azure-cli#tcp) or [Azure Resource Manager](scale-app.md?&pivots=azure-resource-manager#tcp) to configure a TCP scale rule.
309+
Not supported in the Azure portal. Use the [Azure CLI](scale-app.md?pivots=azure-cli#tcp), [Azure Resource Manager](scale-app.md?&pivots=azure-resource-manager#tcp), or [Bicep](scale-app.md?&pivots=container-apps-bicep#tcp) to configure a TCP scale rule.
235310

236311
::: zone-end
237312

@@ -254,6 +329,134 @@ This example shows how to convert an [Azure Service Bus scaler](https://keda.sh/
254329

255330
For authentication, KEDA scaler authentication parameters take [Container Apps secrets](manage-secrets.md) or [managed identity](managed-identity.md#scale-rules).
256331

332+
::: zone pivot="container-apps-bicep"
333+
334+
The following procedure shows you how to convert a KEDA scaler to a Container App scale rule. This snippet is an excerpt of a Bicep template to show you where each section fits in context of the overall template.
335+
336+
```bicep
337+
resource symbolicname 'Microsoft.App/containerApps@2025-02-02-preview' = {
338+
...
339+
properties: {
340+
...
341+
configuration: {
342+
...
343+
secrets: [
344+
{
345+
name: '<NAME>'
346+
value: '<VALUE>'
347+
}
348+
]
349+
}
350+
template: {
351+
...
352+
scale: {
353+
maxReplicas: 0
354+
minReplicas: 5
355+
rules: [
356+
{
357+
name: '<RULE_NAME>'
358+
custom: {
359+
metadata: {
360+
...
361+
}
362+
auth: [
363+
{
364+
secretRef: '<NAME>'
365+
triggerParameter: '<PARAMETER>'
366+
}
367+
]
368+
}
369+
}
370+
]
371+
}
372+
}
373+
}
374+
}
375+
```
376+
377+
Refer to this excerpt for context on how the below examples fit in the Bicep template.
378+
379+
First, you define the type and metadata of the scale rule.
380+
381+
1. From the KEDA scaler specification, find the `type` value.
382+
383+
:::code language="json" source="./code/keda-azure-service-bus-trigger.json" highlight="2":::
384+
385+
1. In the Bicep template, enter the scaler `type` value into the `custom.type` property of the scale rule.
386+
387+
:::code language="bicep" source="./code/container-apps-azure-service-bus-rule-0.bicep" highlight="6":::
388+
389+
1. From the KEDA scaler specification, find the `metadata` values.
390+
391+
:::code language="json" source="./code/keda-azure-service-bus-trigger.json" highlight="4,5,6":::
392+
393+
1. In the Bicep template, add all metadata values to the `custom.metadata` section of the scale rule.
394+
395+
:::code language="json" source="./code/container-apps-azure-service-bus-rule-0.json" highlight="8,9,10":::
396+
397+
### Authentication
398+
399+
Container Apps scale rules support secrets-based authentication. Scale rules for Azure resources, including Azure Queue Storage, Azure Service Bus, and Azure Event Hubs, also support managed identity. Where possible, use managed identity authentication to avoid storing secrets within the app.
400+
401+
#### Use secrets
402+
403+
To use secrets for authentication, you need to create a secret in the container app's `secrets` array. The secret value is used in the `auth` array of the scale rule.
404+
405+
KEDA scalers can use secrets in a [TriggerAuthentication](https://keda.sh/docs/latest/concepts/authentication/) that is referenced by the `authenticationRef` property. You can map the TriggerAuthentication object to the Container Apps scale rule.
406+
407+
1. Find the `TriggerAuthentication` object referenced by the KEDA `ScaledObject` specification.
408+
409+
1. In the `TriggerAuthentication` object, find each `secretTargetRef` and its associated secret.
410+
411+
:::code language="yml" source="./code/keda-azure-service-bus-auth.json" highlight="8,16,17,18":::
412+
413+
1. In the Bicep template, for each secret:
414+
415+
1. Add a [secret](./manage-secrets.md) to the container app's `secrets` array containing the secret name and value.
416+
417+
1. Add an entry to the `auth` array of the scale rule.
418+
419+
1. Set the value of the `triggerParameter` property to the value of the `secretTargetRef`'s `parameter` property.
420+
421+
1. Set the value of the `secretRef` property to the name of the `secretTargetRef`'s `key` property.
422+
423+
:::code language="json" source="./code/container-apps-azure-service-bus-rule-1.json" highlight="8-11,30-33":::
424+
425+
Some scalers support metadata with the `FromEnv` suffix to reference a value in an environment variable. Container Apps looks at the first container listed in the ARM template for the environment variable.
426+
427+
Refer to the [considerations section](#considerations) for more security related information.
428+
429+
#### Using managed identity
430+
431+
Container Apps scale rules can use managed identity to authenticate with Azure services. The following Bicep template passes in system-based managed identity to authenticate for an Azure Queue scaler.
432+
433+
```bicep
434+
scale: {
435+
minReplicas: 0
436+
maxReplicas: 4
437+
rules: [
438+
{
439+
name: 'azure-queue'
440+
custom: {
441+
type: 'azure-queue'
442+
metadata: {
443+
accountName: '<ACCOUNT_NAME>'
444+
queueName: '<QUEUE_NAME>'
445+
queueLength: '1'
446+
},
447+
identity: 'system'
448+
}
449+
}
450+
]
451+
}
452+
```
453+
454+
Replace the `<PLACEHOLDERS`> with your values.
455+
456+
To learn more about using managed identity with scale rules, see [Managed identity](managed-identity.md#scale-rules).
457+
458+
::: zone-end
459+
257460
::: zone pivot="azure-resource-manager"
258461

259462
The following procedure shows you how to convert a KEDA scaler to a Container App scale rule. This snippet is an excerpt of an ARM template to show you where each section fits in context of the overall template.
@@ -308,15 +511,15 @@ First, you define the type and metadata of the scale rule.
308511

309512
1. From the KEDA scaler specification, find the `type` value.
310513

311-
:::code language="yml" source="./code/keda-azure-service-bus-trigger.json" highlight="2":::
514+
:::code language="json" source="./code/keda-azure-service-bus-trigger.json" highlight="2":::
312515

313516
1. In the ARM template, enter the scaler `type` value into the `custom.type` property of the scale rule.
314517

315518
:::code language="json" source="./code/container-apps-azure-service-bus-rule-0.json" highlight="6":::
316519

317520
1. From the KEDA scaler specification, find the `metadata` values.
318521

319-
:::code language="yml" source="./code/keda-azure-service-bus-trigger.json" highlight="4,5,6":::
522+
:::code language="json" source="./code/keda-azure-service-bus-trigger.json" highlight="4,5,6":::
320523

321524
1. In the ARM template, add all metadata values to the `custom.metadata` section of the scale rule.
322525

@@ -358,7 +561,7 @@ KEDA scalers can use secrets in a [TriggerAuthentication](https://keda.sh/docs/l
358561

359562
Container Apps scale rules can use managed identity to authenticate with Azure services. The following ARM template passes in system-based managed identity to authenticate for an Azure Queue scaler.
360563

361-
```
564+
```json
362565
"scale": {
363566
"minReplicas": 0,
364567
"maxReplicas": 4,
@@ -368,8 +571,8 @@ Container Apps scale rules can use managed identity to authenticate with Azure s
368571
"custom": {
369572
"type": "azure-queue",
370573
"metadata": {
371-
"accountName": "apptest123",
372-
"queueName": "queue1",
574+
"accountName": "<ACCOUNT_NAME>",
575+
"queueName": "<QUEUE_NAME>",
373576
"queueLength": "1"
374577
},
375578
"identity": "system"
@@ -379,6 +582,8 @@ Container Apps scale rules can use managed identity to authenticate with Azure s
379582
}
380583
```
381584

585+
Replace the `<PLACEHOLDERS`> with your values.
586+
382587
To learn more about using managed identity with scale rules, see [Managed identity](managed-identity.md#scale-rules).
383588

384589
::: zone-end
@@ -443,7 +648,7 @@ az containerapp create \
443648
--scale-rule-identity <USER_ASSIGNED_IDENTITY_ID>
444649
```
445650

446-
Replace placeholders with your values.
651+
Replace the `<PLACEHOLDERS`> with your values.
447652

448653
::: zone-end
449654

articles/zone-pivot-groups.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,19 @@ groups:
11961196
title: Azure portal
11971197
- id: azure-resource-manager
11981198
title: ARM template
1199+
# Owner: cshoe
1200+
- id: arm-azure-cli-portal-bicep
1201+
title: Interaction type
1202+
prompt: Select how you want to interact with Azure
1203+
pivots:
1204+
- id: azure-cli
1205+
title: Azure CLI
1206+
- id: azure-portal
1207+
title: Azure portal
1208+
- id: azure-resource-manager
1209+
title: ARM template
1210+
- id: container-apps-bicep
1211+
title: Bicep
11991212
# Owner: ruslany
12001213
- id: azure-cli-bicep
12011214
title: Interaction type

0 commit comments

Comments
 (0)