Skip to content

Commit 69758a8

Browse files
committed
[ACA] Add CPU and memory scale rule examples.
1 parent 1fda18c commit 69758a8

File tree

1 file changed

+155
-1
lines changed

1 file changed

+155
-1
lines changed

articles/container-apps/tutorial-scaling.md

Lines changed: 155 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services: container-apps
55
author: craigshoemaker
66
ms.service: azure-container-apps
77
ms.topic: tutorial
8-
ms.date: 02/03/2025
8+
ms.date: 03/06/2025
99
ms.author: cshoe
1010
ms.custom: devx-track-azurecli
1111
ms.devlang: azurecli
@@ -90,6 +90,8 @@ Add an HTTP scale rule to your container app by running the `az containerapp upd
9090
az containerapp update \
9191
--name my-container-app \
9292
--resource-group my-container-apps \
93+
--min-replicas 1 \
94+
--max-replicas 10 \
9395
--scale-rule-name my-http-scale-rule \
9496
--scale-rule-http-concurrency 1
9597
```
@@ -100,6 +102,8 @@ az containerapp update \
100102
az containerapp update `
101103
--name my-container-app `
102104
--resource-group my-container-apps `
105+
--min-replicas 1 `
106+
--max-replicas 10 `
103107
--scale-rule-name my-http-scale-rule `
104108
--scale-rule-http-concurrency 1
105109
```
@@ -291,6 +295,156 @@ The following screenshot shows a zoomed view of how the requests received by you
291295

292296
:::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.":::
293297

298+
## CPU and memory scaling
299+
300+
You should prefer [HTTP scaling rules](/azure/container-apps/scale-app#http) to CPU or memory scale rules when possible.
301+
302+
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).
303+
304+
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).
305+
306+
### CPU scaling
307+
308+
CPU scaling allows your app to scale in or out depending on how much the CPU is being used. CPU scaling doesn't allow your container app to scale to 0. For more information about this trigger, see [KEDA CPU scale trigger](https://keda.sh/docs/scalers/cpu/).
309+
310+
Add a CPU scale rule to your container app by running the `az containerapp update` command. Replace the `<PLACEHOLDERS>` with your values. The CPU utilization value is the percentage of CPU utilization at which you want to scale your app.
311+
312+
# [Bash](#tab/bash)
313+
314+
```azurecli
315+
az containerapp update \
316+
--name my-container-app \
317+
--resource-group my-container-apps \
318+
--min-replicas 1 \
319+
--max-replicas 10 \
320+
--scale-rule-name my-cpu-scale-rule \
321+
--scale-rule-type cpu \
322+
--scale-rule-metadata type=Utilization value=<UTILIZATION>
323+
```
324+
325+
# [PowerShell](#tab/powershell)
326+
327+
```powershell
328+
az containerapp update `
329+
--name my-container-app `
330+
--resource-group my-container-apps `
331+
--min-replicas 1 `
332+
--max-replicas 10 `
333+
--scale-rule-name my-cpu-scale-rule `
334+
--scale-rule-type cpu `
335+
--scale-rule-metadata type=Utilization value=<UTILIZATION>
336+
```
337+
338+
---
339+
340+
### Memory scaling
341+
342+
Memory scaling allows your app to scale in or out depending on how much memory is being used. Memory scaling doesn't allow your container app to scale to 0. For more information about this trigger, see [KEDA memory scale trigger](https://keda.sh/docs/scalers/memory/).
343+
344+
Add a memory scale rule to your container app by running the `az containerapp update` command. Replace the `<PLACEHOLDERS>` with your values. The memory utilization value is the percentage of memory utilization at which you want to scale your app.
345+
346+
# [Bash](#tab/bash)
347+
348+
```azurecli
349+
az containerapp update \
350+
--name my-container-app \
351+
--resource-group my-container-apps \
352+
--min-replicas 1 \
353+
--max-replicas 10 \
354+
--scale-rule-name my-memory-scale-rule \
355+
--scale-rule-type memory \
356+
--scale-rule-metadata type=Utilization value=<UTILIZATION>
357+
```
358+
359+
# [PowerShell](#tab/powershell)
360+
361+
```powershell
362+
az containerapp update `
363+
--name my-container-app `
364+
--resource-group my-container-apps `
365+
--min-replicas 1 `
366+
--max-replicas 10 `
367+
--scale-rule-name my-memory-scale-rule `
368+
--scale-rule-type memory `
369+
--scale-rule-metadata type=Utilization value=<UTILIZATION>
370+
```
371+
372+
---
373+
374+
## Multiple scale rules
375+
376+
To add multiple scale rules to your container app using the Azure CLI, you must use YAML.
377+
378+
1. Export your container app configuration to YAML with the `az containerapp show` command.
379+
380+
# [Bash](#tab/bash)
381+
382+
```azurecli
383+
az containerapp show \
384+
--name my-container-app \
385+
--resource-group my-container-apps \
386+
--output yaml > app.yaml
387+
```
388+
389+
# [PowerShell](#tab/powershell)
390+
391+
```powershell
392+
az containerapp show `
393+
--name my-container-app `
394+
--resource-group my-container-apps `
395+
--output yaml > app.yaml
396+
```
397+
398+
---
399+
400+
1. In the `properties` > `template` > `scale` > `rules` section of `app.yaml`, add the following. Replace the `<PLACEHOLDERS>` with your values.
401+
402+
```yaml
403+
...
404+
properties:
405+
...
406+
template:
407+
...
408+
scale:
409+
...
410+
rules:
411+
- name: cpu-scaling-rule
412+
custom:
413+
type: cpu
414+
metadata:
415+
type: "Utilization"
416+
value: "<CPU_UTILIZATION>"
417+
- name: memory-scaling-rule
418+
custom:
419+
type: memory
420+
metadata:
421+
type: "Utilization"
422+
value: "<MEMORY_UTILIZATION>"
423+
...
424+
```
425+
426+
1. Import your container app configuration from `app.yaml` with the `az containerapp update` command.
427+
428+
# [Bash](#tab/bash)
429+
430+
```azurecli
431+
az containerapp update \
432+
--name my-container-app \
433+
--resource-group my-container-apps \
434+
--yaml app.yaml
435+
```
436+
437+
# [PowerShell](#tab/powershell)
438+
439+
```powershell
440+
az containerapp update `
441+
--name my-container-app `
442+
--resource-group my-container-apps `
443+
--yaml app.yaml
444+
```
445+
446+
---
447+
294448
## Clean up resources
295449
296450
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.

0 commit comments

Comments
 (0)