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:

  1. Specify an IANA timezone for scheduling.
  2. Define start and end times with standard CRON expressions.
  3. Set a desiredReplicas count for the active window.

The image is a diagram illustrating "KEDA Cron" with icons representing Cron, KEDA, a database, and a time zone.

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

ScenarioScheduleBenefit
Daily Traffic Spike0 6 * * * – 0 8 * * *Pre-warm pods for morning users
Promotional Campaign0 12 * * 5 – 0 18 * * 5Extra capacity during Friday sales
Off-Hours Optimization0 20 * * * – 0 6 * * *Scale down to save costs overnight

The image outlines the concept of KEDA Cron for predetermined scaling, detailing the requirement, solution, outcome, and a real-life use case for handling traffic spikes.

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

The image is a graph showing KEDA Cron's predetermined scaling of workload instances over a 24-hour period, with increased activity between 6:00 am and 6:00 pm.

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

FieldRangeDescription
minute0–59Minute of the hour
hour0–23Hour of the day
day-of-month1–31Date
month1–12Month number
day-of-week0–6Weekday (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.

Watch Video

Watch video content

Practice Lab

Practice lab

Previous
KEDA CPU Scaling