Azure Container Apps leverages cron-type KEDA scaling rules to schedule autoscaling actions at specific times. This feature is ideal for applications with predictable workload fluctuations (e.g., batch jobs, reporting systems) that require scaling based on time-of-day or day-of-week patterns. This guide walks you through configuring and optimizing time-based scaling.
Prerequisites
- An active Azure subscription with access to Azure Container Apps.
- Basic understanding of KEDA (Kubernetes Event-driven Autoscaling) concepts.
- A deployed application in Azure Container Apps (see Quickstart Guide).
How Time-Based Scaling Works
Time-based scaling in Azure Container Apps is achieved by defining cron-type scale rules(https://keda.sh/docs/2.15/scalers/cron/). It uses cron expressions to define start and end times for scaling actions. During the active window, the app scales to a specified desiredReplicas count. Outside this window, scaling defaults to minReplicas/maxReplicas settings.
Configuration Example: Weekday vs. Weekend Scaling
Scale to 1 replica on weekdays (Mon–Fri) and 0 replicas on weekends (Sat–Sun) to optimize costs.
triggers:
- type: cron
metadata:
timezone: Asia/Shanghai # Uses TZ database names (e.g., "America/New_York")
start: "0 8 * * 1" # 08:00 AM every Monday (1 = Monday in cron syntax)
end: "0 0 * * 6" # 00:00 (midnight) every Saturday (6 = Saturday)
desiredReplicas: "1" # Maintain 1 replica during active period
Key Parameters Explained
Parameter | Description |
---|---|
type | Set to cron for time-based scaling. |
timezone | Timezone for cron schedules (e.g., Europe/London). Full list. |
start / end | Cron expressions defining the active window. |
desiredReplicas | Replica count during the start–end window. |
Cron Syntax Notes:
- Format: [minute] [hour] [day] [month] [day-of-week] (e.g., 0 8 * * 1 = 8:00 AM every Monday).
- Days: 0 = Sunday, 1 = Monday, ..., 6 = Saturday.
Step-by-Step Configuration
Azure Portal:
- Navigate to your Container App in the Azure portal.
- Under Application, select Scale.
- Add a new scaling rule:
- Rule Type: Select Custom → cron.
- Metadata: Add timezone, start, end, and desiredReplicas (use the example above).
- Save changes.
Azure CLI:
By running below CLI command, we can create a add a new time-based scale rule.
az containerapp update \
--name <APP_NAME> \
--resource-group <RESOURCE_GROUP> \
--environment <ENVIRONMENT_NAME> \
--min-replicas 0 \
--max-replicas 1 \
--scale-rule-name "weekdayscale" \
--scale-rule-type "cron" \
--scale-rule-metadata "timezone=Asia/Shanghai" "start=0 8 * * 1" "end=0 0 * * 6" "desiredReplicas=1"
ARM Template:
This snippet is an excerpt of an ARM template to show you where each section fits in context of the overall template.
{
"scale": {
"minReplicas": 0,
"maxReplicas": 1,
"rules": [
{
"name": "weekdayscale",
"type": "cron",
"metadata": {
"timezone": "Asia/Shanghai",
"start": "0 8 * * 1",
"end": "0 0 * * 6",
"desiredReplicas": "1"
}
}
]
}
}
Benefits of time-based scaling
- Cost efficiency: Scale down during off-peak hours to minimize resource costs.
- Resource optimization: Automatically adjust resources to align with predictable workload patterns.
- Simplicity: Straightforward configuration and management of scaling rules based on time intervals.
Conclusion
Time-based scaling in Azure Container Apps simplifies resource management for time-sensitive workloads. By combining cron schedules with KEDA, you can automate scaling actions to match demand while minimizing costs. For advanced scenarios, explore KEDA cron scaler documentation and Azure Container Apps scaling guide.
Updated Apr 01, 2025
Version 1.0wanjing
Microsoft
Joined June 21, 2021
Apps on Azure Blog
Follow this blog board to get notified when there's new activity