Kubernetes Autoscaling
Kubernetes Event Driven Autoscaling KEDA
KEDA CRON Scaling
Schedule Kubernetes Horizontal Pod Autoscaling (HPA) using KEDA’s Cron trigger to automatically adjust replica counts at specific times. This approach helps you:
- Handle predictable traffic spikes (e.g., morning rush).
- Save resources by scaling down during idle periods.
- Automate capacity management for promotional events.
How KEDA Cron Triggers Work
A Cron trigger in KEDA allows you to:
- Specify an IANA timezone for scheduling.
- Define start and end times with standard CRON expressions.
- Set a
desiredReplicas
count for the active window.
When the clock matches your start
expression, KEDA scales the target Deployment up to desiredReplicas
. After the end
expression, it scales back down (respecting your minReplicaCount
).
Common Use Cases
Scenario | Schedule | Benefit |
---|---|---|
Daily Traffic Spike | 0 6 * * * – 0 8 * * * | Pre-warm pods for morning users |
Promotional Campaign | 0 12 * * 5 – 0 18 * * 5 | Extra capacity during Friday sales |
Off-Hours Optimization | 0 20 * * * – 0 6 * * * | Scale down to save costs overnight |
When to Use Time-Based Scaling
- Predictable Load Windows: Morning routines, lunch peaks, end-of-business-day reporting.
- Short-Lived Events: Flash sales, marketing campaigns.
- Cost Management: Turn off extra capacity when it isn’t needed.
24-Hour Scaling Graph
This graph illustrates:
- Baseline: Default replica count until 06:00.
- Scale-Up: Jump to
desiredReplicas
during the 6:00–20:00 window. - Scale-Down: Return to baseline after 20:00.
Defining the Cron Trigger in KEDA
Add a Cron trigger under spec.triggers
in your ScaledObject
manifest:
triggers:
- type: cron
metadata:
timezone: Asia/Kolkata # IANA Time Zone Database
start: "0 6 * * *" # 06:00 daily
end: "0 20 * * *" # 20:00 daily
desiredReplicas: "10" # Target replicas during active window
CRON Field Reference
Field | Range | Description |
---|---|---|
minute | 0–59 | Minute of the hour |
hour | 0–23 | Hour of the day |
day-of-month | 1–31 | Date |
month | 1–12 | Month number |
day-of-week | 0–6 | Weekday (Sun=0) |
Timezone Accuracy
Make sure to use the exact IANA timezone string (e.g., America/New_York
). An incorrect value can prevent your schedule from triggering.
Complete ScaledObject Example
Below is a full example combining the Cron trigger with a Deployment target. It scales my-deployment
up to 10 replicas between 06:00 and 20:00 Asia/Kolkata time, then scales down to zero after a 5 minute cooldown.
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: cron-scaledobject
namespace: default
spec:
scaleTargetRef:
name: my-deployment
minReplicaCount: 0
cooldownPeriod: 300 # 5 minutes before scaling down
triggers:
- type: cron
metadata:
timezone: Asia/Kolkata
start: "0 6 * * *"
end: "0 20 * * *"
desiredReplicas: "10"
With this configuration, KEDA automatically aligns your application’s capacity to match scheduled demand patterns, improving performance and cost efficiency.
Links and References
Watch Video
Watch video content
Practice Lab
Practice lab