Kubernetes Cluster Autoscaler
Dynamically scales a Kubernetes cluster to match workload needs, optimizing resource utilization and performance.
Overview
The Cluster Autoscaler works by continuously monitoring the cluster for two main conditions:
- Unschedulable pods due to insufficient resources
- Underutilized nodes for an extended period
When it detects unschedulable pods, it scales up the cluster by adding nodes to accommodate the workload. Conversely, when it identifies underutilized nodes, it scales down the cluster by removing them after migrating their pods to other nodes. This process helps optimize resource usage, improve performance, and reduce costs by ensuring the cluster maintains just enough capacity to handle current workloads without manual intervention
Setup
Option 1: Collect metrics via Prometheus scrape annotation
When deploying the Cluster Autoscaler, you can enable Prometheus metrics by adding the following annotations to the Cluster Autoscaler Helm chart.
...
podAnnotations:
prometheus.io/path: /metrics
prometheus.io/port: "8085"
prometheus.io/scrape: "true"
...For more details see cluster-autoscaler Helm chart .
Option 2: Collect metrics via Prometheus scrape configuration
If you are using Prometheus to scrape metrics from your Kubernetes cluster, you can configure Prometheus to scrape the cluster autoscaler metrics by adding the following configuration to your Prometheus configuration file.
You need to verify that the pod labels in the scrape configuration match the name of the cluster-autoscaler pod.
...
- job_name: 'cluster-autoscaler'
kubernetes_sd_configs:
- role: pod
relabel_configs:
- source_labels: [__meta_kubernetes_pod_label_app]
regex: cluster-autoscaler
action: keep
- source_labels: [__meta_kubernetes_pod_container_port_number]
regex: '8085'
action: keep
...