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.
Interview question
What is the primary function of the Kubernetes Metrics Server?
- a.To collect and forward application-specific custom metrics to external monitoring systems like Prometheus.
- b.To provide a comprehensive monitoring solution for all cluster resources, including network I/O and disk usage.
- c.To enable Horizontal and Vertical Pod Autoscalers by supplying real-time CPU and memory usage data.Correct
- d.To store historical performance metrics for long-term analysis and capacity planning.
Why? this is the answer
The Metrics Server is a specialized tool designed to provide real-time CPU and memory usage data specifically for Kubernetes autoscalers (HPA, VPA) and the kubectl top command. It is not intended for general-purpose monitoring or for storing historical data, as it holds minimal historical information.
Just read this? Test yourself on what you have been reading.
Read the original → github.com
- #kubernetes
- #autoscaling
- #monitoring
- #hpa
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on kubernetes — each one lists the topics its interview covers.
See open roles