Skills2026年4月16日·1 分钟阅读

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 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Metrics Server for K8s autoscaling
直接安装命令
npx -y tokrepo@latest install 362bc634-3929-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

TL;DR
Metrics Server feeds CPU and memory data to kubectl top, HPA, and VPA as the minimal Kubernetes metrics pipeline.
§01

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.

§02

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.

§03

How to use

  1. Install Metrics Server with a single command:
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
  1. 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"}]'
  1. Verify metrics are available:
kubectl top nodes
kubectl top pods -A
§04

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
§05

Related on TokRepo

§06

Common pitfalls

  • On minikube and kind clusters, kubelet certificates are self-signed; Metrics Server fails to scrape without the --kubelet-insecure-tls flag
  • 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

常见问题

Does Metrics Server replace Prometheus?+

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.

Why does kubectl top show 'metrics not available'?+

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.

How much overhead does Metrics Server add?+

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.

Can I use Metrics Server for custom application metrics?+

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.

Is Metrics Server required for VPA?+

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)

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产