Horizontal Pod autoscaling
A HorizontalPodAutoscaler automatically changes the number of replicas of a workload to match demand.
A HorizontalPodAutoscaler (HPA) automatically changes the number of replicas of a workload, such as a Deployment or StatefulSet, to match demand. When the load rises, the HPA adds Pods. When the load falls and the number of Pods is above the minimum, the HPA removes Pods. The HPA is separate from the cluster autoscaler of Cloudera Cloud Factory: the HPA changes the number of Pods, and the cluster autoscaler changes the number of nodes that the Pods need.
The HPA runs as a control loop. In each cycle, it reads a metric and calculates the number of replicas with the following formula: desiredReplicas = ceil[currentReplicas * (currentMetricValue / desiredMetricValue)]. Resource metrics come from the metrics.k8s.io API, which Metrics Server provides. Custom and external metrics come from the custom.metrics.k8s.io and external.metrics.k8s.io APIs. The stable API version is autoscaling/v2.
The HPA does not apply to DaemonSets. To scale on CPU or memory utilization, set resource requests on the containers of the workload. Cloudera recommends that you remove the spec.replicas field from the manifest when you enable an HPA, so that a redeployment does not reset the replica count.
To scale on the usage of one container instead of the whole Pod, use a ContainerResource metric. This metric type is beta in Kubernetes 1.27. The following example scales on the CPU utilization of the container named application.
metrics:
- type: ContainerResource
containerResource:
name: cpu
container: application
target:
type: Utilization
averageUtilization: 60Key defaults and limits
- The control loop runs every 15 seconds. The
--horizontal-pod-autoscaler-sync-periodflag of the controller manager changes the interval. - The HPA skips a change when the ratio of current to desired metric is within a tolerance of 0.1.
- Scale-down uses a stabilization window of 300 seconds.
- By default, scale-down can remove 100 percent of the Pods in 15 seconds. Scale-up can add 100 percent of the Pods or 4 Pods in 15 seconds, whichever is larger.
- The maximum value of
periodSecondsin a scaling policy is 1800.
For more information, see Horizontal Pod Autoscaling.
