inspection

kubectl top

Displays CPU and memory usage for nodes or pods, powered by the metrics.k8s.io API. Requires the metrics-server (or an equivalent aggregator) to be installed in the cluster.

kubectl top (node | pod) [NAME | -l label] [flags]

Common flags

Flag Purpose
-A, --all-namespaces Show usage for pods across every namespace.
-l, --selector Filter pods by label.
--containers For pods, break down usage per container.
--sort-by Sort by cpu or memory.
--use-protocol-buffers Use protobuf for lower overhead on large clusters.
--no-headers Skip the column header row (useful in scripts).

Examples

kubectl top nodes --sort-by=cpu

Rank nodes by CPU pressure.

kubectl top pods -A --sort-by=memory

Find the largest memory consumers across the cluster.

kubectl top pod web-abc --containers

Per-container breakdown for one pod.

Gotcha

Returns "Metrics API not available" without metrics-server. Numbers are point-in-time and can lag by up to a minute.

Related commands

← All kubectl commands · Docker vs Kubernetes