Help Center> Cloud Container Engine> User Guide> New Console> Auto Scaling> Scaling a Workload> Creating an HPA Policy for Workload Auto Scaling

Creating an HPA Policy for Workload Auto Scaling

Horizontal Pod Autoscaling (HPA) in Kubernetes implements horizontal scaling of pods. In a CCE HPA policy, you can configure different cooldown time windows and scaling thresholds for different applications based on the Kubernetes HPA.

Prerequisites

To use HPA policies, you need to install add-ons that can provide the metrics API, such as metrics-server and prometheus.

Notes and Constraints

  • HPA policies can be created only for clusters of v1.13 or later.
  • Only one policy can be created for each workload. That is, if you have created an HPA policy, you cannot create CustomedHPA policies or other HPA policies for the workload. You can delete the created HPA policy and create a new one.
  • For clusters earlier than v1.19.10, if an HPA policy is used to scale out a workload with EVS volumes mounted, the existing pods cannot be read or written when a new pod is scheduled to another node.

    For clusters of v1.19.10 and later, if an HPA policy is used to scale out a workload with EVS volume mounted, a new pod cannot be started because EVS disks cannot be attached.

Procedure

  1. Log in to the CCE console and access the cluster details page.
  2. In the navigation pane, choose Workload Scaling. Then click Create HPA Policy in the upper right corner.
  3. Set policy parameters.

    Table 1 HPA policy parameters

    Parameter

    Description

    Policy Name

    Name of the policy to be created. Set this parameter as required.

    Namespace

    Namespace to which the workload belongs.

    Associated Workload

    Workload with which the HPA policy is associated.

    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 available only for clusters of v1.15 and later. It is not supported in clusters of v1.13 or earlier.

    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.

    Rules

    Policy rules can be based on system metrics or custom metrics.

    System Policy

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

      Usage = CPUs or memory used by pods/Requested CPUs or memory.

    • Expected Value: Enter the expected average resource usage.

      This parameter indicates the expected value of the selected metric. The number of new pods required (rounded up) = Current metric value/Expected value x Number of current pods

    • Threshold: Enter the scaling thresholds.

      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.

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

    • Metric Name: name of the custom metric. You can select a name as prompted.

      Before you can configure a custom metric, you need to install the add-on prometheus. For details about how to collect custom metrics, see Monitoring Custom Metrics.

    • Source: Select an object type from the drop-down list. You can select Pod.
    • Expected Value: the average metric value of all pods.
    • Threshold: thresholds for scale-in and scale-out. Scaling is performed only when the current metric value is beyond 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.
    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.

  4. After the configuration is complete, click Create. If the system displays a message indicating that the request to create workload policy *** is successfully submitted, click Back to Workload Scaling.
  5. On the Workload Scaling tab page, you can view the newly created HPA policy.