All Products
Search
Document Center

Container Compute Service:Horizontal Pod Autoscaler (HPA)

Last Updated:Jun 17, 2026

Horizontal Pod Autoscaler (HPA) automatically adjusts the number of pod replicas based on resource utilization. In Container Service for Kubernetes (ACK), you can enable HPA for applications by using the console or kubectl.

Prerequisites

Create an HPA-enabled application

Use the console

  1. Log on to the ACS console. In the left navigation pane, click Clusters.

  2. On the Clusters page, click the name of the target cluster. In the left navigation pane, choose Workloads > Deployments.

  3. On the Deployments page, click Create with Image.

  4. On the Basic Information page, set the application parameters and click Next.

    Parameter

    Description

    Namespace

    The namespace for the application. Defaults to default.

    Application Name

    The name of the application.

    Replicas

    The number of pods for the application. Default: 2.

    Workload

    The type of workload. Select Deployments, StatefulSets, Jobs, or CronJobs.

    Labels

    A label to identify the application.

    Annotations

    An annotation for the application.

    Instance Type

    The instance type of the pod. Select General-purpose, BestEffort, or Performance-enhanced.

  5. On the Container page, configure the container, select an image, and specify resource requests. Then, click Next. For more information, see Container configuration.

    Note

    HPA requires resource requests to be specified for the Deployment.

  6. On the Advanced page, in the Access Control section, click Create next to Service, and configure the Service parameters. For more information, see Advanced configurations.

  7. On the Advanced page, select Enable for HPA and configure the scaling parameters.

    • Metric: The supported metrics are CPU and memory. Must match the configured required resource type.

    • Condition:: The resource utilization percentage. The container scales out when utilization exceeds this value. For more information about the Horizontal Pod Autoscaling algorithm, see Algorithm details.

    • Max. Replicas: The maximum number of containers the Deployment can run.

    • Min. Replicas: The lower limit on the number of replicas.

  8. Click Create to create the HPA-enabled Deployment.

Use kubectl

You can also use an orchestration template and kubectl to create an HPA object and bind it to a Deployment.

The following example uses an NGINX application.

  1. Create a file named nginx.yaml and copy the following content into it.

    apiVersion: apps/v1 
    kind: Deployment
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: nginx  
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: registry-cn-hangzhou.ack.aliyuncs.com/ack-demo/nginx:1.7.9 # Replace with your image name and tag
            ports:
            - containerPort: 80
            resources:
              requests:                         ## Required for HPA to function.
                cpu: 500m
  2. Run the following command to deploy the NGINX application.

    kubectl apply -f nginx.yaml
  3. Create an hpa.yaml file with the following content to define the HPA.

    The scaleTargetRef field specifies the resource that HPA scales. In this example, it targets the nginx Deployment.

    apiVersion: autoscaling/v2
    kind: HorizontalPodAutoscaler
    metadata:
      name: nginx-hpa
    spec:
      scaleTargetRef:
        apiVersion: apps/v1
        kind: Deployment
        name: nginx
      minReplicas: 1  # The minimum replica count. Must be >= 1.
      maxReplicas: 10 # The maximum replica count. Must be > minReplicas.
      metrics:
      - type: Resource
        resource:
          name: cpu
          target:
            type: Utilization
            averageUtilization: 50 # The target average utilization across all pods, calculated as (average usage / requested amount).
                   
  4. Run the following command to create the HPA.

    kubectl apply -f hpa.yaml
  5. After the HPA is created, run kubectl describe hpa <HPA_NAME>.

    The following output indicates that HPA is working correctly.

     Type    Reason             Age    From                       Message
      ----    ------             ----   ----                       -------
      Normal  SuccessfulRescale  4m53s  horizontal-pod-autoscaler  New size: 1; reason: All metrics below target

Related information

For scheduled autoscaling, see Cron Horizontal Pod Autoscaler (CronHPA).