Updated on 2025-08-12 GMT+08:00

Managing HPA Policies

In Kubernetes, a HorizontalPodAutoscaler is a built-in component that provides horizontal pod autoscaling (HPA). It supports the application-level cooldown time window and scaling threshold functions based on the Kubernetes HPA.

Restrictions

Creating an HPA Policy

  1. Log in to ServiceStage.
  2. Use either of the following methods to go to the Scaling page.

    • On the Application Management page, click the application to which the component belongs, click the target component in Component List, and choose Scaling in the left navigation pane.
    • On the Component Management page, click the target component and choose Scaling in the left navigation pane.

  3. If the component is created by Creating a Component by Importing a CCE Workload and is not enabled:

    1. In the displayed dialog box, click OK.
    2. On the Enable Component page, click Enable and wait until the component is restarted.

  4. Click next to Auto Scaling to enable auto scaling policy configuration. The Create AS Policy page is displayed.

    • If metrics-server has not been installed in the CCE cluster, go to 5.
    • If metrics-server has been installed in the CCE cluster, go to 8.

  5. Click Install one to install metrics-server by referring to Installing Metrics Server.

    Wait until the plug-in is installed. If Status is Running, the plug-in is installed successfully.

  6. Return to the Create AS Policy page.
  7. Click Refresh to refresh the page.
  8. Configure the HPA policy.

    1. Policy Name

      Enter a policy name. After the policy is created, its name cannot be changed.

      Enter 4 to 63 characters. Start with a lowercase letter and end with a lowercase letter or digit. Only use lowercase letters, digits, and hyphens (-).

    2. Cooldown Period

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

      Enter a scale-out/scale-in cooldown period, in minute. The minimum period is 1 minute.

      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.

    3. Instances

      Enter the minimum and maximum numbers of pods. The minimum number is an integer ranging from 1 to 299. The maximum number is an integer ranging from 1 to 1500 and must be greater than the minimum number.

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

    4. Scaling Behavior

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

      • Default: scales workloads using the Kubernetes default behavior.
      • Custom: scales workloads using custom policies such as stabilization window, steps, and priorities. For parameters that are not set, the default values recommended by the Kubernetes community are used.
        • 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: 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.
    5. Triggering Condition

      You can configure trigger condition on the UI or by editing the YAML file.

      Before setting trigger conditions of CPU usage or Memory usage, you need to set the CPU quota (CPU) or memory quota (Memory) for the component.

      To modify the quotas, click Increase quota, set component resource parameters, and upgrade the component. You can customize CPU and Memory to set their quota, and set the maximum/minimum number of CPU cores and memory size (GiB) that can be used by components. In this way, you can set the number of resources required by each component instance. For details about how to upgrade a component, see Upgrading a Component in Single-batch Release Mode.

      • UI
        • Metric: Select CPU usage or Memory usage.

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

        • Desired Value: desired average resource usage. Number of pods to be scaled (rounded up) = (Current metric value/Desired value) x Number of current pods

          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.

        • Threshold: Scaling is not triggered when the desired value is within the range. The desired value must be within the threshold range. If the metric value is greater than the scale-in threshold and less than the scale-out threshold, no scaling is triggered.

          This parameter is supported only in clusters of v1.15 or later.

      • YAML

        To configure custom metric parameters by using YAML, ensure that the prometheus add-on has been installed for the CCE cluster.

        Install the prometheus add-on for the CCE cluster. For details, see prometheus.
         metrics:
           - type: Resource
             resource:
               name: cpu
               target:
                 type: Utilization
                 averageUtilization: 50
           - type: Resource
             resource:
               name: memory
               target:
                 type: Utilization
                 averageUtilization: 50
           - type: Pods
             pods:
               metric:
                 name: packets-per-second
               target:
                 type: AverageValue
                 averageValue: 1k
           - type: Object
             object:
               metric:
                 name: requests-per-second
               describedObject:
                 apiVersion: networking.k8s.io/v1beta1
                 kind: Ingress
                 name: main-route
               target:
                 type: Value
                 value: 10k

        As shown in the preceding example, in addition to using the CPU and memory usage as metrics, you can use the YAML format to customize metric parameters and support more metrics such as pods, object, and external.

  9. Click Create Now.

