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.
The add-on CCE Advanced HPA of v1.2.13 or later has been installed.
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 better understand the working rules of the CronHPA.
When the CronHPA rule takes effect, the maximum or minimum number of pods are adjusted by comparing the number of targetReplicas with the actual number of pods and combining the minimum or maximum number of pods in the HPA policy.
Figure 1 shows possible scaling scenarios. The following examples detail how CronHPA modifies the number of pods in HPAs.
Scenario |
Scenario Description |
CronHPA (targetReplicas) |
Deployment (replicas) |
HPA (minReplicas/maxReplicas) |
Result |
Operation Description |
---|---|---|---|---|---|---|
1 |
targetReplicas < minReplicas ≤ replicas ≤ maxReplicas |
4 |
5 |
5/10 |
HPA: 4/10 Deployments: 5 |
When the value of targetReplicas is smaller than that of minReplicas:
|
2 |
targetReplicas = minReplicas ≤ replicas ≤ maxReplicas |
5 |
6 |
5/10 |
HPA: 5/10 Deployments: 6 |
When the value of targetReplicas is equal to that of minReplicas:
|
3 |
minReplicas < targetReplicas < replicas ≤ maxReplicas |
4 |
5 |
1/10 |
HPA: 4/10 Deployments: 5 |
When the value of targetReplicas is greater than that of minReplicas and smaller than that of replicates:
|
4 |
minReplicas < targetReplicas = replicas < maxReplicas |
5 |
5 |
1/10 |
HPA: 5/10 Deployments: 5 |
When the value of targetReplicas is greater than that of minReplicas and equal to that of replicates:
|
5 |
minReplicas ≤ replicas < targetReplicas < maxReplicas |
6 |
5 |
1/10 |
HPA: 6/10 Deployments: 6 |
When the value of targetReplicas is greater than that of replicates and less than that of maxReplicas:
|
6 |
minReplicas ≤ replicas < targetReplicas = maxReplicas |
10 |
5 |
1/10 |
HPA: 10/10 Deployments: 10 |
When the value of targetReplicas is greater than that of replicates and equal to that of maxReplicas:
|
7 |
minReplicas ≤ replicas ≤ maxReplicas < targetReplicas |
11 |
5 |
5/10 |
HPA: 11/11 Deployments: 11 |
When the value of targetReplicas is greater than that of maxReplicas:
|
Using the CCE console
CronHPA periodically adjusts the maximum and minimum numbers of pods using the 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. |
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 of 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 of v1.25 or later.
|
System Policy |
|
Custom Policy (supported only in clusters of 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.
|
Parameter |
Description |
---|---|
Target Instances |
When the policy is triggered, CCE will adjust the number of HPA policy pods based on service requirements. For details, see Table 1. |
Trigger Time |
You can select a specific time every day, every week, every month, or every year. NOTE:
This time indicates the local time of where the node is deployed. |
Enable |
Enable or disable the policy rule. |
Using kubectl
When the CronHPA is compatible with the HPA policy, the scaleTargetRef field in CronHPA must be set to the HPA policy, and the scaleTargetRef field in the HPA policy must be set to Deployment. In this way, CronHPA adjusts the maximum and minimum numbers of pods in the HPA policy at a fixed time and the scheduled scaling is compatible with the auto scaling.
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 a Deployment. apiVersion: apps/v1 kind: Deployment name: nginx targetCPUUtilizationPercentage: 50
apiVersion: autoscaling.cce.io/v2alpha1 kind: CronHorizontalPodAutoscaler metadata: name: ccetest namespace: default spec: scaleTargetRef: # Associate an HPA policy. apiVersion: autoscaling/v1 kind: HorizontalPodAutoscaler name: hpa-test rules: - ruleName: "scale-down" schedule: "15 * * * *" # Running time and period of a job. For details, see Cron, for example, 0 * * * * or @hourly. targetReplicas: 1 # Number of target pods disable: false - ruleName: "scale-up" schedule: "13 * * * *" targetReplicas: 11 disable: false
Field |
Description |
---|---|
apiVersion |
API version. The value is fixed at autoscaling.cce.io/v2alpha1. |
kind |
API type. The value is fixed at CronHorizontalPodAutoscaler. |
metadata.name |
Name of a CronHPA policy. |
metadata.namespace |
Namespace to which the CronHPA policy belongs. |
spec.scaleTargetRef |
Specifies the scaling object of CronHPA. The following fields can be configured:
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 rule. Multiple rules can be added. The following fields can be configured for each rule:
|
CronHPA adjusts associated Deployments separately to periodically adjust the number of Deployment pods. The method is as follows:
Using the CCE console
CronHPA periodically adjusts the number of workload pods.
Parameter |
Description |
---|---|
Target Instances |
When a policy is triggered, the number of workload pods will be adjusted to the value of this parameter. |
Trigger Time |
You can select a specific time every day, every week, every month, or every year. NOTE:
This time indicates the local time of where the node is deployed. |
Enable |
Enable or disable the policy rule. |
Using kubectl
apiVersion: autoscaling.cce.io/v2alpha1 kind: CronHorizontalPodAutoscaler metadata: name: ccetest namespace: default spec: scaleTargetRef: # Associate a Deployment. apiVersion: apps/v1 kind: Deployment name: nginx rules: - ruleName: "scale-down" schedule: "08 * * * *" # Running time and period of a job. For details, see Cron, for example, 0 * * * * or @hourly. targetReplicas: 1 disable: false - ruleName: "scale-up" schedule: "05 * * * *" targetReplicas: 3 disable: false