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=memory
Customize:
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 pods

Step-by-Step Execution Workflow

1Find highest memory pods in current namespace

List pods sorted by RAM consumption:

kubectl top pods -n default --sort-by=memory
2Find cluster-wide top CPU pods

Check across all namespaces for CPU spikes:

kubectl top pods -A --sort-by=cpu
3Inspect cluster worker node utilization

Check memory and CPU pressure on physical/virtual nodes:

kubectl top nodes

Common 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.