Volcengine Kubernetes Engine (VKE) supports workload autoscaling through KEDA, the event-driven autoscaler add-on, which helps users reduce costs. This topic describes how to achieve workload autoscaling based on network metrics provided by API Gateway (APIG).
Background information
KEDA functions as an event-driven autoscaling add-on supported by VKE, which can be connected to multiple data sources and scale out workloads from zero and scale in workloads to zero. By leveraging the network request metrics provided by APIG, KEDA can scale in workloads to zero or scale out workloads from zero. This effectively reduces cloud costs during the idle period, enhances elasticity, and improves service competitiveness.
Prerequisites
- A cluster has been created and needs to be running on Kubernetes v1.24 or later. For details, see Creating clusters.
- The apig-controller add-on has been installed in the cluster to connect to APIG. For details, see Installing add-ons.
- A Volcengine Managed Service for Prometheus (VMP) workspace has been created, and basic authentication has been enabled. For more information, see Creating workspaces.
Procedure
Step 1: Create an application and a service
Deploy an application and a service in the cluster. The following sample code demonstrates how to deploy NGINX.
Step 2: Create an APIG Ingress
Step 3: Enable APIG instance monitoring
- In the left navigation bar, click Instance management. On the page that appears, click the name of the target instance to go to the instance details page.
- Click the Monitoring data tab, and click Bind now.
- In the pop-up dialog box, select the created VMP workspace, and click Confirm. Enable APIG instance monitoring and save the monitoring data in the specified VMP workspace.
warning
The APIG instance and the VKE cluster must be bound to the same VMP workspace.
Step 4: Create a KEDA scaling object
- After you install the KEDA add-on, you need to use a secret to configure the basic authentication information for the VMP workspace. The example is as follows:
- Create an authentication CustomResourceDefinition (CRD) for KEDA to enable KEDA to access the VMP workspace. The example is as follows:
- Create a KEDA autoscaling object ScaledObject.
- query indicates the query metric. In this example, the sum(rate(istio_requests_total[1m])) metric is selected, which indicates the total number of APIG requests. request_host indicates the external access address that corresponds to the APIG Ingress associated with APIG. In this example, example.com is used.
Result validation
Checking whether the workloads decline to zero
- In the left navigation bar, click Cluster.
- In the cluster list, click the name of the target cluster.
- In the left navigation bar of the cluster management page, click Monitoring center > Dashboard.
- In the dashboard list on the left side, click Workload monitoring > Deployment monitoring. After you select a namespace and a workload, you can view the monitoring dashboard for the specified workload.
In the monitoring dashboard, you can see that when the workload is created, two replicas are configured. After the KEDA autoscaling object is created, the scaling metric for the workload is 0. Therefore, the number of replicas is changed to the value of idleReplicaCount in the autoscaling object ScaledObject of KEDA, which indicates that the replicas automatically decline to 0.
Checking whether the workloads are scaled out from zero
Use the following command to access applications in the cluster by using APIG Ingress. http://14.***.***.*** indicates the external IP address of the APIG instance. To obtain the IP address, see Obtaining gateway addresses. Expected result: The corresponding application cannot be accessed and the system displays a backend error because the number of replicas for the backend workloads is zero.
In addition, when you view the observability dashboard or corresponding metrics in the APIG console or VMP console, you can view request quantity metrics.
When KEDA in the cluster detects an increase in external metrics, it will scale out backend workloads from zero. Scaling from zero to ready incurs a 15-20 second delay, during which requests are not served.
After the scale-out is complete, use the following command to access the applications in the cluster as expected.
Expected result: Workloads can be accessed as expected through the APIG Ingress.
After external requests are handled, the workloads decline to zero again, effectively reducing cloud costs during the idle period.
View the autoscaling monitoring dashboard for information about workload scale-out and scale-in.