Prepare and test your skills

Prepare and test your skills

Horizontal Pod Autoscaler (HPA) (opens in a new tab) is a Kubernetes controller in Google Kubernetes Engine (GKE) that automatically changes the number of Pod replicas in a workload based on demand. Each HPA is attached to one workload, such as a Deployment, which runs multiple copies of Pods across cluster nodes. The HPA definition sets a minimum replica count, a maximum replica count, and one or more target utilization thresholds, so the workload stays available during traffic spikes and scales down to save cost when demand drops.
The difference between HPA and cluster autoscaling is what each controller scales and why it scales. HPA changes the shape of a workload by adding or removing Pods, while the cluster autoscaler (opens in a new tab) changes the size of the infrastructure by adding or removing nodes in a node pool. Data flows from workload metrics to the HPA controller, and the HPA controller then adds or removes Pods. Only after Pods become unschedulable or nodes become underutilized does the cluster autoscaler add or remove virtual machine nodes.
HPA and the cluster autoscaler can work together in a fixed order:
| Autoscaler | What it scales | Scaling trigger |
|---|---|---|
| Horizontal Pod Autoscaler (HPA) | Number of Pods in a workload | Pod CPU or memory use, custom metrics, or external metrics compared to a target |
| Cluster autoscaler | Number of nodes in a node pool | Unschedulable Pods that need more capacity, or underutilized nodes that can be removed |
More Pods from HPA scale-out can create the unschedulable Pods that cause the cluster autoscaler to add nodes. Choose HPA when the problem is handling more requests with more Pod copies, and choose the cluster autoscaler when the problem is lack of node capacity to place those Pods.
Metrics that trigger HPA scaling are the signals that an HPA control loop checks against its configured targets. A separate HPA control loop exists for each workload, and each loop only manages the workload it is attached to. When current use is above target, the HPA adds replicas, and when use stays below target, the HPA removes replicas.
The HPA can scale on three types of metrics:
Per-Pod resource calculation is how the HPA controller turns container measurements into a scaling decision for CPU and memory. For per-Pod resources such as CPU, the controller queries the resource metrics API for each container running in the Pod. If the target is a raw value, that value is used directly, and if the target is a percentage, the HPA calculates average utilization as a percentage of that Pod's CPU or memory requests.
Exam tip: Percentage-based CPU or memory targets only work when every container in each Pod of the workload defines a request for that resource.
Minimum, maximum, and target settings are the boundaries that control how far an HPA is allowed to scale. The minimum replica count keeps enough Pods running to handle baseline traffic and tolerate disruption, while the maximum replica count caps cost and prevents unbounded scale-out. The target utilization threshold, such as 70% of requested CPU, is the level the HPA tries to maintain by adding Pods when average use rises above it and removing Pods when average use stays below it.
An HPA object is a Kubernetes API object created from a YAML manifest and applied to the cluster to manage one workload. The manifest identifies the target Deployment and sets minReplicas and maxReplicas bounds plus the metric targets to maintain. Configuring horizontal Pod autoscaling (opens in a new tab) with the Google Cloud console uses autoscaling/v2, while kubectl can specify autoscaling/v1, which supports only CPU utilization, or autoscaling/v2, which is recommended for memory, custom metrics, external metrics, and multiple metrics at once.
Vertical Pod Autoscaling (VPA) (opens in a new tab) in Google Kubernetes Engine (GKE) is an autoscaler that analyzes historical CPU and memory usage and sets the right resource requests for containers. Unlike horizontal scaling, which adds or removes Pod replicas, VPA changes the size of existing Pods by increasing or decreasing their CPU and memory requests. VPA is enabled by default in Autopilot clusters and must be enabled in Standard clusters before use.
Vertical Pod Autoscaling works by observing how containers actually use CPU and memory over time and then generating a recommendation for resource requests. The VPA recommender calculates target, lower-bound, and upper-bound values, and the VPA controller either stores those values for review or applies them to Pods automatically. This process removes the need for manual benchmarking and helps Pods use what they need, which improves stability and reduces waste.
VPA is designed for long-running, homogenous workloads where the correct container size is unknown. If requests are too small, containers can be throttled or fail with out-of-memory errors, and if requests are too large, nodes are wasted and costs increase. VPA notifies the cluster autoscaler before resizing so cluster capacity can be adjusted, and it schedules resized Pods onto nodes that have appropriate resources available. VPA requires a workload controller, such as a Deployment, StatefulSet, ReplicaSet, or ReplicationController, because VPA cannot be used with standalone Pods that have no controller to re-create the Pod when requests change.
Update modes for VPA control when recommendations are applied and whether running Pods are disrupted. The mode is set in the spec.updatePolicy.updateMode field of the VerticalPodAutoscaler object, and Auto is the default if no mode is specified.
| Mode | What VPA does | Impact on Pod lifecycle |
|---|---|---|
| Off | Calculates recommendations only and stores them in the status field; never changes Pods automatically | No disruption; administrator reviews recommendations and applies them manually |
| Initial | Assigns resource requests only when a Pod is created; never changes running Pods later | Disruption only at creation; running Pods keep their original size |
| Auto, also called Recreate | Updates CPU and memory requests during the life of a Pod by evicting the Pod and letting its controller re-create it | Causes Pod re-creation; use a Pod disruption budget and cluster autoscaler to limit disruption time |
The best practice is to start in Off mode, also called recommendation mode, and collect data for at least 24 hours and ideally one week or more before switching to Initial or Auto. Do not use Initial or Auto for workloads that must handle sudden traffic spikes, because eviction and re-creation add delay when fast scale-out is needed.
Exam tip: Off never changes Pods, Initial changes Pods only at creation, and Auto evicts and re-creates running Pods to apply new requests.
Implementing VPA means enabling the feature, linking a VerticalPodAutoscaler object to a workload, and then reviewing or applying recommendations. Enabling or applying VPA changes can re-create Pods, so plan for brief workload disruption. Scale container resource requests and limits (opens in a new tab) follows a fixed workflow:
targetRef points to the workload, such as a Deployment, and set updateMode to Off, Initial, or Auto.recommendation.containerRecommendations field with kubectl get vpa, the Workloads page in the console, or Cloud Monitoring metrics for recommended request bytes and cores.Off or Initial workflows, manually set requests.cpu and requests.memory in the Deployment manifest or console; in Auto mode, VPA applies the new requests by re-creating Pods.Manual settings should follow container best practices where memory request equals memory limit and CPU request is the minimum needed for correct operation with an unbounded CPU limit. Recommendations can be constrained with a ContainerResourcePolicy that sets minAllowed and maxAllowed bounds, selects controlledResources such as CPU only or memory only, or opts a specific sidecar container out with mode Off.
Scaling constraints and interoperability in Google Kubernetes Engine (GKE) describe the limits of combining Pod-level autoscalers and how Pod scaling connects to node scaling. Horizontal Pod Autoscaler (HPA) (opens in a new tab) changes the number of Pods in a workload, while the cluster autoscaler (opens in a new tab) changes the number of nodes in a node pool. The two layers work together only when resource requests are set correctly and conflicting controls are avoided.
Combining HPA and VPA means using one controller that adds or removes Pods and another controller that adjusts the CPU or memory allocated to each Pod. HPA operates in a control loop for each workload, periodically checking CPU consumption, memory consumption, custom metrics from inside Kubernetes, or external metrics from outside the cluster against configured targets. VPA adjusts the resource requests and limits that define each Pod's size, so running both autoscalers on the same CPU or memory metric creates a conflict where both controllers react to the same signal in different ways.
A combined configuration is supported with limitations, so the safe pattern is to separate their responsibilities by metric. Use HPA when the signal should change replica count, such as request rate, queue size from a system like Pub/Sub, or average CPU utilization as a percentage of Pod requests. Use VPA when the signal should change the Pod size itself, and avoid pointing both autoscalers at the same CPU or memory target for the same workload. To use percentage-based HPA targets, each container in each Pod must configure requests for that resource, because HPA calculates average utilization as a percentage of those requests.
The interaction between Pod autoscaling and the GKE cluster autoscaler connects workload demand to infrastructure capacity across a clear boundary. HPA manages Pods on one side of the boundary and never adds or removes nodes, while the cluster autoscaler manages nodes on the other side by adding or removing virtual machine (VM) instances in the underlying Compute Engine Managed Instance Group (MIG) for each node pool. The cluster autoscaler makes its decisions from Pod resource requests rather than actual CPU or memory utilization, so accurate requests are what link the two systems.
The two autoscalers differ in what they scale and what triggers them:
| Autoscaler | What it scales | Scaling trigger |
|---|---|---|
| Horizontal Pod Autoscaler (HPA) | Number of Pods in a workload | CPU or memory use, custom Kubernetes metrics, or external metrics versus target thresholds |
| Cluster autoscaler | Number of nodes in a Standard node pool, between a configured minimum and maximum | Unschedulable Pods that need capacity, or underutilized nodes whose Pods could fit on fewer nodes |
When HPA adds Pods faster than current nodes can fit them, traffic flows from the unschedulable Pods to a scale-up decision by the cluster autoscaler. Node creation then happens in parallel until enough capacity exists, up to the per-node-pool or per-cluster maximum, with the goal of moving unschedulable Pods to Active as quickly as possible.
A left-to-right process flow showing workload metrics triggering HPA to add Pods, then unschedulable Pods triggering the cluster autoscaler to add a node.
Optimizing node pool resources means letting the cluster autoscaler grow and shrink each pool within its configured minimum and maximum without manual intervention or competing autoscalers. The cluster autoscaler works per node pool and periodically checks Pod and node status, then takes action based on schedulability and utilization:
This behavior depends on explicit resource requests for every workload, because insufficient requests or defaults leave the cluster autoscaler with the wrong picture of needed capacity. Do not enable Compute Engine autoscaling on the MIGs that back GKE nodes, because that separate autoscaler conflicts with the GKE cluster autoscaler and pools can fail to scale. Design workloads with multiple replicas under a controller such as a Deployment so Pods can restart on another node during scale-down, and remember that inspection frequency varies with cluster size and can occur every few seconds in small clusters.
Exam tip: The cluster autoscaler scales on Pod resource requests, not actual resource utilization, so missing or too-small requests prevent correct scale-up and scale-down.
The Horizontal Pod Autoscaler (HPA) changes the number of Pod replicas in a workload based on CPU or memory use, custom metrics, or external metrics compared to a target, while the cluster autoscaler changes the number of nodes in a node pool based on unschedulable Pods that need capacity or underutilized nodes that can be removed. More Pods from HPA scale-out can create the unschedulable Pods that cause the cluster autoscaler to add nodes.
The Horizontal Pod Autoscaler (HPA) can scale on actual resource usage, custom metrics from inside the cluster, and external metrics from outside the cluster. Actual usage is Pod CPU or memory use as a raw value or as a percentage of the amount requested, custom metrics include signals such as client requests per second, and external metrics include signals such as the size of a Pub/Sub queue.
In Vertical Pod Autoscaling (VPA), Off calculates recommendations only and never changes Pods automatically, Initial assigns resource requests only when a Pod is created and never changes running Pods later, and Auto updates CPU and memory requests during the life of a Pod by evicting the Pod and letting its controller re-create it. The best practice is to start in Off mode and collect data for at least 24 hours and ideally one week or more before switching to Initial or Auto.
A combined configuration is supported with limitations, so the safe pattern is to separate their responsibilities by metric and avoid pointing both autoscalers at the same CPU or memory target for the same workload. Use the Horizontal Pod Autoscaler (HPA) when the signal should change replica count and use Vertical Pod Autoscaling (VPA) when the signal should change Pod size, because running both on the same metric creates a conflict where both controllers react to the same signal in different ways.
Your team deploys a stateless web application to Google Kubernetes Engine (GKE) as a Deployment named web-frontend.
You create a Horizontal Pod Autoscaler (HPA) configured to maintain an average target CPU utilization of 70%, with a minimum of 2 replicas and a maximum of 10 replicas. During load testing, traffic spikes significantly, but the HPA fails to scale out the Pod replicas and reports that it cannot calculate utilization.
What configuration change must you make to the Deployment manifest to enable the Horizontal Pod Autoscaler to work properly?
Last updated