kubectl-top
Show resource usage for nodes and pods
TLDR
Get the resource consumption of all nodes
Get resource consumption of a specific node
Get resource consumption of all pods
Get resource consumption of a specific pod
Get resource consumption of all pods in a namespace
Get resource consumption of all containers in a pod
Get resource consumption of all pods with the specified label
SYNOPSIS
kubectl top [node|pod] [NAME | --selector selector] [--namespace namespace] [options]
PARAMETERS
-A, --all-namespaces
Display resource (CPU/Memory) usage for pods in all namespaces
--containers
Display resource (CPU/Memory) usage for containers; node usage not shown (default false)
-h, --help
Help for top
-l, --selector string
Selector (label query) to filter on, supports '=', '==', '!=' (e.g. -l key1=value1,key2=value2)
-n, --namespace string
Namespace scope for the request (default current)
DESCRIPTION
kubectl top provides a dynamic view of resource consumption in Kubernetes clusters, showing CPU and memory usage for pods or nodes in a format inspired by the Unix top command. It queries the cluster's Metrics Server (or compatible API) to fetch real-time metrics, displaying them in easy-to-read tables with columns for NAME, CPU (cores or millicores), and MEMORY (bytes or MiB).
Usage requires a properly installed and running Metrics Server; otherwise, it reports 'metrics not available'. Run kubectl top pod for pods in the current namespace or kubectl top node for all nodes. Supports filtering by name, labels, or namespaces. Ideal for monitoring, troubleshooting high usage, and capacity planning without external tools.
Metrics reflect recent usage (typically 1-2 minute windows) and aggregate container data per pod by default.
CAVEATS
Requires Metrics Server (or equivalent) running in cluster; fails without metrics API. Metrics window is ~2 minutes; not historical. No sorting/refresh like full top(1).
PREREQUISITES
Deploy Metrics Server: kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
EXAMPLES
kubectl top pod (current namespace pods)
kubectl top node (all nodes)
kubectl top pod -l app=nginx -A (nginx pods everywhere)
HISTORY
Alpha in Kubernetes v1.6 (2017); beta/stable in v1.8 with Heapster-to-Metrics-Server shift. Evolved for Prometheus integration in later versions.
SEE ALSO
top(1), htop(1), kubectl-get(1), kubectl-describe(1)


