$ run as a normal user# run as root (or with sudo)
The quick answer
Step by step
- Real usage — nodes and Pods (quick answer).
--sort-by=cpu|memoryputs the biggest at the top;--containerssplits Pods into containers (app vs sidecar). - Reserved (requests) vs real use:
kubectl describe node worker1 | grep -A10 'Allocated resources'
Resource Requests Limits
cpu 3650m (91%) 6 (150%)
memory 12Gi (78%) 20Gi (130%)This node is 91 % requested but only 46 % used — new Pods can not be scheduled although the CPU is half idle. The fix is better (lower) requests, not more nodes.
- Requests vs usage per Pod — find over- and under-sized apps:
kubectl get pods -n shop -o custom-columns=NAME:.metadata.name,CPU_REQ:.spec.containers[*].resources.requests.cpu,MEM_REQ:.spec.containers[*].resources.requests.memory
kubectl top pods -n shop- Install metrics-server if
kubectl topsaysMetrics API not available:
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml(Pin a release version instead of latest for production. On kubeadm labs it may need --kubelet-insecure-tls; in production give the kubelets proper certificates.)
- History and trends —
kubectl topshows only "now". For "since when does it grow?" use Prometheus + Grafana (kube-state-metrics and cAdvisor metrics), ork9sfor a live view.
Check that it worked
You can name the top 5 Pods by memory and CPU, see for each node the usage and the requested share, and decide if the problem is real load or wrong requests.
Common problems
| Problem | Cause | Fix |
|---|---|---|
error: Metrics API not available | No metrics-server. | Install it; check its Pod logs. |
metrics-server logs x509 errors | kubelet serving certificates not trusted. | Proper kubelet certs; --kubelet-insecure-tls only in labs. |
| Node "full" but CPU idle | Requests far above real use. | Lower requests from measured usage. |
Memory % looks higher than free on the node | top shows working set (incl. some cache). | Normal; compare trends, not single numbers. |
A Pod is missing in top | It just started (metrics every ~15–60 s) or is not running. | Wait a minute; check the Pod status. |
| Numbers jump around | Short sampling window. | Use Prometheus for averages and percentiles. |
Go further
- Command pages: kubectl, k9s.
- Next how-tos: Set resource requests and limits, Scale a deployment, Check memory and CPU usage (Linux).
- Learn it: CKA — Monitoring, CKA — Resources. Full guides: k9s, Prometheus.
1A node shows 91 % CPU requested but 46 % used. What does that mean?
The scheduler sees it as almost full because of high requests, though the CPU is half idle — lower the requests.
2What does kubectl top need in the cluster?
metrics-server.