All Products
Search
Document Center

Container Service for Kubernetes:Scale pods based on Nginx Ingress metrics

Last Updated:Mar 26, 2026

Scale pods based on real traffic signals—not just CPU—by connecting Simple Log Service (SLS) Ingress metrics to Kubernetes horizontal pod autoscaling (HPA) through the External Metrics API. This guide walks through a complete example: deploy an Nginx application, expose it through an Ingress, then configure HPA to scale based on queries per second (QPS) and 99.99th-percentile latency.

Prerequisites

Before you begin, ensure that you have:

  • An ACK cluster with kubectl configured

  • An Ingress controller with SLS log collection enabled (enabled by default when you create a cluster)

  • Permissions to install Helm charts and create HPA resources

How it works

The ack-alibaba-cloud-metrics-adapter component bridges Alibaba Cloud monitoring services and the Kubernetes External Metrics API. Once installed, HPA can query SLS Ingress metrics—such as sls_ingress_qps and sls_ingress_latency_p9999—and adjust the replica count of your Deployment accordingly.

Step 1: Install ack-alibaba-cloud-metrics-adapter

The ack-alibaba-cloud-metrics-adapter component enables Kubernetes to retrieve monitoring data from Alibaba Cloud services—including ECS, SLB, and RDS—through the External Metrics API.

Important

This component does not support in-place upgrades. To upgrade, uninstall the current version first and then install the latest version. During uninstallation and reinstallation, related HPAs pause scaling because monitoring data retrieval stops.

  1. Log on to the Container Service Management Console. In the navigation pane, click Clusters.

  2. Click the name of your cluster. In the left navigation pane, choose Applications > Helm.

  3. On the Helm page, click Create. Complete the Basic Information configuration, select ack-alibaba-cloud-metrics-adapter, and click Next.

  4. On the Parameter Settings page, select a Chart Version and click OK.

Step 2: Deploy a test application

  1. Create nginx-test.yaml with the following content:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx-deployment-basic
      labels:
        app: nginx
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx:1.7.9
            ports:
            - containerPort: 80
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: nginx
      namespace: default
    spec:
      ports:
        - port: 80
          protocol: TCP
          targetPort: 80
      selector:
        app: nginx
      type: ClusterIP
  2. Apply the configuration:

    kubectl apply -f nginx-test.yaml

Step 3: Create an Ingress

  1. In the left navigation pane of the cluster management page, choose Network > Ingress. On the Ingress page, click Create Ingress.

  2. Fill in the required fields and click OK. The console redirects you to the Ingress page.

  3. In the Name column, click the Ingress name to view its routing rules. For details, see Manage Ingress.

Step 4: Configure HPA

HPA supports two SLS Ingress metrics with different scaling semantics:

MetricTarget typeScaling behavior
sls_ingress_qpsAverageValueQPS is divided by the current pod count before comparison
sls_ingress_latency_p9999ValueRaw latency value is compared directly
  1. Create ingress-hpa.yaml with the following content:

    ParameterRequiredDescription
    sls.ingress.routeYesFormat: <namespace>-<svc>-<port>. Example: default-nginx-80
    sls.logstoreYesThe Logstore in Simple Log Service. Default: nginx-ingress
    sls.projectYesThe Project in Simple Log Service. Default: k8s-log-<cluster-id>
    sls.internal.endpointNoWhether to access SLS over the internal network. Default: true. Set to false to use the public network.
    apiVersion: autoscaling/v2
    kind: HorizontalPodAutoscaler
    metadata:
      name: ingress-hpa
    spec:
      scaleTargetRef:
        apiVersion: apps/v1
        kind: Deployment
        name: nginx-deployment-basic
      minReplicas: 2
      maxReplicas: 10
      metrics:
        - type: External
          external:
            metric:
              name: sls_ingress_qps
              selector:
                matchLabels:
                  sls.project: "<your-sls-project>"      # Default: k8s-log-<cluster-id>
                  sls.logstore: "nginx-ingress"           # Default SLS Logstore for Nginx Ingress logs
                  sls.ingress.route: "default-nginx-80"  # Format: <namespace>-<svc>-<port>
            target:
              type: AverageValue
              averageValue: 10   # Scale up when average QPS per pod exceeds 10
        - type: External
          external:
            metric:
              name: sls_ingress_latency_p9999
              selector:
                matchLabels:
                  sls.project: "<your-sls-project>"
                  sls.logstore: "nginx-ingress"
                  sls.ingress.route: "default-nginx-80"
                  # sls.internal.endpoint: "true"         # true = internal network (default); false = public network
            target:
              type: Value
              value: 10   # Scale up when 99.99th-percentile latency exceeds 10 ms

    The following table describes the parameters used in the HPA configuration.

  2. Apply the configuration:

    kubectl apply -f ingress-hpa.yaml

