Service Configuration
medium

Questão de Service Configuration #019e3a4f

Enunciado da Questão
Service Configuration
#kubernetes
#horizontal-pod-autoscaler
#autoscaling
#hpa
Médio

How does Horizontal Pod autoscaling work in Kubernetes?

A

The Horizontal Pod Autoscaler controller adds more CPU or memory to the pods when the load is above the configured threshold, and reduces CPU or memory when the load is below.

B

The Horizontal Pod Autoscaler controller adds more pods when the load is above the configured threshold, but does not reduce the number of pods when the load is below.

C

The Horizontal Pod Autoscaler controller adds more pods to the specified DaemonSet when the load is above the configured threshold, and reduces the number of pods when the load is below.

D

The Horizontal Pod Autoscaler controller adds more pods when the load is above the configured threshold, and reduces the number of pods when the load is below.

Correta

Explicação Oficial / Explicações da Comunidade

The Horizontal Pod Autoscaler (HPA) automatically scales the number of pods in a replication controller, deployment, replica set, or stateful set based on observed CPU utilization (or, with custom metrics, based on other application-provided metrics). The HPA controller periodically adjusts the desired replica count to match the observed metric value to the user-specified target.

How it Works
The HPA is implemented as a Kubernetes API resource and a controller. The controller queries the metrics server (or custom metrics API) for the current resource usage of the pods, calculates the desired number of replicas using the formula:

desiredReplicas = ceil[currentReplicas * (currentMetricValue / desiredMetricValue)]

It then updates the scale subresource of the target workload (e.g., Deployment) to the new replica count. The scaling is performed in a loop with a configurable sync period (default 15 seconds). The HPA can scale both up and down, with configurable stabilization windows to prevent thrashing.

Why the correct answer is right
The correct answer states that the HPA adds more pods when the load is above the threshold and reduces the number of pods when the load is below. This accurately describes the core behavior: the HPA adjusts the replica count in both directions based on observed metrics relative to the target.

Why the incorrect answers are wrong

  • The option claiming the HPA adds more CPU or memory to the pods is incorrect because the HPA scales the number of pods, not the resources allocated to existing pods. Resource requests/limits are set at pod creation and cannot be changed by the HPA.
  • The option stating the HPA adds more pods but does not reduce them is incorrect because the HPA is designed to scale down as well as up, unless explicitly configured with a minimum replica count or scaling policies that prevent downscaling.
  • The option specifying that the HPA adds more pods to a DaemonSet is incorrect because DaemonSets are not scalable by the HPA; the HPA works with scalable resources like Deployments, ReplicaSets, and StatefulSets. DaemonSets run one pod per node and are not intended for horizontal scaling based on load.