Kubernetes Horizontal Pod Autoscaler: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 25: Line 25:


Autoscaling can be performed for one metric or multiple metrics. If multiple metrics are involved, the controller computes the required number of pods for each metric, and picks the larger value.
Autoscaling can be performed for one metric or multiple metrics. If multiple metrics are involved, the controller computes the required number of pods for each metric, and picks the larger value.
For a specific metric, the goal of the algorithm is to compute the number of replicas that will bring the average value of the metric as close to the target value as possible. The input is a set of metrics, one for each pod, and the output is an integer, which represents the target number of pod replicas.


==<span id='HorizontalPodAutoscaler_Resource'></span>Horizontal Pod Autoscaler Resource==
==<span id='HorizontalPodAutoscaler_Resource'></span>Horizontal Pod Autoscaler Resource==

Revision as of 20:57, 9 October 2020

External

Internal

Overview

Horizontal pod autoscaling is the automatic increase or decrease the number of pod replicas managed by a higher level controller that supports scaling, such as deployments, replica sets and stateful sets.

How it Works

The scaling is performed by a horizontal pod controller and it is controlled by a HorizontalPodAutoscaler Kubernetes API resource, which enables and configures the horizontal pod autoscaler. For an horizontal pod autoscaler to work correctly, a source of metrics, in particular resource metrics, must be deployed. The simplest source of resource metrics is the metrics server.

The controller periodically reads the appropriate metrics API to obtain metrics for the pods it monitors. The set of pods to watch is provided by the higher level pod controller the autoscaler is associated with. The autoscaler calculates the number of replicas required to meet the target metric configured on the HorizontalPodAutoscaler resource, as described in the Autoscaling Algorithm section, below. If there is a mismatch, the controller adjusts the "replicas" field on the target pod controller. The target pod controller is not aware of the autoscaler. In what it is concerned, anybody, including the autoscaler, may update the replica count.

Metrics and Autoscaling.png

Horizontal Pod Autoscaler Controller

The horizontal pod autoscaler controller is part of the cluster's controller manager process.

Autoscaling Algorithm

Autoscaling can be performed for one metric or multiple metrics. If multiple metrics are involved, the controller computes the required number of pods for each metric, and picks the larger value.

For a specific metric, the goal of the algorithm is to compute the number of replicas that will bring the average value of the metric as close to the target value as possible. The input is a set of metrics, one for each pod, and the output is an integer, which represents the target number of pod replicas.

Horizontal Pod Autoscaler Resource

The HorizontalPodAutoscaler Kubernetes API resource is deployed as any other Kubernetes resource by posting a manifest to the API server.

HorizontalPodAutoscaler Manifest

HorizontalPodAutoscaler Manifest

Playground

https://github.com/ovidiuf/playground/tree/master/kubernetes/horizontal-pod-autoscaler

Operations