You need to enable JavaScript to run this app.
Volcengine Kubernetes Engine

Volcengine Kubernetes Engine

Copy page
Download PDF
Horizontal Pod Autoscaler (HPA)
Autoscaling based on self-managed Prometheus
Copy page
Download PDF
Autoscaling based on self-managed Prometheus
When you use a self-managed Prometheus system to monitor clusters, you can deploy the open source Prometheus adapter in the clusters to connect to your self-managed Prometheus. This achieves Horizontal Pod Autoscaler (HPA) based on custom metrics. This topic describes how to deploy the open source Prometheus adapter in a cluster and achieve HPA.​
Differences​
You can use a self-managed Prometheus system or VMP to connect to a VKE cluster and achieve HPA based on metrics. The following table describes the main differences when different systems are connected.​
Prometheus adapter add-on and open source Prometheus adapter​
​
Item​
Prometheus adapter add-on​
Open source Prometheus adapter​
Stability and support​
VKE provides stability guarantee and technical support.​
You need to manage and maintain it yourself and seek support from the community.​
Adaptability​
It can automatically adapt to VMP.​
You need to set up and adapt to a Prometheus service.​
Ease of use​
It is easy to use.​
The features are consistent with the community edition.​
​
VMP and self-managed Prometheus​
​
Item​
VMP​
Self-managed Prometheus​
Adaptability​
Highly compatible with VKE clusters.​
It is managed and maintained by the user and is consistent with the community version.​
Service scope​
Provides a complete managed solution from collection to observation.​
-​
Access method​
Supports the standard Prometheus access method.​
-​
​
Prerequisites​
  • A cluster has been created and is running as expected. For detailed operations, see Creating clusters.​
  • The self-managed Prometheus service has been deployed, and the VKE cluster can access the service and collect metric data as expected.​
  • Configure the local environment (Linux/Mac):​
  • Install and configure the Helm tool. Make sure that Helm can be connected to the specified Helm repository.​
Limit​
  • When you modify the Prometheus URL and configure authentication, invalid configurations may cause the Prometheus adapter to fail to obtain metric data, which will affect the autoscaling feature of HPA.​
  • When you pull an image, if the specified image architecture is inconsistent with the architecture of the Kubernetes cluster nodes, the image may not run as expected in the cluster.​
  • When you configure custom metrics, invalid configurations will prevent HPA from autoscaling as expected. This may cause resource waste or degraded business performance.​
Procedure​
Step 1: Pull a chart​
  1. On your on-premises computer, run the following command to pull the Prometheus adapter chart locally.​
​
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts​
helm repo update​
helm pull prometheus-community/prometheus-adapter​
​
  1. Extract the pulled chart file and access the extracted folder. The file named prometheus-adapter-4.11.0.tgz is used as an example in this topic.​
​
tar -zxvf prometheus-adapter-4.11.0.tgz && cd prometheus-adapter​
​
Step 2: Modify configurations​
  1. Open the values.yaml file on your on-premises computer and change the Prometheus URL to the query address of your self-managed Prometheus system. If the port number is not required, you can delete it.​
  • ​alt​​
  1. If you have configured basic authentication for the self-managed Prometheus system, add the extraArguments field in values.yaml to authenticate the Prometheus adapter. Generate the token using online or offline tools with your Prometheus basic authentication credentials, then add it to the corresponding parameter.​
  • ​alt​​
Step 3: Build an image​
  1. Pull an image that matches the architecture of your Kubernetes cluster nodes from your on-premises computer. This topic uses the linux/amd64 architecture as an example.​
​
docker pull --platform linux/amd64 registry.k8s.io/prometheus-adapter/prometheus-adapter:v0.12.0​
​
  1. Add tags to the pulled image and specify the address of the target container registry, image name, and version number. This topic takes doc-cn-beijing.cr.volces.com/vke/prometheus-adapter-demo:v1.0 as an example.​
