If your application's resource usage follows a predictable periodic pattern, use Cron Horizontal Pod Autoscaler (CronHPA) to scale pods at specific times. Such scheduling is ideal for scenarios with recurring traffic peaks or scheduled background jobs.
Before you begin
ACK provides multiple scaling solutions at both the scheduling (workload) and resource (node) layers. Before you proceed, read Auto scaling to determine the best strategy for your specific use case.
How CronHPA works
CronHPA is powered by kubernetes-cronhpa-controller, a time-based pod scaling controller. It uses crontab-like syntax to dynamically adjust resources, making it ideal for workloads with periodic traffic fluctuations. CronHPA works with any Kubernetes object that supports the Scale subresource, such as Deployments and StatefulSets.
Step 1: Install the CronHPA add-on
Log on to the Container Service Management Console . In the navigation pane on the left, click Clusters.
On the Clusters page, click the name of your cluster. In the navigation pane on the left, click Add-ons.
Click the Manage Applications tab, find ack-kubernetes-cronhpa-controller, and install the add-on as prompted.
Step 2: Create CronHPA jobs
Before creating CronHPA jobs, ensure the CronHPA is running and the target workload has only one HPA object associated with it. The following example uses a Deployment. The steps are similar for other workload types.
Option 1: Create CronHPA jobs during workload creation
Log on to the Container Service Management Console . In the navigation pane on the left, click Clusters.
On the Clusters page, click the name of your cluster. In the navigation pane on the left, click .
On the Deployments page, click Create from Image.
On the Create page, configure the settings to create a CronHPA-enabled Deployment.
For detailed configuration instructions, see Create a stateless workload (Deployment).
Basic Information: Set the application name and replica count.
Container: Specify the container image and resource requests for CPU and memory.
Advanced:
In the Scaling section, enable CronHPA. Install the add-on if prompted, then configure the scaling parameters:
Job Name: A unique name for the CronHPA job.
Desired Number of Replicas: The number of pod replicas to scale to at the scheduled time.
Scaling Schedule: The cron expression that defines the scaling schedule. For more information, see kubernetes-cronhpa-controller.
Option 2: Create CronHPA jobs for an existing workload
Workload page
Log on to the Container Service Management Console . In the navigation pane on the left, click Clusters.
On the Clusters page, click the name of your cluster. In the navigation pane on the left, click .
Click the target workload, then click the Pod Scaling tab. In the CronHPA section, click Create.

Parameter
Description
Job Name
A unique name for the CronHPA job.
Desired Number of Replicas
The number of pod replicas to scale to at the scheduled time.
Scaling Schedule
The cron expression that defines the scaling schedule. For more information, see kubernetes-cronhpa-controller.
Workload scaling page
Log on to the Container Service Management Console . In the navigation pane on the left, click Clusters.
On the Clusters page, click the name of your cluster. In the navigation pane on the left, click Workload Scaling.
In the upper-right corner, click Create Auto Scaling.
Click the HPA and CronHPA tab, select the target workload, then select CronHPA in the Configure Auto Scaling Policy section.
You can add multiple CronHPA jobs. Configure the following parameters then click OK.
CronHPA Task Name: A name for the CronHPA object.
Job Name: A name for the individual CronHPA job.
Desired Number of Replicas: The desired number of pod replicas at the scheduled time.
Scaling Schedule: The cron expression that defines the scaling schedule. For more information, see kubernetes-cronhpa-controller.
kubectl
Save the following manifest to a file named
cronhpa.yaml:apiVersion: autoscaling.alibabacloud.com/v1beta1 kind: CronHorizontalPodAutoscaler metadata: name: cronhpa-sample namespace: default spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: nginx-deployment-basic excludeDates: - "* * * 15 11 *" - "* * * * * 5" jobs: - name: "scale-down" schedule: "30 */1 * * * *" targetSize: 1 runOnce: false - name: "scale-up" schedule: "0 */1 * * * *" targetSize: 3 runOnce: trueRun the following command to create the CronHPA:
kubectl apply -f cronhpa.yamlExpected output:
cronhorizontalpodautoscaler.autoscaling.alibabacloud.com/cronhpa-sample created
What's next
View, add, or modify CronHPA jobs
After creating a CronHPA, view job status, add new jobs, or modify existing configurations using either of the following methods:
From the Workload Scaling page:
On the Clusters page, click the name of your cluster. In the navigation pane on the left, click Workload Scaling.
Click the CronHPA tab. In the Actions column, click Edit for the target CronHPA.
From the Workloads page (using Deployments as an example):
On the Clusters page, click the name of your cluster. In the navigation pane on the left, click .
Click the target Deployment, then click the Pod Scaling tab. In the CronHPA section, click Add or Modify Job in the Actions column.
Use CronHPA with HPA
Cron Horizontal Pod Autoscaler (HPA) and Horizontal Pod Autoscaler (HPA) are unaware of each other. If both CronHPA and HPA are configured for your application, CronHPA and HPA scale your application separately. In this case, the later scaling activity overwrites the earlier one. To resolve this issue, Container Service for Kubernetes (ACK) provides a solution for CronHPA to interact with HPA without conflicts. If ACK detects that both CronHPA and HPA are deployed, ACK sets HPA as the scaling object of CronHPA. CronHPA triggers HPA to scale the object scaled by HPA, such as a Deployment, at the scheduled time.
For more information, see Make CronHPA compatible with HPA.