Difficulty: Beginner
How do you check real-time CPU and memory usage of nodes and Pods in a Kubernetes cluster?
Use kubectl top nodes to see current CPU and memory usage per node, and kubectl top pods (with -n, -A, -l or --containers) for Pods and containers. Both read from the Metrics Server through the metrics.k8s.io API, so Metrics Server must be installed. The numbers are a recent snapshot, roughly 15 to 60 seconds old, not a historical graph.
kubectl top nodes: CPU in millicores and memory per node, plus percentages.kubectl top pods -n checkout: usage per Pod in a namespace.kubectl top pods -A --sort-by=memory: find the heaviest Pods across the cluster.kubectl top pod <name> --containers: break usage down per container, useful when a sidecar is the culprit.kubectl top pods -l app=payments: filter by label.250m is a quarter of one core.Mi or Gi. This is the same number the kubelet uses for OOM and eviction decisions, so it is more useful than total cache-inclusive memory.--show-capacity to compare against raw capacity instead.A frequent interview trap: kubectl top shows actual usage, while scheduling is based on requests. To see what is reserved on a node, use kubectl describe node <name> and look at the "Allocated resources" section.
| Question | Command |
|---|---|
| What is the Pod using right now? | kubectl top pod |
| What has the Pod reserved? | kubectl get pod -o yaml (resources.requests) |
| Why will no new Pod fit on this node? | kubectl describe node (allocated requests vs allocatable) |
| What did usage look like over the last week? | Prometheus and Grafana, not kubectl top |
A node can show 30% CPU in kubectl top and still reject new Pods because its requests are 100% allocated. That is a sign of over-requesting and a good conversation about rightsizing.
error: Metrics API not available: Metrics Server is missing or unhealthy. Check kubectl get apiservice v1beta1.metrics.k8s.io and the metrics-server Pod logs.In practice, during an incident such as a festive sale spike at Flipkart, kubectl top pods --sort-by=cpu is often the first quick check to see which service is hot before opening Grafana.
# Node level
kubectl top nodes
# Top 5 memory consumers across all namespaces
kubectl top pods -A --sort-by=memory | head -6
# Per-container breakdown for one Pod
kubectl top pod payments-api-7c9f6d-x2k4p -n payments --containers
# Compare usage with what is reserved on a node
kubectl describe node ip-10-0-1-23 | grep -A 8 "Allocated resources"
`kubectl top` answers "what is being used now", while `describe node` answers "what has been promised". You often need both to explain why scheduling fails or why a node is under pressure.
kubectl top, Metrics Server, Working Set Memory, Millicores, Requests vs Usage