All Products
Search
Document Center

Container Compute Service:Cron-based container scaling (CronHPA)

Last Updated:Mar 26, 2026

CronHPA (Cron Horizontal Pod Autoscaler) is a feature of Container Compute Service (ACS) that scales your workloads on a schedule—like crontab, but for Kubernetes. This topic describes how to set up CronHPA in an ACS cluster and how to run CronHPA alongside HPA without conflicts.

Prerequisites

Before you begin, ensure that you have:

How CronHPA works

CronHPA is powered by the ack-kubernetes-cronhpa-controller component. It triggers scaling at specific points in time—not across a time window. Each scheduled job fires once at its configured time and sets the replica count to targetSize. CronHPA works with any Kubernetes object that exposes the scale subresource, including Deployments and StatefulSets.

A CronHPA resource looks like this:

apiVersion: autoscaling.alibabacloud.com/v1beta1
kind: CronHorizontalPodAutoscaler
metadata:
  labels:
    controller-tools.k8s.io: "1.0"
  name: cronhpa-sample
  namespace: default
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: nginx-deployment-basic
  excludeDates:
  # Exclude November 15th
  - "* * * 15 11 *"
  # Exclude every Friday
  - "* * * * * 5"
  jobs:
  - name: "scale-down"
    schedule: "30 */1 * * * *"
    targetSize: 1
  - name: "scale-up"
    schedule: "0 */1 * * * *"
    targetSize: 3
    runOnce: false

Key fields:

Field Description
scaleTargetRef The object to scale. CronHPA supports any object that exposes the scale subresource.
excludeDates Dates on which all jobs are skipped. The minimum granularity is one day. The format is "* * * <Day of month> <Month> <Day of week>".
jobs[].name The job name. Must be unique within the CronHPA object.
jobs[].schedule A 6-field cron expression (see Schedule format).
jobs[].targetSize The number of pods to scale to at the scheduled time.
jobs[].runOnce If true, the job runs once and then exits.

Schedule format

CronHPA uses a 6-field cron expression that includes seconds:

<Seconds> <Minutes> <Hours> <Day of month> <Month> <Day of week>
Field Mandatory Allowed values Allowed special characters
Seconds Yes 0–59 * / , -
Minutes Yes 0–59 * / , -
Hours Yes 0–23 * / , -
Day of month Yes 1–31 * / , - ?
Month Yes 1–12 or JAN–DEC * / , -
Day of week Yes 0–6 or SUN–SAT * / , - ?

Special character reference:

Character Meaning Example
* Matches all values in the field * in the Month field means every month
/ Specifies increments */15 in Minutes means every 15 minutes
- Specifies a range 9-17 in Hours means 9 AM through 5 PM
, Specifies a list 1,3,5 in Day of week means Monday, Wednesday, Friday
? No specific value (Day of month or Day of week only) Use ? to leave one field blank when the other is set

For predefined schedule aliases and extended expression rules, see the go-cron library and predefined-schedules.

Install the CronHPA component

  1. Log on to the ACS console. In the left navigation pane, click Clusters.

  2. On the Clusters page, click the name of your cluster. In the left navigation pane, click Add-ons.

  3. On the Add-ons page, click the Application Management tab. Find ack-kubernetes-cronhpa-controller and click Install. In the dialog box, click OK.

To uninstall CronHPA, see Manage components.

Create a CronHPA scheduled task

Before creating a CronHPA task, ensure that the CronHPA component is running correctly in the cluster and that the application has only one HPA object. For more information about the compatibility policy between CronHPA and HPA, see Use CronHPA with HPA.

Option 1: During application creation

When creating a new application, go to the Advanced Configuration page. In the Scaling Configuration section, select Enable next to Cron-based Scaling.

For instructions on creating an application, see Create a stateless workload (Deployment) or Create a stateful workload (StatefulSet).

image.png

If the CronHPA component is not installed, a Click to install message appears. Install the component, then configure the following parameters.

Parameter Description
Scheduled task name A unique name for the task.
Target replicas The number of replicas to scale to at the scheduled time.
Scheduling cycle The schedule for the task.

Option 2: For an existing application

  1. Log on to the ACS console. In the left navigation pane, click Clusters.

  2. On the Clusters page, click the name of your cluster. In the left navigation pane, choose Workloads > Deployments.

  3. On the Stateless page, click Details in the Actions column for your application.

  4. Click the Container Scaling tab.

    • If the CronHPA component is not installed, click Click to install, then proceed.

    • If the component is already installed, proceed to the next step.

  5. Click Create next to Cron-based Scaling (CronHPA). In the Create dialog box, configure the following parameters.

    Parameter Description
    Task name A unique name for the task.
    Target replicas The number of replicas to scale to at the scheduled time.
    Scheduling cycle The schedule for the task.

    create

Add or modify a scheduled task

  1. Follow the steps in Option 2: For an existing application to reach the Container Scaling tab.

  2. In the Cron-based Scaling (CronHPA) section, find the task and click Add or Edit Task in the Actions column.

  3. In the Edit dialog box, click Add Task to add a new task, or click an existing task to modify it. Click OK to save.

    To delete a task, click the delete icon in the upper-right corner of the task card in the Edit dialog box, then click OK. delete

    modify

Use CronHPA with HPA

CronHPA and HPA both act on workloads, and running both on the same workload without coordination causes conflicts—the later operation overwrites the earlier one.

To avoid this, set CronHPA's scaleTargetRef to the HPA object instead of the workload directly. CronHPA then reads the HPA's state before acting, and adjusts the HPA's minReplicas or maxReplicas rather than writing to the workload directly.

image

CronHPA-compatible templates

CronHPA

CronHPA (targeting the HPA object):

apiVersion: autoscaling.alibabacloud.com/v1beta1
kind: CronHorizontalPodAutoscaler
metadata:
  labels:
    controller-tools.k8s.io: "1.0"
  name: cronhpa-sample
spec:
  scaleTargetRef:
    apiVersion: autoscaling/v1
    kind: HorizontalPodAutoscaler
    name: nginx-deployment-basic-hpa
  jobs:
  - name: "scale-down"
    schedule: "30 */1 * * * *"
    targetSize: 1
    runOnce: false
  - name: "scale-up"
    schedule: "0 */1 * * * *"
    targetSize: 3
    runOnce: false

HPA

HPA:

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: nginx-deployment-basic-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: nginx-deployment-basic
  minReplicas: 4
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 50

How CronHPA adjusts the HPA

CronHPA reads spec.minReplicas, spec.maxReplicas, and status.desiredReplicas from the HPA, then applies the following rules:

HPA (min/max) CronHPA target Current replicas Result Rule
1/10 5 5 HPA: 1/10, Deployment: 5 Target equals current — no change.
1/10 4 5 HPA: 1/10, Deployment: 5 Target is lower than current — maintain current replica count.
1/10 6 5 HPA: 6/10, Deployment: 6 Target is higher than current — scale up and raise minReplicas to match.
5/10 4 5 HPA: 4/10, Deployment: 5 Target is lower than minReplicas — lower minReplicas, but keep current replica count.
5/10 11 5 HPA: 11/11, Deployment: 11 Target exceeds maxReplicas — set both minReplicas and maxReplicas to target.

What's next