Skip to content

HPA prerequisites and Metrics Server

To implement the Horizontal Pod Autoscaler (HPA) in a Kubernetes cluster, a mechanism for monitoring resource usage is strictly required. This mechanism is the Metrics Server^[400-devops__06-Kubernetes__k8s-ithelp__Day26__README.md].

Metrics Server

The Metrics Server is a cluster-wide aggregator of resource usage data. It is responsible for collecting metrics from the Pods and Nodes, which serve as the foundation for scaling decisions^[400-devops__06-Kubernetes__k8s-ithelp__Day26__README.md].

Verification

Before configuring HPA, it is crucial to verify that the Metrics Server is installed and functioning correctly. This can be done using the kubectl top node command^[400-devops__06-Kubernetes__k8s-ithelp__Day26__README.md].

kubectl top node

A successful output will display the current CPU and Memory usage for the nodes, confirming that the metrics pipeline is active^[400-devops__06-Kubernetes__k8s-ithelp__Day26__README.md].

HPA Configuration Prerequisites

Once the Metrics Server is operational, the HorizontalPodAutoscaler resource can be defined. The configuration relies on specific API versions and metric definitions^[400-devops__06-Kubernetes__k8s-ithelp__Day26__README.md].

API Version

To utilize standard resource metrics like memory in addition to CPU, the HPA resource must use apiVersion: autoscaling/v2^[400-devops__06-Kubernetes__k8s-ithelp__Day26__README.md].

Metric Sources

The HPA spec requires a metrics block to define the scaling logic^[400-devops__06-Kubernetes__k8s-ithelp__Day26__README.md]. Common sources include:

  • Resource: Refers to known Kubernetes resources like CPU or memory^[400-devops__06-Kubernetes__k8s-ithelp__Day26__README.md].
  • Pods: Metrics specific to the pods being scaled (e.g., packets-per-second)^[400-devops__06-Kubernetes__k8s-ithelp__Day26__README.md].
  • Object: Metrics from a specific Kubernetes object, such as an Ingress^[400-devops__06-Kubernetes__k8s-ithelp__Day26__README.md].
  • External: Metrics from outside the Kubernetes cluster, allowing for autoscaling based on external system data^[400-devops__06-Kubernetes__k8s-ithelp__Day26__README.md].

Sources

^[400-devops__06-Kubernetes__k8s-ithelp__Day26__README.md]