How to Deploy and Use Kubernetes Metrics Server for Cluster Monitoring
This guide compares node-exporter, metric-server, and kube-state-metrics, explains their different focuses, and provides step‑by‑step instructions to deploy metric‑server, verify its API, and use kubectl top to monitor node and pod resource usage in a Kubernetes cluster.
Comparison of Monitoring Tools
node-exporter collects server‑level metrics such as load average, filesystem usage, and memory information, similar to traditional host‑monitoring tools like Zabbix agent.
metric‑server (or heapster) retrieves CPU and memory usage metrics from the API server and forwards them to a storage backend (e.g., InfluxDB or a cloud provider), primarily to supply decision metrics for components like HPA.
kube‑state‑metrics focuses on exposing the current state of Kubernetes resources such as Deployments or DaemonSets.
Typical kube‑state‑metrics queries
How many Replicas are scheduled and how many are currently available?
How many Pods are in running, stopped, or terminated states?
How many times have Pods restarted?
How many Jobs are currently running?
These metrics are provided by kube‑state‑metrics. They are not included in metric‑server because the two components have fundamentally different goals.
metric‑server only fetches, formats, and writes existing data to a specific storage, essentially acting as a monitoring system.
kube‑state‑metrics snapshots Kubernetes status in memory and offers new metrics, but it cannot export them.
Deploying metric‑server
Download the deployment manifest:
wget https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.3.7/components.yamlPull the metric‑server image:
# docker pull zhaoqinchang/metrics-server:0.3.7
0.3.7: Pulling from zhaoqinchang/metrics-server
9ff2acc3204b: Pull complete
9d14b55ff9a0: Pull complete
Digest: sha256:c0efe772bb9e5c289db6cc4bc2002c268507d0226f2a3815f7213e00261c38e9
Status: Downloaded newer image for zhaoqinchang/metrics-server:0.3.7Edit components.yaml as shown (the essential parts are reproduced below):
# cat components.yaml
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: system:aggregated-metrics-reader
labels:
rbac.authorization.k8s.io/aggregate-to-view: "true"
rbac.authorization.k8s.io/aggregate-to-edit: "true"
rbac.authorization.k8s.io/aggregate-to-admin: "true"
rules:
- apiGroups: ["metrics.k8s.io"]
resources: ["pods","nodes"]
verbs: ["get","list","watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: metrics-server:system:auth-delegator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:auth-delegator
subjects:
- kind: ServiceAccount
name: metrics-server
namespace: kube-system
---
# (additional RoleBinding, APIService, ServiceAccount, Deployment, Service, and ClusterRole definitions continue…)Apply the manifest:
# kubectl apply -f components.yaml
clusterrole.rbac.authorization.k8s.io/system:aggregated-metrics-reader created
clusterrolebinding.rbac.authorization.k8s.io/metrics-server:system:auth-delegator created
rolebinding.rbac.authorization.k8s.io/metrics-server-auth-reader created
apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io created
serviceaccount/metrics-server created
deployment.apps/metrics-server created
service/metrics-server created
clusterrole.rbac.authorization.k8s.io/system:metrics-server created
clusterrolebinding.rbac.authorization.k8s.io/system:metrics-server createdVerify that the metrics.k8s.io API group is registered:
# kubectl api-versions | grep metrics
metrics.k8s.io/v1beta1Using kubectl top
The kubectl top command displays resource usage for Nodes and Pods, relying on the cluster’s metrics API.
Example – list node resource usage:
# kubectl top nodes
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
master 282m 14% 1902Mi 51%
node-02 70m 3% 1371Mi 37%
node-03 121m 1% 892Mi 11%Example – list pods in the kube-system namespace:
# kubectl top pods -n kube-system
NAME CPU(cores) MEMORY(bytes)
etcd-master 32m 300Mi
kube-apiserver-master 86m 342Mi
kube-controller-manager-master 30m 48Mi
kube-flannel-ds-l5ghn 5m 10Mi
kube-flannel-ds-rqlm2 4m 12Mi
kube-flannel-ds-v92r9 4m 14Mi
kube-proxy-7vjcv 18m 15Mi
kube-proxy-xrz8f 13m 21Mi
kube-proxy-zpwn6 1m 14Mi
kube-scheduler-master 7m 17Mi
metrics-server-5549c7694f-7vb66 2m 14MiThe kubectl top command provides a quick, built‑in way to monitor CPU and memory consumption of nodes and pods, making it essential for day‑to‑day Kubernetes operations.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
