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.
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.
Log on to the Container Service Management Console. In the navigation pane, click Clusters.
Click the name of your cluster. In the left navigation pane, choose Applications > Helm.
On the Helm page, click Create. Complete the Basic Information configuration, select ack-alibaba-cloud-metrics-adapter, and click Next.
On the Parameter Settings page, select a Chart Version and click OK.
Step 3: Create an Ingress
In the left navigation pane of the cluster management page, choose Network > Ingress. On the Ingress page, click Create Ingress.
Fill in the required fields and click OK. The console redirects you to the Ingress page.
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:
| Metric | Target type | Scaling behavior |
|---|---|---|
sls_ingress_qps | AverageValue | QPS is divided by the current pod count before comparison |
sls_ingress_latency_p9999 | Value | Raw latency value is compared directly |
Create
ingress-hpa.yamlwith the following content:Parameter Required Description sls.ingress.routeYes Format: <namespace>-<svc>-<port>. Example:default-nginx-80sls.logstoreYes The Logstore in Simple Log Service. Default: nginx-ingresssls.projectYes The Project in Simple Log Service. Default: k8s-log-<cluster-id>sls.internal.endpointNo Whether to access SLS over the internal network. Default: true. Set tofalseto 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 msThe following table describes the parameters used in the HPA configuration.
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 --watchExpected 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 7m49sWhen 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`
Run
kubectl describe hpa <hpa-name>and check theConditionsfield:If
AbleToScaleisFalse: confirm the Deployment is healthy.If
ScalingActiveisFalse: proceed to the next step.
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 ofalibaba-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.Verify the format of
sls.ingress.route. The value must be<namespace>-<svc>-<port>, where:namespace: the namespace where the Ingress residessvc: the Service name associated with the Ingressport: 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:
Back up the current component configuration.
Uninstall the old version.
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:
| Metric | Description | Required parameter |
|---|---|---|
sls_ingress_qps | QPS for the specified Ingress route | sls.ingress.route |
sls_alb_ingress_qps | QPS for ALB Ingress route | sls.ingress.route |
sls_ingress_latency_avg | Average latency for all requests | sls.ingress.route |
sls_ingress_latency_p50 | Latency at the 50th percentile | sls.ingress.route |
sls_ingress_latency_p95 | Latency at the 95th percentile | sls.ingress.route |
sls_ingress_latency_p99 | Latency at the 99th percentile | sls.ingress.route |
sls_ingress_latency_p9999 | Latency at the 99.99th percentile | sls.ingress.route |
sls_ingress_inflow | Inbound bandwidth for Ingress | sls.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.