Kubernetes metrics: metrics-server and Lens Metrics
metrics-server and Lens Metrics solve different problems. metrics-server gives the current CPU and memory usage, for kubectl top and the HPA. Lens Metrics installs a Prometheus, with history, for the IDE charts. This page shows how to install each one and which one Kubepier uses.
What metrics-server is
- A Kubernetes component that reads CPU and memory usage for every node and pod from the kubelet and serves it through the Metrics API (metrics.k8s.io).
- kubectl top and the HorizontalPodAutoscaler’s CPU and memory metrics come from it.
- It keeps only the latest reading, in memory: no history and no charts. That is what Prometheus is for.
- AKS and GKE ship with metrics-server, and so does k3s. On EKS, kubeadm and kind, you usually install it.
How to install metrics-server
From the newest release manifest, or with Helm:
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
# or with Helm
helm repo add metrics-server https://kubernetes-sigs.github.io/metrics-server/
helm upgrade --install metrics-server metrics-server/metrics-server -n kube-system Check that metrics-server responds
The APIService must be Available, and kubectl top must answer a minute or two after the install:
kubectl get apiservice v1beta1.metrics.k8s.io
kubectl -n kube-system get deploy metrics-server
kubectl top nodes
kubectl top pods -A - "Metrics API not available": metrics-server is not installed, or its pod is not ready. Check the Deployment logs.
- An x509 error talking to the kubelet, common on kind and minikube: the kubelet certificate is not signed by the cluster CA. In a lab, the --kubelet-insecure-tls argument works around it; in production, fix the certificates.
- A pod with no metrics right after it starts: the first reading takes a few seconds.
What Lens Metrics is
Lens Metrics is a bundle of Prometheus, kube-state-metrics and node-exporter, installed in the lens-metrics namespace. It keeps history and feeds the CPU, memory, network and disk charts for clusters, nodes and pods in the Lens and Freelens IDEs, and in Kubepier Desktop.
It does not replace metrics-server: kubectl top and the HPA still read the Metrics API.
Lens Metrics in Kubepier Desktop
- Open the cluster Settings › Metrics and use Install / Update under Lens Metrics. Kubepier applies Prometheus, kube-state-metrics and node-exporter in the lens-metrics namespace and picks the Lens provider.
- Metrics show up in 1 to 2 minutes, once Prometheus finishes starting.
- If the cluster already has a Prometheus, pick its provider on the same screen instead of installing another one.
- Without Prometheus, the node and pod lists use metrics-server, when the cluster has it.
- Uninstall asks for confirmation and deletes the lens-metrics namespace, with all the metrics history.
- From desktop 2.7.0, installing or updating is for Pro and Team, and uninstalling is admin-only.
- Install and uninstall need permission to create Namespace, ServiceAccount, ConfigMap, Service, DaemonSet, Deployment, StatefulSet, ClusterRole and ClusterRoleBinding: in practice, cluster-admin.
Metrics in Kubepier Web: metrics-server
Kubepier Web shows CPU and memory usage per cluster, node and namespace from the metrics-server the cluster already has, with nothing to install. Without metrics-server, usage does not show. If it stops responding, the screen tells you usage is unavailable. The credential needs get and list on pods and nodes in the metrics.k8s.io group.
Which one to use
| You need | Use |
|---|---|
| kubectl top, HPA on CPU or memory | metrics-server |
| Usage in Kubepier Web | metrics-server |
| Charts with history in Kubepier Desktop | Lens Metrics, or the Prometheus the cluster already has |
| Alerting and long retention | A full Prometheus (with Alertmanager) or your cloud monitoring |