Metrics Server Integration¶
This document describes how ktop collects metrics from the Kubernetes Metrics Server.
Overview¶
The Kubernetes Metrics Server is a cluster-wide aggregator of resource usage data. It collects metrics from kubelets and exposes them through the Kubernetes API. ktop queries this API to display CPU and memory usage for nodes and pods.
This is the most compatible metrics source, working with virtually all Kubernetes clusters including managed services like GKE, EKS, and AKS.
Quick Start¶
# Explicit metrics server mode
ktop --metrics-source=metrics-server
# ktop auto-detects available sources
# Falls back to metrics-server if prometheus isn't available
ktop
Architecture¶
How It Works¶
ktop queries Metrics Server through the Kubernetes API using the GA metrics.k8s.io/v1 endpoint and falls back automatically to metrics.k8s.io/v1beta1 on older clusters:
- Node metrics:
/apis/metrics.k8s.io/v1/nodes(fallback/apis/metrics.k8s.io/v1beta1/nodes) - Pod metrics:
/apis/metrics.k8s.io/v1/pods(fallback/apis/metrics.k8s.io/v1beta1/pods)
These endpoints work wherever kubectl top works.
Metrics Collected¶
Node Metrics¶
| Metric | API Field | Description |
|---|---|---|
| CPU usage | usage.cpu |
Current CPU consumption |
| Memory usage | usage.memory |
Current memory consumption |
Pod/Container Metrics¶
| Metric | API Field | Description |
|---|---|---|
| CPU usage | containers[].usage.cpu |
Per-container CPU consumption |
| Memory usage | containers[].usage.memory |
Per-container memory consumption |
Historical Data¶
ktop maintains local ring buffers to store metrics history when using Metrics Server mode. This enables sparklines and trend visualization even though Metrics Server itself only provides point-in-time data.
- Default buffer size: 120 samples (~10 minutes at default refresh rate)
- History is lost when ktop exits
- Only CPU and memory history is tracked
RBAC Requirements¶
Metrics Server mode requires standard read access to the metrics API:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: ktop-metrics-server
rules:
- apiGroups: ["metrics.k8s.io"]
resources: ["nodes", "pods"]
verbs: ["get", "list"]
Most Kubernetes users already have these permissions. Check with:
Troubleshooting¶
"metrics client not available"¶
Cause: Metrics Server is not installed or not accessible.
Solutions: 1. Check if Metrics Server is running:
2. Verify metrics API is available: 3. Install Metrics Server if missing:kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
Metrics show as "-" or "n/a"¶
Cause: Metrics Server hasn't collected data yet, or pod is too new.
Solutions:
1. Wait 30-60 seconds after pod startup
2. Verify the pod is running: kubectl get pod <name>
3. Check Metrics Server logs: kubectl logs -n kube-system deployment/metrics-server
"Metrics Server unavailable" errors¶
Cause: Network or permission issues reaching Metrics Server.
Solutions:
1. Check cluster connectivity: kubectl cluster-info
2. Verify RBAC permissions (see above)
3. Check if Metrics Server pod is healthy:
Limitations¶
- Basic metrics only: CPU and memory usage. PSI stall percentages, CPU throttling, network RX/TX rates, disk I/O, and volume fill metrics are unavailable (
unavailable/-) because Metrics Server does not expose them. - No native history: Metrics Server provides point-in-time snapshots only.
ktopmaintains local ring buffers for sparklines while open, and history clears on exit. - Aggregated values: Container metrics are pre-aggregated on an upstream scrape cycle (typically 15–60s), making short bursts less visible than direct Prometheus scraping.
Graceful Degradation & Fallback¶
Every tab ([1] Overview, [2] Workloads, [3] Storage, [4] Network, and [5] Events) remains functional regardless of telemetry source. When --metrics-source is omitted, ktop:
- Attempts direct Prometheus scraping via kubelet proxies first.
- Falls back to Metrics Server (
metrics.k8s.io/v1, thenv1beta1) if direct node proxy RBAC is unavailable. - Falls back cleanly to Kubernetes resource specs (requests/limits and object state) when no metrics API responds or
--metrics-source=noneis set.
Panels that depend exclusively on Prometheus telemetry display explicit unavailable indicators rather than failing or hiding object inventory.