Feedback

Chat Icon

Cloud-Native Microservices With Kubernetes - 2nd Edition

A Comprehensive Guide to Building, Scaling, Deploying, Observing, and Managing Highly-Available Microservices in Kubernetes

Autoscaling Microservices in Kubernetes: Horizontal Autoscaling
50%

Horizontal Pod Autoscaler

The Metrics Server

Instead of manually scaling the number of replicas, Kubernetes can be used to achieve automated scaling. Known as Horizontal Pod Autoscaling (HPA), this feature scales your Pods up or down based on metrics using the HPA controller.

To leverage the HPA, Kubernetes needs Metrics Server. This tool is responsible for aggregating resource usage data across the cluster. It collects metrics from various resources and exposes them through the Kubernetes API Server via the metrics.k8s.io API. No Metrics Server means no HPA and no VPA (as we're going to see in the next chapter).

There are different ways to install the Metrics Server in your cluster, including:

Using YAML (which we are going to use):

kubectl apply -f \
https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml

Using Helm:

helm repo add metrics-server \
  https://kubernetes-sigs.github.io/metrics-server/

helm repo update

helm install metrics-server metrics-server/metrics-server

Using a cloud provider-specific method:

For example, using the DigitalOcean Marketplace. If you are using a different cloud provider, you may use the option provided by that cloud provider. Not all cloud providers offer this option.


We are going to use the first option. You need to check the compatibility matrix to make sure you are installing a version compatible with your Kubernetes cluster version.

Metrics ServerMetrics API group/versionSupported Kubernetes version
0.8.xmetrics.k8s.io/v1beta11.31+
0.7.xmetrics.k8s.io/v1beta1

Cloud-Native Microservices With Kubernetes - 2nd Edition

A Comprehensive Guide to Building, Scaling, Deploying, Observing, and Managing Highly-Available Microservices in Kubernetes

Enroll now to unlock all content and receive all future updates for free.