Show CPU and memory resource usage for nodes and pods.
low risk
kubectl top shows real-time CPU and memory usage for nodes and pods, powered by the metrics-server addon. Unlike kubectl get (which shows requests/limits), top shows actual consumption. Essential for identifying resource-hungry pods and right-sizing requests.
| Flag | Meaning |
|---|---|
--sort-by | Sort by cpu or memory |
--containers | Show per-container usage within pods |
-A --all-namespaces | Show across all namespaces |
kubectl top nodesNode CPU and memory usage · explain & risk-check →kubectl top pods -A --sort-by=memoryMost memory-hungry pods across all namespaces · explain & risk-check →kubectl top pods --containers -n productionPer-container resource usage in production · explain & risk-check →watch kubectl top pods -A --sort-by=cpuLive top CPU consumers across cluster · explain & risk-check →Use `kubectl top pods --sort-by=memory` before scaling — it often reveals one rogue pod consuming 10x expected memory, letting you target the fix rather than scaling everything.
Reference text is hand-written and may be incomplete — check man kubectl for your version. Test destructive commands on a non-production system first.