Verify scaling

Run a 5-minute load test against your Ingress domain to trigger scale-up:

# Send 10 concurrent requests for 300 seconds
ab -t 300 -c 10 <domain-name-configured-for-the-ingress>

Watch the HPA status in real time:

kubectl get hpa ingress-hpa --watch

Expected output when scale-up succeeds (REPLICAS reaches MAXPODS):

NAME            REFERENCE                              TARGETS           MINPODS   MAXPODS   REPLICAS   AGE
ingress-hpa     Deployment/nginx-deployment-basic      21/10 (avg)       2         10        10         7m49s

When traffic drops below the threshold, REPLICAS returns to the minimum value.

Troubleshooting

Start troubleshooting by running kubectl describe hpa ingress-hpa and checking the Conditions field. Use the Type and Status columns to identify the issue, then follow the steps below.

The `target` column shows `unknown`

  1. Run kubectl describe hpa <hpa-name> and check the Conditions field:

    • If AbleToScale is False: confirm the Deployment is healthy.

    • If ScalingActive is False: proceed to the next step.

  2. Run the following command to check whether the External Metrics API is available:

    kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1/"

    If the response is Error from server (NotFound), check the startup status of alibaba-cloud-metrics-adapter. If the adapter is running normally and the HPA metrics are Ingress-related, deploy the SLS component first. For details, see Collect and analyze Nginx Ingress access logs.

  3. Verify the format of sls.ingress.route. The value must be <namespace>-<svc>-<port>, where:

    • namespace: the namespace where the Ingress resides

    • svc: the Service name associated with the Ingress

    • port: the port name of that Service

Failed to pull ack-alibaba-cloud-metrics-adapter image (version 1.3.7)

When upgrading to version 1.3.7, you may see:

Failed to pull image "registry-<region-id>-vpc.ack.aliyuncs.com/acs/alibaba-cloud-metrics-adapter-amd64:v0.2.9-ba634de-aliyun".

This happens because the component does not support direct updates. To resolve this:

  1. Back up the current component configuration.

  2. Uninstall the old version.

  3. Install the latest version using the backup configuration.

FAQ

How do I query sls_ingress_qps from the command line?

kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1/namespaces/*/sls_ingress_qps?labelSelector=sls.project={{SLS_Project}},sls.logstore=nginx-ingress"

Replace {{SLS_Project}} with your SLS Project name. If you didn't set a custom name when creating the cluster, the default is k8s-log-{{ClusterId}}.

A successful response returns an ExternalMetricValueList with the current QPS in the value field. If you get a ParameterInvalid error, the metric has no data—this typically means ALB Ingress is not configured but sls_alb_ingress_qps was queried instead of sls_ingress_qps.

What metrics does HPA support?

For the full list, see Alibaba Cloud HPA Metrics. Common SLS Ingress metrics:

MetricDescriptionRequired parameter
sls_ingress_qpsQPS for the specified Ingress routesls.ingress.route
sls_alb_ingress_qpsQPS for ALB Ingress routesls.ingress.route
sls_ingress_latency_avgAverage latency for all requestssls.ingress.route
sls_ingress_latency_p50Latency at the 50th percentilesls.ingress.route
sls_ingress_latency_p95Latency at the 95th percentilesls.ingress.route
sls_ingress_latency_p99Latency at the 99th percentilesls.ingress.route
sls_ingress_latency_p9999Latency at the 99.99th percentilesls.ingress.route
sls_ingress_inflowInbound bandwidth for Ingresssls.ingress.route

How do I adapt HPA after customizing the Nginx Ingress log format?

SLS log collection relies on the AliyunLogConfig custom resource definition (CRD) deployed when SLS is first enabled. This CRD is tuned for the default ACK Ingress Controller log format. If you modified the Ingress Controller's access log format, update the processor_regex section in the CRD configuration to match your custom format. For details, see Collect container logs using a DaemonSet and a CRD.

If SLS was disabled when you created the cluster and you need Ingress metrics for HPA, re-enable or configure SLS first. For details, see Collect and analyze Nginx Ingress access logs.

What's next