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
@@ -37,7 +37,7 @@ Create and deploy your container app with the `containerapp up` command. This co
37
37
38
38
If any of these resources already exist, the command uses the existing resources rather than creating new ones.
39
39
40
-
Lastly, the command creates and deploys the container app using a public container image.
40
+
Lastly, the command creates and deploys the container app using a public container image, `mcr.microsoft.com/dotnet/samples:aspnetapp`. This image is used to trigger the scale rules you create in this article. You don't need to know or use .NET to complete this procedure.
By setting `--ingress` to `external`, you make the container app available to public requests.
76
76
77
-
The `up` command returns the fully qualified domain name (FQDN) for the container app. Copy this FQDN to a text file. You'll use it in the [Send requests](#send-requests) section. Your FQDN looks like the following example:
77
+
The `up` command returns the fully qualified domain name (FQDN) for the container app. Copy this FQDN to a text file. You use it in the [Send requests](#send-requests) section. Your FQDN looks like the following example:
1. By default, the graph scale is set to last 24 hours, with a time granularity of 15 minutes. Select the scale and change it to the last 30 minutes, with a time granularity of one minute. Select the **Apply** button.
290
+
286
291
1. Select on the graph and drag to highlight the recent increase in requests received by your container app.
287
292
288
-
:::image type="content" source="media/scale-app/azure-container-apps-scale-replicas-metrics-2.png" alt-text="Screenshot of container app metrics graph, showing requests split by replica, with a scale of 30 minutes and time granularity of one minute.":::
293
+
:::image type="content" source="media/scale-app/azure-container-apps-scale-replicas-metrics-2.png" alt-text="Screenshot of container app metrics graph, showing requests split by replica, with a scale of 30 minutes and time granularity of one minute.":::
294
+
295
+
The following screenshot shows a zoomed view of how the requests received by your container app are divided among replicas.
296
+
297
+
:::image type="content" source="media/scale-app/azure-container-apps-scale-replicas-metrics-3.png" alt-text="Screenshot of container app metrics graph, showing requests split by replica, in a zoomed view.":::
298
+
299
+
## CPU and memory scaling
300
+
301
+
You should prefer [HTTP scale rules](/azure/container-apps/scale-app#http) to CPU or memory scale rules when possible. CPU and memory scaling don't allow your container app to scale to zero.
302
+
303
+
After you add a CPU or memory scale rule, you can test it by [sending requests to your container app](#send-requests) and [viewing the scaling in Azure portal](#view-scaling-in-azure-portal-optional).
304
+
305
+
After you send requests to your scale app, it might take a minute before the scale rule is triggered and the new replicas are created.
306
+
307
+
### CPU scaling
308
+
309
+
CPU scaling allows your app to scale in or out depending on how much the CPU is being used.
310
+
311
+
For example, if you create a CPU scale rule with a utilization value of `50`, Azure Container Apps creates more replicas of your container app when the average CPU utilization for all replicas reaches 50%.
312
+
313
+
CPU scaling doesn't allow your container app to scale to zero. For more information about this trigger, see [KEDA CPU scale trigger](https://keda.sh/docs/scalers/cpu/).
314
+
315
+
Add a CPU scale rule to your container app by running the `az containerapp update` command.
316
+
317
+
> [!NOTE]
318
+
> When you use the Azure CLI to add a scale rule to a container app that already has a scale rule, the new scale rule replaces the old scale rule. To see how to add multiple scale rules, see [Multiple scale rules](#multiple-scale-rules).
319
+
320
+
Before running the following command, replace the `<PLACEHOLDERS>` with your values. For this tutorial, replace `<UTILIZATION>` with `1`. This causes your container app to scale when the average CPU utilization for all replicas reaches 1%. This value is for demonstration only. The number of replicas is limited to 10 by the `--max-replicas 10` you specified when running `az containerapp update`.
Memory scaling allows your app to scale in or out depending on how much memory is being used.
353
+
354
+
For example, if you create a memory scale rule with a utilization value of `50`, Azure Container Apps creates more replicas of your container app when the average memory utilization for all replicas reaches 50%.
289
355
290
-
The following screenshot shows a zoomed view of how the requests received by your container app are divided among replicas.
356
+
Memory scaling doesn't allow your container app to scale to zero. For more information about this trigger, see [KEDA memory scale trigger](https://keda.sh/docs/scalers/memory/).
357
+
358
+
Add a memory scale rule to your container app by running the `az containerapp update` command.
359
+
360
+
> [!NOTE]
361
+
> When you use the Azure CLI to add a scale rule to a container app that already has a scale rule, the new scale rule replaces the old scale rule. To see how to add multiple scale rules, see [Multiple scale rules](#multiple-scale-rules).
362
+
363
+
Before running the following command, replace the `<PLACEHOLDERS>` with your values. For this tutorial, replace `<UTILIZATION>` with `1`. This causes your container app to scale when the average memory utilization for all replicas reaches 1%. This value is for demonstration only. The number of replicas is limited to 10 by the `--max-replicas 10` you specified when running `az containerapp update`.
:::image type="content" source="media/scale-app/azure-container-apps-scale-replicas-metrics-3.png" alt-text="Screenshot of container app metrics graph, showing requests split by replica, in a zoomed view.":::
393
+
## Multiple scale rules
394
+
395
+
To add multiple scale rules to your container app using the Azure CLI, you must use YAML.
396
+
397
+
1. Export your container app configuration to YAML with the `az containerapp show` command.
398
+
399
+
# [Bash](#tab/bash)
400
+
401
+
```azurecli
402
+
az containerapp show \
403
+
--name my-container-app \
404
+
--resource-group my-container-apps \
405
+
--output yaml > app.yaml
406
+
```
407
+
408
+
# [PowerShell](#tab/powershell)
409
+
410
+
```powershell
411
+
az containerapp show `
412
+
--name my-container-app `
413
+
--resource-group my-container-apps `
414
+
--output yaml > app.yaml
415
+
```
416
+
417
+
---
418
+
419
+
1. In the `properties` > `template` > `scale` > `rules` section of `app.yaml`, add the following properties. Replace the `<PLACEHOLDERS>` with your values.
420
+
421
+
```yaml
422
+
...
423
+
properties:
424
+
...
425
+
template:
426
+
...
427
+
scale:
428
+
...
429
+
rules:
430
+
- name: cpu-scaling-rule
431
+
custom:
432
+
type: cpu
433
+
metadata:
434
+
type: "Utilization"
435
+
value: "<CPU_UTILIZATION>"
436
+
- name: memory-scaling-rule
437
+
custom:
438
+
type: memory
439
+
metadata:
440
+
type: "Utilization"
441
+
value: "<MEMORY_UTILIZATION>"
442
+
...
443
+
```
444
+
445
+
1. Import your container app configuration from `app.yaml` with the `az containerapp update` command.
446
+
447
+
# [Bash](#tab/bash)
448
+
449
+
```azurecli
450
+
az containerapp update \
451
+
--name my-container-app \
452
+
--resource-group my-container-apps \
453
+
--yaml app.yaml
454
+
```
455
+
456
+
# [PowerShell](#tab/powershell)
457
+
458
+
```powershell
459
+
az containerapp update `
460
+
--name my-container-app `
461
+
--resource-group my-container-apps `
462
+
--yaml app.yaml
463
+
```
464
+
465
+
---
293
466
294
467
## Clean up resources
295
468
296
469
If you're not going to continue to use this application, run the following command to delete the resource group along with all the resources created in this tutorial.
297
470
298
471
>[!CAUTION]
299
-
> The following command deletes the specified resource group and all resources contained within it. If resources outside the scope of this tutorial exist in the specified resource group, they will also be deleted.
472
+
> The following command deletes the specified resource group and all resources contained within it. If resources outside the scope of this tutorial exist in the specified resource group, they'll also be deleted.
0 commit comments