Updated on 2026-08-26 GMT+08:00

Creating a Scheduled CronHPA Policy

There are predictable and unpredictable traffic peaks for some services. For such services, CCE CronHPA allows you to scale resources in fixed periods. It can work with HPA policies to periodically adjust the HPA scaling scope, implementing workload scaling.

CronHPA can periodically adjust the maximum and minimum numbers of pods in the HPA policy or directly adjust the number of pods of a Deployment.

Prerequisites

CCE Advanced HPA of v1.2.13 or later has been installed in the cluster.

Using CronHPA to Adjust the HPA Scaling Scope

CronHPA can periodically scale out/in pods in HPA policies to satisfy complex services.

HPA and CronHPA associate scaling objects using the scaleTargetRef field. If a Deployment is the scaling object for both CronHPA and HPA, the two scaling policies are independent of each other. The operation performed later overwrites the operation performed earlier. As a result, the scaling effect does not meet the expectation.

When CronHPA and HPA are used together, CronHPA rules take effect based on the HPA policy. CronHPA uses HPA to perform operations on the Deployment. Understanding the following parameters can help you better understand the working rules of the CronHPA.

  • targetReplicas: number of pods set for CronHPA. When CronHPA takes effect, this parameter adjusts the maximum or minimum number of pods in HPA policies to adjust the number of Deployment pods.
  • minReplicas: minimum number of Deployment pods.
  • maxReplicas: maximum number of Deployment pods.
  • replicas: number of pods in a Deployment before the CronHPA policy takes effect.

When a CronHPA rule is triggered, the maximum or minimum number of pods is adjusted by comparing the targetReplicas value with the actual pod count, while also considering the HPA policy's minimum or maximum pod limits.

Figure 1 CronHPA scaling scenarios

Figure 1 shows possible scaling scenarios. The following examples detail how CronHPA modifies the number of pods in HPAs.

Table 1 CronHPA scaling parameters

Scenario

Scenario Description

Scaling Condition

Result

Operation Description

Target CronHPA Pods

(targetReplicas)

Deployment Pods

(replicas)

Upper and Lower Limits of HPA Pods

(minReplicas/maxReplicas)

1

targetReplicas < minReplicas ≤ replicas ≤ maxReplicas

4

5

5/10

HPA: 4/10

Deployment: 5

When the value of targetReplicas is smaller than that of minReplicas:

  • Change the value of minReplicas.
  • The value of replicas requires no change.

2

targetReplicas = minReplicas ≤ replicas ≤ maxReplicas

5

6

5/10

HPA: 5/10

Deployment: 6

When the value of targetReplicas is equal to that of minReplicas:

  • The value of minReplicas requires no change.
  • The value of replicas requires no change.

3

minReplicas < targetReplicas < replicas ≤ maxReplicas

4

5

1/10

HPA: 4/10

Deployment: 5

When the value of targetReplicas is greater than that of minReplicas and smaller than that of replicas:

  • Change the value of minReplicas.
  • The value of replicas requires no change.

4

minReplicas < targetReplicas = replicas < maxReplicas

5

5

1/10

HPA: 5/10

Deployment: 5

When the value of targetReplicas is greater than that of minReplicas and equal to that of replicas:

  • Change the value of minReplicas.
  • The value of replicas requires no change.

5

minReplicas ≤ replicas < targetReplicas < maxReplicas

6

5

1/10

HPA: 6/10

Deployment: 6

When the value of targetReplicas is greater than that of replicas and less than that of maxReplicas:

  • Change the value of minReplicas.
  • Change the value of replicas.

6

minReplicas ≤ replicas < targetReplicas = maxReplicas

10

5

1/10

HPA: 10/10

Deployment: 10

When the value of targetReplicas is greater than that of replicas and equal to that of maxReplicas:

  • Change the value of minReplicas.
  • Change the value of replicas.

7

minReplicas ≤ replicas ≤ maxReplicas < targetReplicas

11

5

5/10

HPA: 11/11

Deployment: 11

When the value of targetReplicas is greater than that of maxReplicas:

  • Change the value of minReplicas.
  • Change the value of maxReplicas.
  • Change the value of replicas.

