ack-advanced-vertical-pod-autoscaler (AVPA) is a in-placing scaling component provided by Alibaba cloud. It supports metrics-based in-place scaling and application startup acceleration. This topic describes vertical scaling based on CPU metrics and introduces the use scenarios, configuration, and limits of this feature.
Background information
AVPA supports startup acceleration and metrics-based vertical scaling. You can use these capabilities together with ACS in-place scaling to scale pod resources without business interruptions. This enables you to handle hotspots in business loads.
Comparison between AVPA and open source VPA
VPA | AVPA | |
Scaling method | Recreate pods in one after one. | Perform in-place hot upgrade. |
Scaling scope | Upgrade or downgrade all pods. | Upgrade or downgrade separately. |
Applicable workloads |
|
|
Use scenarios | Long-term and balanced workload changes. | Periodical workload changes, unexpected workload fluctuations, and unbalanced workloads. |
Use scenarios
Gaming businesses: hot upgrade and downgrade for periodically fluctuating CPU workloads.
Online businesses: vertically scale hotspot pods.
Limits
AVPA cannot be used together with open source VPA or HPA.
Vertical scaling based on CPU metrics is supported. If the CPU specifications no longer meet the ACS requirements after scaling, the scaling request is rejected. For example, the system cannot upgrade from
2vCpu2Gito3vCpu2Gi. In addition, you must configure resourcerequestsfor the containers to be scaled.Vertical scaling automatically adjusts the CPU requests and limits of pods. In ACK and ACK serverless clusters, vertical scaling may be constrained due to the limited node resources.
In ACK and ACK serverless clusters, the version of
ack-virtual-nodemust be at leastv2.14.0.AVPA does not create profiles and takes effect only on existing pods. Therefore, new pods are created based on the original resource specifications defined in the workload.
-
ACK currently supports in-place CPU scaling for general-purpose and compute-optimized ACK pods with
ComputeQoS=default.-
The maximum resource specification for in-place scaling is
16vCPU16Gi. -
You can scale up by 100% of the original CPU specification and scale down by 50%. For example, an ACK pod with a specification of
2vCPU4Gican be scaled within the range of1vCPU4Gito4vCPU4Gi. -
In-place scaling is also subject to ACK resource normalization constraints. If a scaled specification is outside the supported range, ACK automatically normalizes it to the nearest supported resource specification. For example, an ACK pod with a specification of
0.75vCPU1.5Giis automatically normalized to1vCPU2Gi.
-
Procedure
This topic uses a sample workload and an optional shadow workload to demonstrate the procedure. AVPA is configured for the sample workload. The shadow workload has the same resource specifications as the sample workload but does not have AVPA configured. This setup simulates a real business load to perform vertical scaling based on CPU load.
The sample workload uses a Service as the traffic Ingress, including a load simulation tool. The tool can trigger the API to consume the specified amount of CPU resources, such as 500 millicores (0.5 core) within 6,000 seconds.
Procedure
Step 1: Enable the in-place scaling feature gate
-
Log on to the ACS console. In the left navigation pane, click Clusters.
-
On the Clusters page, click the name of the target cluster. In the left navigation pane, click Add-ons.
-
In the Core Components section, find the Kube API Server card and click Configuration. In the featureGates field, enter
InPlacePodVerticalScaling=trueto enable the in-place scaling feature gate.NoteDuring the configuration process, the status on the Kube API Server card changes to Executing. When the status returns to Installed, the in-place scaling feature gate is enabled.
Step 2: Install AVPA
In the left-side navigation pane, choose Applications > Helm. Search for and install the ack-advanced-vertical-pod-autoscaler component. For more information, see Use Helm to manage applications in ACK.
Step 3: Deploy the workload and create a local connection
Create a YAML file. You can also create a YAML file named shadow-hello-avpa.yaml for stress testing.
Create a YAML file named hello-avpa.yaml.
apiVersion: apps/v1 kind: Deployment metadata: name: hello-avpa namespace: default spec: replicas: 1 selector: matchLabels: name: hello-avpa template: metadata: annotations: scaling.alibabacloud.com/enable-inplace-resource-resize: 'true' labels: name: hello-avpa vpa: enabled spec: containers: - image: 'registry.cn-hangzhou.aliyuncs.com/acs-demo-ns/simulation-resource-consumer:1.13' name: hello-avpa resources: limits: cpu: '2' memory: '4Gi' requests: cpu: '2' memory: '4Gi' --- apiVersion: v1 kind: Service metadata: name: hello-avpa-svc namespace: default spec: ports: - port: 80 protocol: TCP targetPort: 8080 selector: name: hello-avpa type: ClusterIP(Optional) Create a YAML file named shadow-hello-avpa.yaml.
apiVersion: apps/v1 kind: Deployment metadata: name: shadow-hello-avpa namespace: default spec: replicas: 1 selector: matchLabels: name: shadow-hello-avpa template: metadata: annotations: scaling.alibabacloud.com/enable-inplace-resource-resize: 'true' labels: vpa: enabled name: shadow-hello-avpa spec: containers: - image: 'registry.cn-hangzhou.aliyuncs.com/acs-demo-ns/simulation-resource-consumer:1.13' name: shadow-hello-avpa resources: limits: cpu: '2' memory: '4Gi' requests: cpu: '2' memory: '4Gi' --- apiVersion: v1 kind: Service metadata: name: shadow-avpa-svc namespace: default spec: ports: - port: 80 protocol: TCP targetPort: 8080 selector: name: shadow-hello-avpa type: ClusterIPDeploy the workload.
kubectl apply -f hello-avpa.yaml kubectl apply -f shadow-hello-avpa.yamlRun
kubectl port-forwardto create a local connection.ImportantPort forwarding set up by using
kubectl port-forwardis not reliable, secure, or extensible in production environments. It is only for development and debugging. Do not use this command to set up port forwarding in production environments. For more information about networking solutions used for production in ACK clusters, see Ingress management.kubectl port-forward svc/hello-avpa-svc -n default 28080:80 kubectl port-forward svc/shadow-avpa-svc -n default 28081:80
Step 4: Configure AVPA
You can create an AdvancedVerticalPodAutoscaler resource to configure elastic scaling.
-
Create a YAML file named avpa.yaml.
TargetRef mode
The following scaling configuration is based on the TargetRef mode of AVPA to adjust the resources of the
podscreated by theDeploymentnamedhello-avpain thedefaultnamespace based on the CPU utilization.apiVersion: autoscaling.alibabacloud.com/v1beta1 kind: AdvancedVerticalPodAutoscaler metadata: name: hello-avpa namespace: default spec: metrics: - containerResource: container: hello-avpa name: cpu target: averageUtilization: 30 type: Utilization type: ContainerResource watermark: low - containerResource: container: hello-avpa name: cpu target: averageUtilization: 50 type: Utilization type: ContainerResource watermark: high scaleResourceLimit: maximum: cpu: '4' minimum: cpu: '1' scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: hello-avpaThe following table describes some of the parameters.
Parameter
Required
Description
scaleTargetRef
Yes
The target workload. Currently, AdvancedStatefulSet and CloneSet for Kubernetes-native Deployments, StatefulSets, Jobs, and OpenKruise are supported.
metrics.containerResource
Yes
Specify the type and utilization threshold of the resource whose metrics are collected:
container: the name of the container from which metrics are collected.name: the name of the metric to collect. Only CPU metrics are supported.target: the threshold information.type: set toUtilization.averageUtilization: the average utilization threshold.
NoteFor an ACK serverless pod, metric calculation prioritizes the container's resource limits. If resource limits are not set, the calculation is based on the resource requests. Metric calculation is not supported for pods that have neither resource limits nor requests defined.
metrics.watermark
Yes
Specify the type of threshold. Valid values:
low: the low threshold. When the metric value drops below the threshold, pods are scaled in.high: the high threshold. When the metric value exceeds the threshold, pods are scaled out.
metrics.type
Yes
Specify the metric collection granularity. You can aggregate metrics by container or pod. The default is
ContainerResource.NoteCurrently, you can collect and aggregate metrics by container.
scaleResourceLimit.minimum
No
The lower limit of vertical scaling (for
cpuonly).cpu: The default is 250m (millicores).
scaleResourceLimit.maximum
No
The upper limit of vertical scaling (for
cpuonly).cpu: The default is 64 (cores).
Selector mode
The following Selector mode is introduced in AVPA 0.2.0, which provides a more flexible selector to simplify the pod configuration.
apiVersion: autoscaling.alibabacloud.com/v1beta1 kind: AdvancedVerticalPodAutoscaler metadata: name: hello-avpa namespace: default spec: metrics: - containerResource: container: "*" name: cpu target: averageUtilization: 30 type: Utilization type: ContainerResource watermark: low - containerResource: container: "*" name: cpu target: averageUtilization: 50 type: Utilization type: ContainerResource watermark: high scaleResourceLimit: maximum: cpu: '4' minimum: cpu: '1' # You can modify the following sample selector configuration on demand. selector: matchLabels: vpa: enabled matchExpressions: # A label that applies to all ACS pods. - key: alibabacloud.com/compute-class operator: Exists - key: name operator: In values: - hello-avpa # A reserved switch to disable AVPA for certain pods. - key: alibabacloud.com/disable-avpa operator: DoesNotExistUnlike
scaleTargetRefthat takes effect only on one workload, theselectorcan select any pods to meet scaling requirements in different scenarios.Parameter
Required
Description
selector
No
The
selectorandscaleTargetRefare mutually exclusive. Theselectorcan simplify the AVPA configuration to centrally manage pods created by a type of workload. This saves you the need to configure AVPA for each workload.metrics.containerResource
Yes
Specify the type and utilization threshold of the resource whose metrics are collected:
container: the name of the container from which metrics are collected.
NoteYou can enter a wildcard character (
*) to match all containers.If a container matches both the wildcard expression and a specific container match rule, the container match rule prevails.
name: the name of the metric to collect. Only CPU metrics are supported.target: the threshold information.type: set toUtilization.averageUtilization: the average utilization threshold.
metrics.watermark
Yes
Specify the type of threshold. Valid values:
low: the low threshold. When the metric value drops below the threshold, pods are scaled in.high: the high threshold. When the metric value exceeds the threshold, pods are scaled out.
metrics.type
Yes
Specify the metric collection granularity. You can aggregate metrics by container or pod. The default is
ContainerResource.NoteCurrently, you can collect and aggregate metrics by container.
scaleResourceLimit.minimum
No
The lower limit of vertical scaling (for
cpuonly).cpu: The default is 250m (millicores).
scaleResourceLimit.maximum
No
The upper limit of vertical scaling (for
cpuonly).cpu: The default is 64 (cores).
Container resource utilization calculation rules:
For serverless pods, such as ACK serverless pods, resource specifications are provisioned based on resource limits. Therefore, utilization is first calculated based on the limit:
. If a limit is not set, the calculation is based on the requested resources: . Calculating container metrics is not supported if neither the request nor the limit is set. For example, if a container declaration causes ACS to create a pod with 4 vCPUs and 4 GiB, and PodMetrics reports a CPU usage of 1000m, the CPU utilization is
... spec: containers: - resources: limits: cpu: '4' memory: '4Gi' requests: cpu: '1' memory: '4Gi' -
You can create an AVPA configuration with more fine-grained control over the scaling behavior, such as the scaling step.
apiVersion: autoscaling.alibabacloud.com/v1beta1 kind: AdvancedVerticalPodAutoscaler metadata: name: hello-avpa namespace: default spec: behavior: parallelism: 1 stabilizationWindowSeconds: 600 scaleDown: #Defines the resource step and policy for scaling down. A gradual decrease is generally recommended, but each scale-down must be large enough to exceed the normalization granularity. policies: - type: CpuPercent value: 10% periodSeconds: 60 - type: Cpus value: 500m periodSeconds: 60 selectPolicy: Max scaleUp: #Defines the resource step and policy for scaling up. A relatively steep increase is generally recommended to meet load growth with fewer scaling events. policies: - type: CpuPercent value: 60% periodSeconds: 60 - type: Cpus value: 500m periodSeconds: 60 selectPolicy: Max metricObserveWindowSeconds: 600 metrics: - containerResource: container: hello-avpa name: cpu target: averageUtilization: 30 type: Utilization type: ContainerResource watermark: low - containerResource: container: hello-avpa name: cpu target: averageUtilization: 50 type: Utilization type: ContainerResource watermark: high scaleResourceLimit: maximum: cpu: '4' minimum: cpu: '1' scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: hello-avpaIn the
spec.behaviorparameter,scaleDownandscaleUpdescribe the resource policies for scaling down and scaling up, respectively. The sub-parameters that they contain have the same semantics.Parameter
Required
Description
policies[].type
No
-
Cpus: The absolute value of the CPU scaling step. -
CpuPercent: Specifies the CPU scaling step as a percentage of the current resource specifications.
policies[].value
No
-
Use this configuration when
typeis set toCpus. The value can be set to250m,1, etc. -
Use this configuration when
typeis set toCpuPercent. The value can be a percentage, such as5%.
selectPolicy
No
The calculation policy. Valid values are:
-
Max: Uses the maximum value as the target step size when multiple policies are set. -
Min: When multiple policies are set, the minimum value is used as the target step size.
metricObserveWindowSeconds
No
The time window for data collection. When the collected metrics span this time window, the system calculates the load and determines whether to perform scaling. The unit is seconds. The default value is
600seconds, and the minimum value is300seconds.behavior.parallelism
No
The parallelism for scaling, which is the number of Pods scaled simultaneously, with a default value of
1.behavior.stabilizationWindowSeconds
No
The cooldown period for scaling is specified in seconds, with a default value of
600and a minimum value of300. You must also ensure that the cooldown period is not shorter than the data collection window timemetricObserveWindowSeconds.When scaling is required, AVPA uses a default policy to calculate the target resource specifications. It calculates the scaling step for scaling up or down by using the average of
highWaterMarkandlowWaterMarkas the target load level. For example, for a1 vCPUcontainer, if the high and low thresholds are set to60and40respectively and the current utilization is100%, the target utilization is50%. The expected scale-up step is1 vCPU, scaling the container up to2 vCPU.Based on the configuration in the preceding YAML file, the system scales up in increments of 600m, which is the maximum value of
and 500m. NoteRecommended configuration: Scale up rapidly and scale down gradually. This allows you to quickly meet increasing load demands while maintaining stability by slowly releasing resources.
scaleUp: Scales up in relatively large increments to meet workload requirements with fewer scaling activities. For example, use
type: Cpusandvalue: 1.scaleDown: Gradually scales down resources in small increments as the load decreases to improve stability. For example,
type: Cpus,value: 250m. -
Deploy the YAML file.
kubectl apply -f avpa.yaml
Step 5: Perform stress testing
Send requests to the backend pod through the traffic Ingress to generate CPU loads. Observe the workload monitoring data before and after AVPA is enabled based on the same resource specifications and loads.
-
Send requests to generate loads.
The current test pod has a CPU resource specification of
2 vCPU. Initially, the load is increased to about 50%, consuming 1000 millicores, and is maintained for 2000 s. After that, the load is increased by an additional 100 millicores every 60 s, eventually reaching 4000 millicores after 30 minutes.# Increase the loads. The upper limit of each command is 1,000 millicores. curl --data "millicores=1000&durationSec=2000" http://localhost:28080/ConsumeCPU curl --data "millicores=1000&durationSec=2000" http://localhost:28081/ConsumeCPU # Continuously increase the loads. for i in {1..30} do sleep 60 curl --data "millicores=100&durationSec=2000" http://localhost:28080/ConsumeCPU curl --data "millicores=100&durationSec=2000" http://localhost:28081/ConsumeCPU done -
Monitor the metric data.
In the left-side navigation pane, click . On the tab, view the monitoring data.
The CPU loads continuously increase and then reach the threshold. After 10 minutes, CPU resources are scaled out to
2 vCPUs. After 30 minutes, CPU resources are scaled out to4 vCPUs. After the scale-out, the CPU loads significantly drop.
Monitor the loads of the shadow workload. The CPU resources are exhausted within a short period of time.