​
docker tag registry.k8s.io/prometheus-adapter/prometheus-adapter:v0.12.0 doc-cn-beijing.cr.volces.com/vke/prometheus-adapter-demo:v1.0​
​
  1. Push the image to the target container registry. If you use the Container Registry (CR) service of Volcano Engine, see Pushing and pulling images for more operation details.​
​
docker push doc-cn-beijing.cr.volces.com/vke/prometheus-adapter-demo:v1.0​
​
  1. Modify the image path in the values.yaml file so that it points to the pushed image address.​
  • ​alt​​
Step 4: Configure custom metrics​
  1. In the configuration section of custom metrics in values.yaml, set default to false, which indicates that the default configuration is disabled.​
  • ​alt​​
  1. Specify the custom field. The following sample code takes the network metrics container_network_receive_bytes_total and container_network_transmit_bytes_total as examples.​
​
rules:​
default: false​
​
custom:​
- seriesQuery: 'container_network_receive_bytes_total'​
resources:​
overrides:​
namespace: {resource: "namespace"}​
pod: {resource: "pod"}​
name: {as: 'k8s_pod_network_receive_throughput'}​
metricsQuery: 'sum(rate(<<.Series>>{<<.LabelMatchers>>,pod!=""}[1m])) by (<<.GroupBy>>) / 125000.0'​
- seriesQuery: 'container_network_transmit_bytes_total'​
resources:​
overrides:​
namespace: {resource: "namespace"}​
pod: {resource: "pod"}​
name: {as: 'k8s_pod_network_transmit_throughput'}​
metricsQuery: 'sum(rate(<<.Series>>{<<.LabelMatchers>>,pod!=""}[1m])) by (<<.GroupBy>>) / 125000.0'​
​
Step 5: Install the chart​
In the prometheus-adapter folder, run the following command to install the chart. Replace prom-adapter with another name based on your business requirements.​
​
helm install prom-adapter .​
​
Viewing configurations​
After the Prometheus-adapter is installed, log in to the cluster and check whether all related workloads are running as expected and the parameters are valid.​
  1. Log in to VKE console.​
  1. In the left navigation bar, click Cluster.​
  1. On the cluster list page, click the cluster you want to configure.​
  1. In the left navigation bar of the cluster management page, click Workload > Deployment. In the workload list, check whether all related workloads function as expected.​
  1. In the left navigation bar of the cluster management page, click Configurations > ConfigMap to view ConfigMaps.​
  1. In the left navigation bar of the cluster management page, click Workload > Resource Explorer. Select API Group from the Category list to view API groups.​
Result validation​
  1. Create a workload in the cluster. This topic provides an example of how to create a Deployment.​
​
apiVersion: apps/v1​
kind: Deployment​
metadata:​
name: workload-demo​
namespace: default​
spec:​
replicas: 1​
selector:​
matchLabels:​
app: workload-demo​
template:​
metadata:​
labels:​
app: workload-demo​
spec:​
containers:​
- name: nginx​
image: nginx:1.14.2​
ports:​
- containerPort: 80​
​
  1. Create an HPA associated with the workload and configure autoscaling based on network metrics.​
​
apiVersion: autoscaling/v2​
kind: HorizontalPodAutoscaler​
metadata:​
name: hpa-demo​
namespace: default​
spec:​
maxReplicas: 10​
metrics:​
- pods:​
metric:​
name: k8s_pod_network_receive_throughput​
target:​
averageValue: "80"​
type: AverageValue​
type: Pods​
- pods:​
metric:​
name: k8s_pod_network_transmit_throughput​
target:​
averageValue: "80"​
type: AverageValue​
type: Pods​
minReplicas: 1​
scaleTargetRef:​
apiVersion: apps/v1​
kind: Deployment​
name: workload-demo​
​
  1. View workload details. Click the Autoscaling tab, and you can view the HPA configuration of the current workload. Achieve horizontal scaling for the workload based on the self-managed Prometheus system.​
​
Last updated: 2026.07.24 14:51:38