Creating a Policy Using the Console

  1. Log in to the CCE console and click the cluster name to access the cluster console.
  2. Choose Workloads in the navigation pane. Locate the target workload and choose More > Auto Scaling in the Operation column.

    Figure 2 Scaling a workload

  3. Set Policy Type to HPA+CronHPA and enable HPA and CronHPA policies.

    CronHPA periodically adjusts the maximum and minimum pod counts of the HPA policy.

  4. Configure the HPA policy. For details, see Creating an HPA Policy.

    Figure 3 Enabling the HPA policy
    Table 2 HPA policy

    Parameter

    Description

    Pod Range

    Minimum and maximum numbers of pods.

    When a policy is triggered, the workload pods are scaled within this range.

    NOTICE:

    In CCE Turbo clusters, if you use a dedicated load balancer for your workload, the number of pods cannot exceed the backend server group quota of the load balancer, which is 500 by default. If you exceed this limit, you will not be able to add any more pods to the load balancer backend.

    Cooldown Period

    Interval between a scale-in and a scale-out. The unit is minute. The interval cannot be shorter than 1 minute.

    This parameter is supported only in clusters v1.15 to v1.23.

    This parameter indicates the interval between consecutive scaling operations. The cooldown period ensures that a scaling operation is initiated only when the previous one is completed and the system is running stably.

    Scaling Behavior

    This parameter is supported only in clusters v1.25 or later.

    • Default: scales workloads using the Kubernetes default behavior. For details, see Default Behavior.
    • Custom: scales workloads using custom policies such as stabilization window, steps, and priorities. Unspecified parameters use the values recommended by Kubernetes.
      • Disable scale-out/scale-in: Select whether to disable scale-out or scale-in.
      • Stabilization Window: a period during which CCE continuously checks whether the metrics used for scaling keep fluctuating. CCE triggers scaling if the desired state is not maintained for the entire window. This window restricts the unwanted flapping of pod count due to metric changes.
      • Step: specifies the scaling step. You can set the number or percentage of pods to be scaled in or out within a specified period. If there are multiple policies, you can select the policy that maximizes or minimizes the number of pods.

    System Policy

    When calculating the number of pods to add or remove, HPA determines the target number of pods based on the current metric value, desired value, and the current number of pods. The current number of pods is the maximum number of pods in the last 5 minutes. The formula is as follows:

    Desired number of pods = Rounded up value of [Current number of pods × (Current metric value/Desired value)]

    • Metric: You can select CPU usage or Memory usage.

      Usage = Average resource usage of all pods in a workload/Requested resources

    • Desired Value: Enter the desired average resource usage.
    • Tolerance Range: Scaling is not triggered when the metric value is within the tolerance range. The desired value must be within the tolerance range.

    Custom Policy (supported only in clusters v1.15 or later)

    NOTE:

    Before creating a custom policy, install an add-on that supports custom metric collection (for example, Prometheus) in the cluster. Ensure that the add-on can collect and report the custom metrics of the workloads.

    For details, see Monitoring Custom Metrics Using Cloud Native Cluster Monitoring.

    • Metric Name: name of the custom metric. You can select a name based on suggested values.
    • Metric Source: Select an object type from the drop-down list. You can select Pod.
    • Desired Value: the average metric value of all pods. Number of pods to be scaled (rounded up) = (Current metric value/Desired value) × Current number of pods
      NOTE:

      When calculating the number of pods to be added or reduced, the HPA policy uses the maximum number of pods in the last 5 minutes.

    • Tolerance Range: Scaling is not triggered when the metric value is within the tolerance range. The desired value must be within the tolerance range.

  5. Click in the CronHPA policy rule. In the dialog box displayed, configure the scaling policy parameters.

    Figure 4 Enabling the CronHPA policy

    Table 3 CronHPA policy parameters

    Parameter

    Description

    Target Instances

    When triggered, CCE adjusts the HPA policy's pod count based on service requirements. For details, see Table 1.

    Triggered At

    Select a specific time to trigger daily, weekly, monthly, or yearly.

    NOTE:

    This reflects the local time of the node location.

    Enable

    Enable or disable the policy rule.

  6. After configuring the parameters, click OK. Then, the added policy rule is displayed in the rule list. Repeat these steps to add up to 10 policy rules. Each rule must have a unique trigger time.
  7. Click Create.

Creating a Policy Using kubectl