-
View pod events.
The pod events show configuration changes in the YAML template during scaling.
On the Events tab, select the Pod sub-tab. You can see events related to vertical scaling, including
StartingVerticalScalingPod,InplaceResizing,InplaceResizedFinished, andFinishedVerticalScalingPod. The events show the CPU request scaling up from 2 to 3,200m, 3,500m, and finally 4. The entire in-place adjustment process takes about 34 to 36 seconds. Simulate scale-in activities due to low loads.
After the CPU loads drop below the threshold, CPU resources are scaled in.
After the loads reach the scale-in threshold, CPU resources are scaled in at the specified step to ensure stability.
The container resources will be scaled to the minimum specification
1 vCPUclaimed in the AVPA configuration if the loads consistently remain at a low level.

(Optional) Step 6: Delete resources
Delete the workloads, Service, and AVPA resource.
kubectl delete -f hello-avpa.yaml kubectl delete -f shadow-hello-avpa.yaml-
In the left-side navigation pane, choose Applications > Helm. Find the row containing ack-advanced-vertical-pod-autoscaler and click Delete in the Actions column.
FAQ
How do I view the status of AVPA?
Use kubectl to query the real-time status of AVPA.
# In this example, the cluster connection information is stored in the ~/.kube/acs-test file.
# export KUBECONFIG=~/.kube/acs-test
kubectl get avpa -n [namespace] [-oyaml]Expected output:
$ kubectl get avpa
NAME TARGETTYPE TARGETNAME REPLICAS UPDATING WAITING LASTSCALED AGE
hello-avpa 1 0 0 11d 11dHow do I query pods are being scaled?
In AVPA versions later than 0.3.0, pods that are being scaled have the avpa.alibabacloud.com/resizing-lock label.
kubectl get po -n [ns] -lavpa.alibabacloud.com/resizing-lockHow do I query pods that encounter scaling failures?
In AVPA versions later than 0.3.0, scaling failures are recorded in Kubernetes events. You can query scaling failures in the Logstore by specifying the InplaceResizedTimeoutFailed keyword.
You can create alert rules for these events. For more information, see Create alert rules.