Modifying an HPA Policy

  1. Log in to ServiceStage.
  2. Use either of the following methods to go to the Scaling page.

    • On the Application Management page, click the application to which the component belongs, click the target component in Component List, and choose Scaling in the left navigation pane.
    • On the Component Management page, click the target component and choose Scaling in the left navigation pane.

  3. On the Scaling page, choose Policy, click Edit, and reconfigure parameters.

    1. Cooldown Period

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

      Enter a scale-out/scale-in cooldown period, in minute. The minimum period is 1 minute.

      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.

    2. Instances

      Enter the minimum and maximum numbers of pods. The minimum number is an integer ranging from 1 to 299. The maximum number is an integer ranging from 1 to 1500 and must be greater than the minimum number.

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

    3. Scaling Behavior

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

      • Default: scales workloads using the Kubernetes default behavior.
      • Custom: scales workloads using custom policies such as stabilization window, steps, and priorities. For parameters that are not set, the default values recommended by the Kubernetes community are used.
        • 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: 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.
    4. Triggering Condition

      You can configure trigger condition on the UI or by editing the YAML file.

      Before setting trigger conditions of CPU usage or Memory usage, you need to set the CPU quota (CPU) or memory quota (Memory) for the component.

      To modify the quotas, click Increase quota, set component resource parameters, and upgrade the component. You can customize CPU and Memory to set their quota, and set the maximum/minimum number of CPU cores and memory size (GiB) that can be used by components. In this way, you can set the number of resources required by each component instance. For details about how to upgrade a component, see Upgrading a Component in Single-batch Release Mode.

      • UI
        • Metric: Select CPU usage or Memory usage.

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

        • Desired Value: desired average resource usage. Number of pods to be scaled (rounded up) = (Current metric value/Desired value) x Number of current pods

          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.

        • Threshold: Scaling is not triggered when the desired value is within the range. The desired value must be within the threshold range. If the metric value is greater than the scale-in threshold and less than the scale-out threshold, no scaling is triggered.

          This parameter is supported only in clusters of v1.15 or later.

      • YAML

        To configure custom metric parameters by using YAML, ensure that the prometheus add-on has been installed for the CCE cluster.

        Install the prometheus add-on for the CCE cluster. For details, see prometheus.
         metrics:
           - type: Resource
             resource:
               name: cpu
               target:
                 type: Utilization
                 averageUtilization: 50
           - type: Resource
             resource:
               name: memory
               target:
                 type: Utilization
                 averageUtilization: 50
           - type: Pods
             pods:
               metric:
                 name: packets-per-second
               target:
                 type: AverageValue
                 averageValue: 1k
           - type: Object
             object:
               metric:
                 name: requests-per-second
               describedObject:
                 apiVersion: networking.k8s.io/v1beta1
                 kind: Ingress
                 name: main-route
               target:
                 type: Value
                 value: 10k

        As shown in the preceding example, in addition to using the CPU and memory usage as metrics, you can use the YAML format to customize metric parameters and support more metrics such as pods, object, and external.

  4. Click OK.

Viewing the Running Status of an HPA Policy

  1. Log in to ServiceStage.
  2. Use either of the following methods to go to the Scaling page.

    • On the Application Management page, click the application to which the component belongs, click the target component in Component List, and choose Scaling in the left navigation pane.
    • On the Component Management page, click the target component and choose Scaling in the left navigation pane.

  3. On the Scaling page:

    • Click the Status tab to view the policy running status.
    • Click the Event tab to view events that occur during policy running.

Disabling an HPA Policy

After the HPA policy is disabled, all data will be cleared. Exercise caution when performing this operation.

  1. Log in to ServiceStage.
  2. Use either of the following methods to go to the Scaling page.

    • On the Application Management page, click the application to which the component belongs, click the target component in Component List, and choose Scaling in the left navigation pane.
    • On the Component Management page, click the target component and choose Scaling in the left navigation pane.

  3. On the Scaling page, click on the right of Auto Scaling.
  1. Click OK.