# 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

The metrics-server add-on has been installed. This add-on collects public metrics of kubelet in Kubernetes clusters, including the CPU usage and memory usage.

#### 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 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. In the navigation pane, choose Auto Scaling. On the Workload Scaling tab page, click Create HPA Policy.
2. In the Check Add-ons step:

   - If is displayed next to the add-on name, click Install, set add-on parameters as required, and click Install to install the add-on.
   - If is displayed next to the add-on name, the add-on has been installed.
3. After the required add-ons have been installed, click Next: Policy configuration.

   If the add-ons have been installed, after you click Create HPA Policy, you will directly land on the second step to configure the policy. The first step (checking the add-ons) has been completed almost instantly.

4. Set policy parameters by referring to Table 1.

   Table 1 HPA policy parameters
   Parameter | Description
   --- | ---
   Policy Name | Name of the policy to be created. Set this parameter as required.
   Cluster Name | Cluster to which the workload belongs.
   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.

   System metrics
   - 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.

   You can click Add Rule again to add more scaling policies.

   NOTE:

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

5. 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.
6. On the Workload Scaling tab page, you can view the newly created HPA policy.

Parent topic: Scaling a Workload