Kubernetes β’ Monitoring & Resources
How to Check CPU and Memory Resource Usage of Pods and Nodes
`kubectl top` retrieves real-time CPU and memory metrics reported by cAdvisor and metrics-server. It is the fastest way to identify memory leaks, resource hogging pods, and unallocated capacity across cluster worker nodes.
Check CPU & Memory (top) Command
Safe β’ Read-Only / Non-Destructive
kubectl top pods -A --sort-by=memoryCustomize:
Namespace:
Resource Name:
Flags & Parameter Breakdown
-A, --all-namespacesShow pods across every namespace--sort-by=memorySort results by memory usage descending (or --sort-by=cpu)--containersBreak down memory/CPU per individual container inside podsStep-by-Step Execution Workflow
1Find highest memory pods in current namespace
List pods sorted by RAM consumption:
kubectl top pods -n default --sort-by=memory2Find cluster-wide top CPU pods
Check across all namespaces for CPU spikes:
kubectl top pods -A --sort-by=cpu3Inspect cluster worker node utilization
Check memory and CPU pressure on physical/virtual nodes:
kubectl top nodesCommon Pitfalls & Troubleshooting Advice
- If you receive "error: Metrics API not available", install Kubernetes Metrics Server: `kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml`.
- CPU is reported in millicores (e.g. 250m = 0.25 CPU cores), and memory in MiB (e.g. 512Mi).
Prerequisites & Cluster Access
- Metrics Server must be installed and active in the cluster (`kube-system`).
Frequently Asked Questions About Check CPU & Memory (top)
Frequently Asked Questions
Frequently Asked Questions
Everything you need to know regarding specifications, syntax, and security best practices.
100m represents 100 millicores, which is equivalent to 10% (0.10) of a single CPU core.
Related Kubernetes & DevOps Recipes
View All RecipesNetworking & Access
How to Port-Forward a Kubernetes Pod or Service to Localhost
port-forwardGuide β
Debug & Inspection
How to Exec into a Kubernetes Pod with an Interactive Bash Shell
execGuide β
Troubleshooting
How to Debug and Fix CrashLoopBackOff Pods in Kubernetes
logsGuide β
Troubleshooting
How to Force Delete a Kubernetes Pod Stuck in Terminating State
deleteGuide β
Deployments & Workloads
How to Restart a Kubernetes Deployment with Zero Downtime
rolloutGuide β
Config & Secrets
How to Create a Kubernetes Generic Secret from an .env File
createGuide β