If your application resource utilization exhibits periodic changes and you need to scale pods based on Crontab-like schedules, you can use Cron Horizontal Pod Autoscaler (CronHPA) to achieve scheduled scaling. CronHPA is suitable for scenarios where business traffic has significant peak periods, or applications need to perform tasks at specific times.
Pre-reading tips
Prerequisites
An ACK managed cluster or ACK Serverless cluster is created. For more information, see Create an ACK Managed Cluster and Create an ACK Serverless Cluster.
A kubectl client is connected to the cluster. For more information, see Connect to Kubernetes Cluster Using kubectl.
CronHPA template and parameters
CronHPA is implemented based on kubernetes-cronhpa-controller. The kubernetes-cronhpa-controller is a time-based pod horizontal scaling controller that scales the cluster based on crontab-like schedules, such as automatically increasing the number of pods during business peak hours on weekdays and decreasing the number of pods during business off-peak hours. CronHPA can be applied to any Kubernetes object that supports scaling subresources, such as Deployment and StatefulSet.
Step 1: Install the CronHPA component
You can install the CronHPA component ack-kubernetes-cronhpa-controller to achieve scheduled scaling of application workloads.
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, find the cluster that you want to manage and click its name. In the left-side navigation pane, choose .
Click the Manage Applications tab, find ack-kubernetes-cronhpa-controller, click Install, and follow the page prompts to complete the component installation.
Step 2: Create CronHPA Task
Before creating and running CronHPA for an application, make sure that the CronHPA component in the cluster is running normally and that there is only one HPA task object for the current application. The following example shows how to enable CronHPA for a stateless application. The steps for other types of workloads are similar.
Create CronHPA jobs when creating an application
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, find the cluster that you want to manage and click its name. In the left-side pane, choose .
On the Deployments page, click Create from Image.
On the Create page, follow the page prompts to complete the basic application information configuration, container configuration, service configuration, and scheduled scaling configuration to create a Deployment that supports CronHPA.
For more information about steps and parameters, see Create a stateless application by using a Deployment. The following only introduces the main parameters.
Basic Information: Configure the basic information of the application, such as the name and the number of replicas.
Container: Configure the image, CPU, and memory resources required by the container.
Advanced:
In the Access Control section, click Create corresponding to Service to configure the service.
In the Scaling section, check Enable for CronHPA, follow the page prompts to install the component (ignore if already installed), and then configure the conditions and parameters for scheduled scaling.
Job Name: The name of the CronHPA task.
Desired Number of Replicas: When the scheduled time is reached, the number of application replicas automatically scales to this value.
Scaling Schedule: Set the scheduling period. For more information about setting the scheduling period for CronHPA jobs, see AliyunContainerService/kubernetes-cronhpa-controller.
Create CronHPA jobs for an existing application
Create on the Workloads page
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, find the cluster that you want to manage and click its name. In the left-side pane, choose .
On the Deployments page, click Details in the Actions column of the target deployment, and then click the Pod Scaling tab. In the CronHPA section, follow the page prompts to install the CronHPA component (ignore if already installed) and click Create to configure CronHPA.
Parameter
Description
Job Name
The name of the CronHPA job.
Desired Number of Replicas
When the scheduled time is reached, the number of application replicas automatically scales to this value.
Scaling Schedule
The set scheduling period. For more information about setting the scheduling period for CronHPA jobs, see AliyunContainerService/kubernetes-cronhpa-controller.
Create on the Workload Scaling page
The Workload Scaling page is available for only users in whitelists. If you want to use this page, submit a ticket.
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, find the cluster that you want to manage and click its name. In the left-side pane, choose
.In the upper right corner of the page, click Create Auto Scaling, select the target workload, and then check the CronHPA option under the Horizontal Scaling tab. Follow the page prompts to install the component (ignore if already installed) and configure the CronHPA policy.
CronHPA Name: Enter the name of CronHPA.
Job Name: Enter the name of the CronHPA job.
Desired Number of Replicas: When the scheduled time is reached, the number of application replicas automatically scales to this value.
Scaling Schedule: Set the scheduling period. For more information about setting the scheduling period for CronHPA tasks, see AliyunContainerService/kubernetes-cronhpa-controller.
Related operations
View, add, or modify CronHPA jobs
After creating CronHPA jobs, you can view the status and list of CronHPA jobs in the CronHPA list. You can add a CronHPA job or modify the existing CronHPA configuration through the following entry points.
Workload Scaling entry point
On the Clusters page, find the cluster that you want to manage and click its name. In the left-side pane, choose
.In the CronHPA section under the Horizontal Scaling tab, click Edit in the Actions column.
Workloads entry point (using a stateless application as an example, the steps for other types of workloads are similar)
On the Clusters page, find the cluster that you want to manage and click its name. In the left-side pane, choose .
In the Deployments page, click Details in the Actions column of the target deployment, and then click the Pod Scaling tab. In the CronHPA section, click Add or Edit Job in the Actions column.
Implement coordination between CronHPA and HPA
CronHPA and HPA are independent and unaware of each other. As a result, if both CronHPA and HPA are configured in the YAML file of your application, the CronHPA controller and the HPA controller scale for the application separately. 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, it sets the scaling target of CronHPA to HPA, thereby enabling scheduled scaling for the HPA scaling object, such as a Deployment.
For more information, refer to Implement Coordination Between CronHPA and HPA.
FAQ
How do I uninstall ack-kubernetes-cronhpa-controller?
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, find the cluster that you want to manage and click its name. In the left-side navigation pane, choose .
On the Helm page, check whether the ack-kubernetes-cronhpa-controller component exists.
If it exists, click Delete in the Actions column on the right side of the component.
ImportantDeleting the component via Helm will not delete the CRD and created Task resources. To completely delete CronHPA-related resources, delete them manually.
If it does not exist, go to the next step.
In the left-side navigation pane of the details page, choose .
On the Add-ons page, find the ack-kubernetes-cronhpa-controller component and click Uninstall.