Metrics Server — Lightweight Core Metrics for Kubernetes Autoscaling
Kubernetes Metrics Server is the lightweight cluster-wide CPU and memory metrics pipeline that powers kubectl top, HorizontalPodAutoscaler, and VerticalPodAutoscaler without requiring a full monitoring stack.
Agent 可直接安装
这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。
npx -y tokrepo@latest install 362bc634-3929-11f1-9bc6-00163e2b0d79 --target codex先 dry-run 确认安装计划,再运行此命令。
What it is
Kubernetes Metrics Server is a lightweight, cluster-wide aggregator of resource usage data. It collects CPU and memory metrics from kubelets and exposes them through the Kubernetes Metrics API. This API powers kubectl top, HorizontalPodAutoscaler (HPA), and VerticalPodAutoscaler (VPA) without requiring a full monitoring stack.
The tool targets cluster operators who need autoscaling and basic resource visibility without deploying Prometheus, Grafana, or other heavyweight monitoring solutions.
How it saves time or tokens
Metrics Server is a single deployment that replaces the need to configure a full monitoring pipeline just for autoscaling. Without it, kubectl top returns nothing and HPA cannot make scaling decisions. Installing it takes one command and provides immediate visibility into pod and node resource consumption. It stores only the latest data point in memory, so it adds minimal overhead to the cluster.
How to use
- Install Metrics Server with a single command:
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
- For development clusters with self-signed kubelet certificates:
kubectl patch deployment metrics-server -n kube-system \
--type='json' \
-p='[{"op": "add", "path": "/spec/template/spec/containers/0/args/-", "value": "--kubelet-insecure-tls"}]'
- Verify metrics are available:
kubectl top nodes
kubectl top pods -A
Example
# HPA that uses Metrics Server data
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: web-app-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: web-app
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 80
Related on TokRepo
- DevOps tools directory -- Kubernetes management and infrastructure tools
- Monitoring tools -- Full observability stacks and metrics platforms
Common pitfalls
- On minikube and kind clusters, kubelet certificates are self-signed; Metrics Server fails to scrape without the
--kubelet-insecure-tlsflag - Metrics Server only stores the latest data point; it is not a replacement for Prometheus or other time-series databases for historical analysis
- HPA requires resource requests to be set on containers; without them, utilization percentages cannot be calculated and autoscaling silently fails
常见问题
No. Metrics Server provides only current CPU and memory data for autoscaling. It does not store historical data, support custom metrics, or provide alerting. Use Prometheus or similar for full monitoring. Metrics Server and Prometheus can run side by side.
This happens when Metrics Server is not installed or cannot scrape kubelets. Install Metrics Server and check its logs for TLS errors. On development clusters, add the --kubelet-insecure-tls flag to bypass certificate validation.
Metrics Server is designed to be lightweight. It stores only the latest data point in memory, not a time series. For a 100-node cluster, it typically uses less than 100MB of memory and minimal CPU. It scrapes kubelets every 15 seconds by default.
No. Metrics Server only provides CPU and memory resource metrics. For custom application metrics in HPA, use the custom metrics API backed by Prometheus Adapter, Datadog Cluster Agent, or similar custom metrics providers.
Yes. VerticalPodAutoscaler relies on the Metrics API to observe actual resource usage and recommend or apply resource request adjustments. Without Metrics Server or an equivalent provider, VPA cannot function.
引用来源 (3)
- Metrics Server GitHub— Metrics Server is the default metrics pipeline for Kubernetes autoscaling
- Kubernetes Metrics Server Docs— Powers HPA, VPA, and kubectl top
- Kubernetes Metrics API— Scrapes kubelet summary API for CPU and memory metrics
讨论
相关资产
kube-state-metrics — Kubernetes Cluster State Metrics Exporter
kube-state-metrics is a Kubernetes add-on that listens to the API server and generates Prometheus metrics about the state of Kubernetes objects like deployments, nodes, and pods.
Beszel — Lightweight Self-Hosted Server Monitoring
Beszel is a lightweight server monitoring platform with historical data, Docker container stats, and configurable alerts. It uses a hub-agent architecture with minimal resource overhead and a clean, modern dashboard.
Vaultwarden — Lightweight Self-Hosted Bitwarden Server
Vaultwarden is an unofficial Bitwarden-compatible server written in Rust. Full Bitwarden features with minimal resources — perfect for self-hosted password management.
Fluent Bit — Lightweight High-Performance Log and Metrics Processor
Fluent Bit is a fast, lightweight telemetry agent from the Fluentd family. It collects logs, metrics and traces from any source, processes them with filters, and forwards them to dozens of backends.