Kubernetes Metrics Server: The Engine for Autoscaling
Metrics Server is the dedicated speedometer for your cluster's pods, feeding CPU and memory usage to Kubernetes's autoscalers. It powers the Horizontal and Vertical Pod Autoscalers and the `kubectl top` command. The footgun: it's *only* for autoscaling.
WHY IT EXISTS Kubernetes needs a simple, efficient way to know how much CPU and memory pods are using to make automatic scaling decisions. Without a standardized, lightweight source of metrics, core features like the Horizontal Pod Autoscaler would be complex and resource-intensive to implement.
THE MENTAL MODEL Think of the Metrics Server as the speedometer and fuel gauge for your Kubernetes cluster, but only for the driver (the autoscaler). It provides just enough real-time information—CPU and memory usage—for the Horizontal and Vertical Pod Autoscalers to decide whether to add or remove pods. It is not the full diagnostic dashboard you'd show to a mechanic (like Prometheus); it's a specialized, internal tool.
HOW IT WORKS Metrics Server runs as a single, cluster-wide deployment. It periodically scrapes resource usage metrics from the Kubelet on every node, which already gathers this data from the running containers. The Metrics Server aggregates this data and exposes it through a dedicated Kubernetes API called the Metrics API (metrics.k8s.io). This API is then consumed by other Kubernetes components. The data collection is fast and efficient, typically happening every 15 seconds.
WHEN TO USE IT Use Metrics Server as the data source for core Kubernetes autoscaling features. This is its primary and intended function. It's the standard component for enabling the Horizontal Pod Autoscaler (HPA) to scale pods based on CPU or memory consumption. It's also used by the Vertical Pod Autoscaler (VPA) to recommend or apply resource requests and limits. Finally, it's what makes the kubectl top node and kubectl top pod commands work.
WHEN NOT TO USE IT Do not use Metrics Server as a general-purpose monitoring system or to feed metrics into one, like Prometheus or Datadog. It is explicitly not designed for this. It holds minimal historical data and lacks the rich metadata and query capabilities of a full monitoring solution. For robust monitoring and alerting, collect metrics directly from the Kubelet's /metrics/resource endpoint or use a more comprehensive tool.
ONE CANONICAL EXAMPLE You have a web application and want it to scale out when CPU usage gets high. You create a HorizontalPodAutoscaler object targeting your deployment, specifying a target average CPU utilization of 80%. The HPA controller queries the Metrics Server to get the current CPU usage for your app's pods. If the average exceeds 80%, the HPA instructs the ReplicaSet to create more pods. The Metrics Server is the essential data source that makes this entire loop possible.
Read the original → github.com
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.