Bird
Raised Fist0
Azurecloud~5 mins

Container Apps scaling rules in Azure - Commands & Configuration

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
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.

Practice

(1/5)
1. What is the main purpose of scaling rules in Azure Container Apps?
easy
A. To automatically adjust the number of app instances based on demand
B. To manually restart the app when it crashes
C. To set the app's color theme
D. To limit the app's network bandwidth

Solution

  1. Step 1: Understand scaling rules function

    Scaling rules help apps change the number of running instances automatically based on usage.
  2. Step 2: Identify the correct purpose

    Among the options, only automatic adjustment of instances matches scaling rules' purpose.
  3. Final Answer:

    To automatically adjust the number of app instances based on demand -> Option A
  4. Quick Check:

    Scaling rules = auto adjust instances [OK]
Hint: Scaling rules control instance count automatically [OK]
Common Mistakes:
  • Confusing scaling with manual restarts
  • Thinking scaling changes app appearance
  • Assuming scaling controls network limits
2. Which of the following is the correct JSON snippet to set a CPU-based scaling rule in Azure Container Apps?
easy
A. {"name":"cpu","type":"memory","metadata":{"value":"75"}}
B. {"name":"memory","type":"cpu","metadata":{"value":"75"}}
C. {"name":"cpu","type":"cpu","metadata":{"value":"75"}}
D. {"name":"requests","type":"http","metadata":{"value":"75"}}

Solution

  1. Step 1: Identify correct metric type for CPU scaling

    The metric type must be "cpu" to scale based on CPU usage.
  2. Step 2: Check JSON structure and metadata

    {"name":"cpu","type":"cpu","metadata":{"value":"75"}} correctly uses "cpu" type and sets a value of 75 for CPU percentage.
  3. Final Answer:

    {"name":"cpu","type":"cpu","metadata":{"value":"75"}} -> Option C
  4. Quick Check:

    CPU scaling JSON uses type "cpu" [OK]
Hint: CPU scaling uses type "cpu" in JSON metadata [OK]
Common Mistakes:
  • Using wrong metric type like memory for CPU scaling
  • Mixing HTTP request type with CPU
  • Incorrect JSON key names
3. Given this scaling rule snippet:
{"name":"http","type":"http","metadata":{"concurrentRequests":"50"}}

What happens when the app receives 60 concurrent HTTP requests?
medium
A. The app scales out to add more instances
B. The app scales in to reduce instances
C. The app ignores the requests and crashes
D. The app blocks all requests above 50

Solution

  1. Step 1: Understand the scaling trigger

    The rule triggers scaling when concurrent HTTP requests exceed 50.
  2. Step 2: Analyze the scenario with 60 requests

    Since 60 > 50, the app will scale out by adding instances to handle load.
  3. Final Answer:

    The app scales out to add more instances -> Option A
  4. Quick Check:

    Requests > threshold triggers scale out [OK]
Hint: Requests above limit cause scale out [OK]
Common Mistakes:
  • Thinking app scales in when load increases
  • Assuming app crashes on overload
  • Believing app blocks extra requests
4. You wrote this scaling rule JSON:
{"name":"cpu","type":"cpu","metadata":{"value":"abc"}}

What is the problem with this configuration?
medium
A. The JSON keys are misspelled
B. The type "cpu" is incorrect for CPU scaling
C. Scaling rules cannot use CPU metrics
D. The value for CPU threshold is not a valid number

Solution

  1. Step 1: Check the value field in metadata

    The value should be a number representing CPU percentage, but "abc" is not numeric.
  2. Step 2: Confirm type correctness

    The type "cpu" is correct, and keys are spelled properly.
  3. Final Answer:

    The value for CPU threshold is not a valid number -> Option D
  4. Quick Check:

    CPU value must be numeric [OK]
Hint: CPU threshold value must be a number [OK]
Common Mistakes:
  • Using non-numeric strings for threshold values
  • Changing correct type names
  • Misspelling JSON keys
5. You want to configure an Azure Container App to scale between 2 and 10 instances based on CPU usage exceeding 70%. Which JSON snippet correctly sets the min and max replicas along with the CPU scaling rule?
hard
A. {"minReplicas": 10, "maxReplicas": 2, "rules": [{"name": "cpuRule", "type": "cpu", "metadata": {"value": "70"}}]}
B. {"minReplicas": 2, "maxReplicas": 10, "rules": [{"name": "cpuRule", "type": "cpu", "metadata": {"value": "70"}}]}
C. {"minReplicas": 2, "maxReplicas": 10, "rules": [{"name": "cpuRule", "type": "memory", "metadata": {"value": "70"}}]}
D. {"minReplicas": 2, "maxReplicas": 10, "rules": [{"name": "cpuRule", "type": "http", "metadata": {"concurrentRequests": "70"}}]}

Solution

  1. Step 1: Verify min and max replicas values

    Min replicas should be 2 and max replicas 10 as per requirement; {"minReplicas": 2, "maxReplicas": 10, "rules": [{"name": "cpuRule", "type": "cpu", "metadata": {"value": "70"}}]} matches this correctly.
  2. Step 2: Check scaling rule type and metadata

    The rule must be type "cpu" with value "70" for CPU usage threshold; {"minReplicas": 2, "maxReplicas": 10, "rules": [{"name": "cpuRule", "type": "cpu", "metadata": {"value": "70"}}]} correctly sets this.
  3. Final Answer:

    {"minReplicas": 2, "maxReplicas": 10, "rules": [{"name": "cpuRule", "type": "cpu", "metadata": {"value": "70"}}]} -> Option B
  4. Quick Check:

    Min/max replicas correct and CPU rule set [OK]
Hint: Min < max replicas and type "cpu" for CPU scaling [OK]
Common Mistakes:
  • Swapping min and max replica values
  • Using wrong metric type like memory or http
  • Incorrect metadata keys for CPU scaling