When CronHPA is used with HPA, the scaleTargetRef field in CronHPA must reference the HPA policy, and the scaleTargetRef field in the HPA policy must reference the Deployment. This allows CronHPA to adjust the HPA policy's min/max pod counts at scheduled times, making scheduled scaling compatible with auto scaling.

  1. Create an HPA policy for the Deployment.

    apiVersion: autoscaling/v1
    kind: HorizontalPodAutoscaler
    metadata:
      name: hpa-test
      namespace: default
    spec:
      maxReplicas: 10               # Maximum number of pods
      minReplicas: 5               # Minimum number of pods
      scaleTargetRef:              # Associate with a Deployment.
        apiVersion: apps/v1
        kind: Deployment
        name: nginx
      targetCPUUtilizationPercentage: 50

  2. Create a CronHPA policy and associate it with the HPA policy created in 1.

    apiVersion: autoscaling.cce.io/v2alpha1
    kind: CronHorizontalPodAutoscaler
    metadata:
      name: ccetest
      namespace: default
    spec:
       scaleTargetRef:                  # Associate with an HPA policy.
          apiVersion: autoscaling/v1
          kind: HorizontalPodAutoscaler
          name: hpa-test
       rules:
       - ruleName: "scale-down"    
         schedule: "15 * * * *"         # Cron expression for trigger time. For details, see Cron. Examples: 0 * * * * or @hourly.
         targetReplicas: 1              # Number of target pods
         disable: false
       - ruleName: "scale-up"
         schedule: "13 * * * *"
         targetReplicas: 11
         disable: false
    Table 4 Key CronHPA fields

    Field

    Description

    apiVersion

    API version. Fixed value: autoscaling.cce.io/v2alpha1.

    kind

    API type. Fixed value: CronHorizontalPodAutoscaler.

    metadata.name

    Name of the CronHPA policy.

    metadata.namespace

    Namespace to which the CronHPA policy belongs.

    spec.scaleTargetRef

    Scaling target of CronHPA. Configurable fields:

    • apiVersion: API version of the scaling target.
    • kind: API type of the scaling target.
    • name: name of the scaling target.

    CronHPA supports HPA policies or Deployments. For details, see Using CronHPA to Adjust the HPA Scaling Scope or Using CronHPA to Directly Adjust the Number of Deployment Pods.

    spec.rules

    CronHPA policy rules. Multiple rules can be configured. Fields per rule:

    • ruleName: CronHPA rule name, which must be unique.
    • schedule: specifies when and how often a task runs, using standard Cron expression syntax (for example, 0 * * * * or @hourly). For details, see Cron.
      NOTE:

      This reflects the local time of the node location.

    • targetReplicas: target pod count for scaling.
    • disable: The value can be true or false. false enables the rule, and true disables it.

Using CronHPA to Directly Adjust the Number of Deployment Pods

CronHPA adjusts associated Deployments separately to periodically adjust the number of Deployment pods. The method is as follows:

Adjustment Using the Console

  1. Log in to the CCE console and click the cluster name to access the cluster console.
  2. Choose Workloads in the navigation pane. Locate the target workload and choose More > Auto Scaling in the Operation column.

    Figure 5 Scaling a workload

  3. Set Policy Type to HPA+CronHPA, disable HPA, and enable CronHPA.

    CronHPA periodically adjusts the workload's pod count directly.

  4. Click in the CronHPA policy rule. In the dialog box displayed, configure the scaling policy parameters.

    Figure 6 Using CronHPA to adjust workload pod count

    Table 5 CronHPA policy parameters

    Parameter

    Description

    Target Instances

    When a policy is triggered, the workload pod count is adjusted to this value.

    Triggered At

    Select a specific time to trigger daily, weekly, monthly, or yearly.

    NOTE:

    This reflects the local time of the node location.

    Enable

    Enable or disable the policy rule.

  5. After configuring the parameters, click OK. Then, the added policy rule is displayed in the rule list. Repeat these steps to add multiple policy rules. Each rule must have a unique trigger time.
  6. Click Create.

Adjustment Using kubectl

apiVersion: autoscaling.cce.io/v2alpha1
kind: CronHorizontalPodAutoscaler
metadata:
  name: ccetest
  namespace: default
spec:
   scaleTargetRef:             # Associate with a Deployment.
      apiVersion: apps/v1
      kind: Deployment
      name: nginx
   rules:
   - ruleName: "scale-down"
     schedule: "08 * * * *"    # Cron expression for trigger time. For details, see Cron. Examples: 0 * * * * or @hourly.
     targetReplicas: 1
     disable: false
   - ruleName: "scale-up"
     schedule: "05 * * * *"
     targetReplicas: 3
     disable: false

Helpful Links