0
0
Azurecloud~5 mins

Container Apps scaling rules in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
Scaling rules help your container apps automatically adjust the number of running instances based on demand. This keeps your app responsive during busy times and saves money when traffic is low.
When your app needs to handle more users during certain hours without manual intervention
When you want to save costs by reducing resources during low traffic periods
When you want your app to respond quickly to sudden spikes in requests
When you want to maintain performance by adding more instances as CPU or memory usage grows
When you want to scale based on custom metrics like queue length or HTTP request count
Config File - scale-rule.yaml
scale-rule.yaml
apiVersion: apps/v1
kind: ContainerApp
metadata:
  name: example-containerapp
  resourceGroup: example-rg
properties:
  configuration:
    scale:
      minReplicas: 1
      maxReplicas: 5
      rules:
      - name: http-scaling
        custom:
          type: http
          metadata:
            concurrentRequests: "50"
      - name: cpu-scaling
        custom:
          type: cpu
          metadata:
            value: "75"

This file defines scaling rules for an Azure Container App named example-containerapp.

  • minReplicas sets the minimum number of instances to 1 to keep the app always available.
  • maxReplicas limits scaling up to 5 instances to control costs.
  • rules define when to scale: one rule triggers scaling when concurrent HTTP requests exceed 50, another triggers when CPU usage goes above 75%.
Commands
This command creates a container app with scaling rules that start with 1 instance and can scale up to 5 based on HTTP request load.
Terminal
az containerapp create --name example-containerapp --resource-group example-rg --image mcr.microsoft.com/azuredocs/containerapps-helloworld --min-replicas 1 --max-replicas 5 --cpu 0.5 --memory 1.0 --scale-rule-name http-scaling --scale-rule-type http --scale-rule-concurrent-requests 50
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.App/containerApps/example-containerapp", "name": "example-containerapp", "type": "Microsoft.App/containerApps", "properties": { "provisioningState": "Succeeded", "configuration": { "scale": { "minReplicas": 1, "maxReplicas": 5, "rules": [ { "name": "http-scaling", "custom": { "type": "http", "metadata": { "concurrentRequests": "50" } } } ] } } } }
--min-replicas - Sets the minimum number of container instances
--max-replicas - Sets the maximum number of container instances
--scale-rule-concurrent-requests - Defines the threshold of concurrent HTTP requests to trigger scaling
This command checks the current configuration and status of the container app to verify scaling rules are applied.
Terminal
az containerapp show --name example-containerapp --resource-group example-rg
Expected OutputExpected
{ "name": "example-containerapp", "resourceGroup": "example-rg", "properties": { "configuration": { "scale": { "minReplicas": 1, "maxReplicas": 5, "rules": [ { "name": "http-scaling", "custom": { "type": "http", "metadata": { "concurrentRequests": "50" } } } ] } }, "provisioningState": "Succeeded" } }
This command adds a CPU-based scaling rule to the container app to scale when CPU usage exceeds 75%.
Terminal
az containerapp update --name example-containerapp --resource-group example-rg --set properties.configuration.scale.rules[1].name=cpu-scaling properties.configuration.scale.rules[1].custom.type=cpu properties.configuration.scale.rules[1].custom.metadata.value="75"
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.App/containerApps/example-containerapp", "name": "example-containerapp", "properties": { "configuration": { "scale": { "rules": [ { "name": "http-scaling", "custom": { "type": "http", "metadata": { "concurrentRequests": "50" } } }, { "name": "cpu-scaling", "custom": { "type": "cpu", "metadata": { "value": "75" } } } ] } }, "provisioningState": "Succeeded" } }
--set - Updates specific properties in the container app configuration
This command lists all container apps in the resource group to confirm the app is running and scaling rules are active.
Terminal
az containerapp list --resource-group example-rg
Expected OutputExpected
[ { "name": "example-containerapp", "resourceGroup": "example-rg", "properties": { "provisioningState": "Succeeded", "configuration": { "scale": { "minReplicas": 1, "maxReplicas": 5, "rules": [ { "name": "http-scaling", "custom": { "type": "http", "metadata": { "concurrentRequests": "50" } } }, { "name": "cpu-scaling", "custom": { "type": "cpu", "metadata": { "value": "75" } } } ] } } } } ]
Key Concept

If you remember nothing else from this pattern, remember: scaling rules automatically adjust your container app instances based on real-time demand to keep performance steady and costs low.

Common Mistakes
Setting minReplicas and maxReplicas to the same number
This disables scaling because the app cannot add or remove instances beyond that fixed number.
Set minReplicas lower than maxReplicas to allow scaling up and down.
Using very low thresholds for scaling rules like 1 concurrent request
This causes the app to scale up too often, wasting resources and increasing costs.
Choose realistic thresholds based on expected traffic to avoid unnecessary scaling.
Not verifying the scaling rules after creation
You might think scaling is configured but it could be missing or misconfigured, causing performance issues.
Always run commands like az containerapp show to confirm your scaling rules are applied.
Summary
Create a container app with min and max replicas and define scaling rules based on HTTP requests or CPU usage.
Use az containerapp show to verify the scaling configuration is applied correctly.
Update scaling rules anytime to add or adjust triggers for automatic scaling.