This topic describes how to implement auto scaling based on Alibaba Cloud metrics.
Prerequisites
Background information
In many scenarios, you may want to scale applications based on metrics such as the HTTP request rate and the query rate of the Ingress. By default, the HPA does not support custom or external metrics. However, Kubernetes provides the external metrics API that allows you to implement auto scaling in a flexible manner.
Deploy alibaba-cloud-metrics-adapter
- Log on to the ACK console.
- In the left-side navigation pane of the ACK console, choose .
- On the App Catalog page, click the Alibaba Cloud Apps tab. Select Auto Scaling and click ack-alibaba-cloud-metrics-adapter.
- In the Deploy section, select the cluster that you want to scale and click Create.
- View the deployed ack-alibaba-cloud-metrics-adapter component.
Examples
The following example shows how to configure HPA by creating a Deployment and a Service that are both named Nginx.
FAQ
-
What do I do if the TARGETS column shows <unknow> after I run the
kubectl get hpa
command?Perform the following operations to troubleshoot the issue:- Run the
kubectl describe hpa <hpa_name>
command to check why HPA does not function as normal.- If the value of AbleToScale is False in the Conditions field, check whether the Deployment is created as normal.
- If the value of ScalingActive is False in the Conditions field, proceed to the next step.
- Run the
kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1/"
command. If Error from server (NotFound): the server could not find the requested resource is returned, verify the status of alibaba-cloud-metrics-adapter.If the status of alibaba-cloud-metrics-adapter is normal, check whether the HPA metrics are relevant to the Ingress. If the metrics are relevant to the Ingress, make sure that you deploy the Log Service component before ack-alibaba-cloud-metrics-adapter is deployed. For more information, see Analyze and monitor the access log of nginx-ingress.
- Make sure that the values of the HPA metrics are valid. The value of sls.ingress.route must be in the
<namespace>-<svc>-<port>
format.- namespace specifies the namespace to which the Ingress belongs.
- svc specifies the name of the Service that you selected when you created the Ingress.
- port specifies the port of the Service.
- Run the
-
Where can I find the metrics that are supported by HPA?
For more information about the metrics that are supported by HPA, see Alibaba Cloud metrics adapter. The following table describes the commonly used metrics.Metric Description Additional parameter sls_ingress_qps The number of requests that the Ingress can process per second based on a specific routing rule. sls.ingress.route sls_ingress_latency_avg The average latency of all requests. sls.ingress.route sls_ingress_latency_p50 The maximum latency for the fastest 50% of all requests. sls.ingress.route sls_ingress_latency_p95 The maximum latency for the fastest 95% of all requests. sls.ingress.route sls_ingress_latency_p99 The maximum latency for the fastest 99% of all requests. sls.ingress.route sls_ingress_latency_p9999 The maximum latency for the fastest 99.99% of all requests. sls.ingress.route sls_ingress_inflow The inbound bandwidth of the Ingress. sls.ingress.route