Difficulty: Intermediate
What is the Metrics Server in Kubernetes, how does it collect data, and what depends on it?
Metrics Server is a lightweight cluster add-on that collects current CPU and memory usage for nodes and Pods from every kubelet and exposes it through the Kubernetes API as metrics.k8s.io. kubectl top, the Horizontal Pod Autoscaler's resource metrics and the Vertical Pod Autoscaler's recommender all read from it. It is not a monitoring system: it keeps only the latest values in memory and stores no history.
/metrics/resource endpoint, gathered from the container runtime and cgroups.--metric-resolution).APIService for v1beta1.metrics.k8s.io, so the API server's aggregation layer forwards requests for that group to Metrics Server.kubectl top call the API server, which proxies to Metrics Server.Because it is served through the normal API, access is controlled by RBAC like any other resource.
<unknown>/70% and events like failed to get cpu utilization: unable to get metrics for resource cpu.kubectl top nodes and kubectl top pods: fail with error: Metrics API not available.Managed clusters such as GKE and AKS install it by default. On EKS it is available as an add-on, and on kind or kubeadm you install it yourself.
| Metrics Server | Prometheus | |
|---|---|---|
| Data | CPU and memory only | Any metric, including app metrics |
| Retention | Latest value, in memory | Time series stored on disk |
| API | metrics.k8s.io | PromQL |
| Purpose | Autoscaling and kubectl top | Monitoring, alerting, dashboards |
For autoscaling on custom metrics such as requests per second or Kafka lag, you need a different API: custom.metrics.k8s.io or external.metrics.k8s.io, typically served by Prometheus Adapter or KEDA.
--kubelet-insecure-tls; in production, use properly signed kubelet serving certs instead.# Install the latest release
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
# Is the aggregated API registered and available?
kubectl get apiservice v1beta1.metrics.k8s.io
# Raw API call (what kubectl top does under the hood)
kubectl get --raw /apis/metrics.k8s.io/v1beta1/nodes | head -c 400
# Consumers
kubectl top nodes
kubectl get hpa
If the APIService shows `AVAILABLE False`, check the metrics-server Pod logs for kubelet scrape or TLS errors before debugging the HPA itself.
Metrics Server, metrics.k8s.io, Aggregation Layer, kubelet resource metrics, HPA