Azure Container Apps is a fully managed environment that enables you to run microservices and containerized applications on a serverless platform, which manages automatic horizontal scaling through a set of declarative scaling rules. As a container app revision scales out, new instances of the revision are created on-demand. These instances are known as replicas.
Adding or editing scaling rules creates a new revision of your container app. A revision is an immutable snapshot of your container app.
Scaling is driven by different categories of triggers - this blog discusses HTTP and Custom triggers.
HTTP SCALING
With an HTTP scaling rule, you have control over the threshold of concurrent HTTP requests that determines how your container app revision scales.
Navigate to Container App > Scale and replicas > Scale > Edit and deploy > Scale > Add Scale rule to configure scaling rules.
HTTP traffic: These rules will scale the container app based on the number of concurrent HTTP requests to your container app.
Note – You can utilize the Request Metric to check the number of requests in the metrics, as shown above.
CUSTOM SCALING
You can create a custom Container Apps scaling rule based on any ScaledObject-based KEDA scaler.
NOTE: Metadata parameters are case-sensitive. Inaccuracies may affect functionality or cause errors, so attention to detail is crucial.
1. Configure Scale rules based on Memory Usage under Custom Rule –
The rules will scale the container app based on the amount of Memory consumption.
Custom rule type: memory Reference: Memory | KEDA
Parameter List –
type - Type of metric to use. Options are Utilization, or AverageValue.
value - Value to trigger scaling actions for:
Note – You can monitor the memory consumption in DASP to validate the activation of the auto-scaling rules.
2. Configure Scale rules based on CPU Usage under Custom Rule –
The rules will scale the container app based on the amount of CPU consumption.
Custom rule type: cpu Reference: CPU | KEDA
Parameter List –
type - Type of metric to use. Options are Utilization, or AverageValue.
value - Value to trigger scaling actions for:
Note – You can monitor the CPU consumption in DASP to validate the activation of the auto-scaling rules.
Scale rules for Azure resources, including Azure Queue Storage, Azure Service Bus, and Azure Event Hubs, now also support managed identity: You can use managed identities in your scale rules to authenticate with Azure services that support managed identities. To use a managed identity in your scale rule, use the identity
property instead of the auth
property in your scale rule. Acceptable values for the identity
property are either the Azure resource ID of a user-assigned identity, or system
to use a system-assigned identity.
For details and example, refer:
Managed identities in Azure Container Apps | Microsoft Learn
Scaling in Azure Container Apps | Microsoft Learn
ARM | CLI |
The following ARM template example shows how to use a managed identity with an Azure Queue Storage scale rule: The queue storage account uses the
|
Container Apps scale rules can use managed identity to authenticate with Azure services. The following command creates a container app with a user-assigned managed identity and uses it to authenticate for an Azure Queue scaler.
Replace placeholders with your values. |
3. Configure Scale rules based on Azure Service Bus Queues or Topics-
This rule will scale the container app replicas based on the number of messages in the Azure Service Bus Queue or Topic.
Custom rule type: azure-servicebus Reference: Azure Service Bus | KEDA
Parameter List –
connection – this is an Authentication Parameter which has the connection string for the Azure Service Bus Namespace. The following formats are supported.
messageCount- Amount of active messages in your Azure Service Bus queue or topic to scale on. Default: 5 messages
namespace- Name of the Azure Service Bus namespace that contains your queue or topic.
queueName- Name of the Azure Service Bus queue to scale on.
(or)
topicName- Name of the Azure Service Bus topic to scale on.
Note- To monitor the messages in the queue or topic, navigate to the Service Bus resource and view the metrics.
4. Configure Scale rules based on Azure Blob Storage-
This rule will scale the container app replicas based on the count of blobs in a given Azure Blob Storage container.
Custom rule type: azure-blob Reference: Azure Blob Storage | KEDA
NOTE: This requires you to setup an environment variable on the replica you are configuring the scale rule with value of the connection string of the storage account. For this, you will need to create a secret and use this secret in the environment variable.
Parameter List –
connection – this is an Authentication Parameter which has the Connection string for Azure Storage Account. The following format is supported for the connection string (to be specified at the secret/environment variable).
DefaultEndpointsProtocol=https;AccountName=<storage-account>;AccountKey=<key>;EndpointSuffix=core.windows.net
blobContainerName - Name of container in an Azure Storage account.
blobCount - Average target value to trigger scaling actions. (Default: 5, Optional)
activationBlobCount- Target value for activating the scaler. (Default: 0, Optional)
connectionFromEnv- Name of the environment variable your deployment uses to get the connection string.
accountName- Name of the storage account that the container belongs to.
Note- To monitor the blobs in the container, navigate to the container in the storage account.
SCALING BEHAVIOR
This video explains how scaling works in Container Apps with an example:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.