All Products
Search
Document Center

Microservices Engine:Auto-scale ACK applications based on gateway QPS

Last Updated:Jun 20, 2026

As the traffic entry point, an MSE gateway provides the most accurate view of your application's traffic volume. Use the queries per second (QPS) metrics from the gateway to enable auto scaling for applications in Container Service for Kubernetes (ACK). This allows your backend services to scale on demand. This topic shows you how to configure auto scaling for ACK applications by using gateway access logs.

Prerequisites

Procedure

  1. Deploy the following resources in your ACK cluster.

    1. Log on to the ACK console. In the left navigation pane, click Marketplace > Marketplace.

    2. Search for ack-alibaba-cloud-metrics-adapter and click its application card. On the details page, click Deploy. In the Deploy panel, configure the parameters and click OK.

      Set the following parameters: select the target cluster, set the namespace to kube-system, and set the release name to ack-alibaba-cloud-metrics-adapter.

    3. In the navigation pane on the left, click Clusters.

    4. On the Clusters page, click the name of your cluster. In the left navigation pane, click Workloads > Deployments.

    5. On the Deployments page, click Create Resources in YAML. Select Custom from the template list, paste the following YAML, and then click Create.

      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: httpbin-deploy
        labels:
          app: httpbin-deploy
      spec:
        replicas: 1
        selector:
          matchLabels:
            app: httpbin
        template:
          metadata:
            labels:
              app: httpbin
          spec:
            containers:
            - image: kennethreitz/httpbin
              imagePullPolicy: IfNotPresent
              name: httpbin
              ports:
              - name: http
                containerPort: 80
      ---
      apiVersion: v1
      kind: Service
      metadata:
        name: httpbin-svc
        namespace: default
        labels:
          app: httpbin-svc
      spec:
        ports:
          - port: 8080
            name: http
            protocol: TCP
            targetPort: 80
        selector:
          app: httpbin
        type: ClusterIP
  2. In the MSE gateway, add a service source and create a service.

    1. Log on to the MSE console. In the top navigation bar, select a region.

    2. In the left-side navigation pane, choose Cloud-native Gateway > Gateways. On the Gateways page, click the ID of the gateway.

    3. In the left-side navigation pane, click Routes. Then, click the Source tab.

    4. Click Add Source. For Source Type, select Container Service, choose the ACK cluster where your application is deployed, and then click OK.

    5. In the left-side navigation pane, click Routes. Then, click the Services tab.

    6. Click Add Service to add the service source to the Services, and then click OK.

  3. Create a routing rule for the service that you added. For more information, see Create a routing rule.

  4. Enable log shipping.

    1. In the left-side navigation pane, click Parameter Settings.

    2. In the Observability Parameters section, click the settings icon图标2.png next to Log Shipping. In the dialog box that appears, enable log shipping and the Compatible with NGINX Ingress option.

      Leave Simple Log Service (SLS) Project set to Use Default, and then click OK.

  5. In your ACK cluster, create a HorizontalPodAutoscaler (HPA) and configure its settings.

    You need to specify the backend application to scale, the minimum and maximum replica count, and the scaling metrics. The following example configuration scales out the application when the average QPS per pod exceeds 10. In this example, sls.project is the log shipping project name, which can be found on the Parameter Settings page in the gateway console. The sls.ingress.route is formatted as <namespace>-<service-name>-<service-port>.

    apiVersion: autoscaling/v2
    kind: HorizontalPodAutoscaler
    metadata:
      name: higress-hpa
    spec:
      scaleTargetRef:
        apiVersion: apps/v1beta2
        kind: Deployment
        name: httpbin-deploy
      minReplicas: 1
      maxReplicas: 10
      metrics:
        - type: External
          external:
            metric:
              name: sls_ingress_qps
              selector:
                matchLabels:
                  sls.project: "aliyun-product-data-xxxxxxxxxxxxx-cn-hangzhou"
                  sls.logstore: "nginx-ingress"
                  sls.ingress.route: "default-httpbin-svc-8080"
            target:
              type: AverageValue
              averageValue: 10
  6. Run a load test against the application by routing traffic with a controlled QPS through the gateway. Then, observe the HPA events to verify the scaling behavior.

    Run the following command:

    kubectl describe hpa higress-hpa

    The output is similar to the following:

    Normal  SuccessfulRescale  9m     horizontal-pod-autoscaler  New size: 3; reason: external metric sls_ingress_qps(&LabelSelector{MatchLabels:map[string]string{sls.ingress.route: default-httpbin-svc-8080,sls.logstore: nginx-ingress,sls.project: aliyun-product-data-xxxxxxxxxxxxxxxx-cn-hangzhou,},MatchExpressions:[]LabelSelectorRequirement{},}) above target
    Normal  SuccessfulRescale  8m45s  horizontal-pod-autoscaler  New size: 4; reason: external metric sls_ingress_qps(&LabelSelector{MatchLabels:map[string]string{sls.ingress.route: default-httpbin-svc-8080,sls.logstore: nginx-ingress,sls.project: aliyun-product-data-xxxxxxxxxxxxxxxx-cn-hangzhou,},MatchExpressions:[]LabelSelectorRequirement{},}) above target
    Normal  SuccessfulRescale  5m12s  horizontal-pod-autoscaler  New size: 4; reason:
    Normal  SuccessfulRescale  3m41s  horizontal-pod-autoscaler  New size: 3; reason: All metrics below target
    Normal  SuccessfulRescale  2m55s  horizontal-pod-autoscaler  New size: 1; reason: All metrics below target