VPA (Vertical Pod Autoscaler)
https://kubernetes.io/docs/concepts/workloads/autoscaling/vertical-pod-autoscale/
In Kubernetes, a VerticalPodAutoscaler automatically updates a workload management resource (such as a Deployment or StatefulSet), with the aim of automatically adjusting infrastructure resource requests and limits to match actual usage.
Vertical scaling means that the response to increased resource demand is to assign more resources (for example: memory or CPU) to the Pods that are already running for the workload. This is also known as rightsizing, or sometimes autopilot. This is different from horizontal scaling, which for Kubernetes would mean deploying more Pods to distribute the load.
If the resource usage decreases, and the Pod resource requests are above optimal levels, the VerticalPodAutoscaler instructs the workload resource (the Deployment, StatefulSet, or other similar resource) to adjust resource requests back down, preventing resource waste.
The VerticalPodAutoscaler is implemented as a Kubernetes API resource and a controller. The resource determines the behavior of the controller. The vertical pod autoscaling controller, running within the Kubernetes data plane, periodically adjusts the resource requests and limits of its target (for example, a Deployment) based on analysis of historical resource utilization, the amount of resources available in the cluster, and real-time events such as out-of-memory (OOM) conditions.
Components
- The VPA is a CRD in Kubernetes and must be installed
- VPA consists of multiple components:
- VPA Recommender - analyzes resource usage and recommends updates
- VPA Updater - evicts or updates pods in place
- VPA Admission Controller - applies resource recommendations to new or recreated Pods
Update modes
- A VerticalPodAutoscaler supports different update modes that control how and when resource recommendations are applied to your Pods. You configure the update mode using the updateMode field in the VPA spec under updatePolicy:
---
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
name: my-app-vpa
spec:
targetRef:
apiVersion: "apps/v1"
kind: Deployment
name: my-app
updatePolicy:
updateMode: "Recreate" # Off, Initial, Recreate, InPlaceOrRecreate, InPlace
Installation
Clone the VPA Repository and Set Up the Vertical Pod Autoscaler
You are required to clone the Kubernetes Autoscaler repository into the /root directory and set up the Vertical Pod Autoscaler (VPA) by running the provided script.
Steps:
-
Clone the repository: First, navigate to the /root directory and clone the repository:
git clone https://github.com/kubernetes/autoscaler.gitgit clone https://github.com/kubernetes/autoscaler.gitNavigate to the Vertical Pod Autoscaler directory: -
After cloning, move into the vertical-pod-autoscaler directory:
cd autoscaler/vertical-pod-autoscaler -
Run the setup script: Execute the provided script to deploy the Vertical Pod Autoscaler:
./hack/vpa-up.sh