kubectl top Command
What you'll learn: How to use kubectl top to quickly check CPU and memory usage for nodes and pods in your cluster.
Why kubectl top Matters
Now that your Metrics Server is running (from the previous lessons), you can finally see what's happening with your cluster's resources. The kubectl top command is your window into real-time resource consumption—think of it as the "task manager" for Kubernetes.
Viewing Node Resources
To see resource usage across all nodes:
kubectl top nodes
This displays output like:
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
node-1 450m 22% 2048Mi 51%
node-2 780m 39% 3200Mi 80%
Interpreting the output:
- CPU(cores): "450m" means 450 millicores (0.45 of a CPU core)
- CPU%: Percentage of the node's total CPU capacity being used
- MEMORY(bytes): Actual memory consumption in mebibytes (Mi)
- MEMORY%: Percentage of the node's total memory being used
Viewing Pod Resources
To check resource usage for pods:
kubectl top pods
kubectl top pods -n my-namespace
Output example:
NAME CPU(cores) MEMORY(bytes)
web-app-abc123 120m 256Mi
database-xyz789 350m 1024Mi
This shows how much each pod is actually consuming right now—not what you requested or limited, but what's being used at this moment.
Practical Tips
Use kubectl top pods --containers to break down usage per container within pods. This helps identify which container in a multi-container pod is the resource hog.
Key Takeaway: The kubectl top command provides real-time CPU and memory usage snapshots from the Metrics Server, helping you monitor resource consumption at both the node and pod levels—essential for capacity planning and troubleshooting performance issues.