LinuxCommandLibrary

kubectl-top

Show resource usage for nodes and pods

TLDR

Get the resource consumption of all nodes

$ kubectl top [[no|nodes]]
copy

Get resource consumption of a specific node
$ kubectl top [[no|nodes]] [node_name]
copy

Get resource consumption of all pods
$ kubectl top [[po|pods]]
copy

Get resource consumption of a specific pod
$ kubectl top [[po|pods]] [pod_name]
copy

Get resource consumption of all pods in a namespace
$ kubectl top [[po|pods]] [[-n|--namespace]] [namespace_name]
copy

Get resource consumption of all containers in a pod
$ kubectl top [[po|pods]] --containers
copy

Get resource consumption of all pods with the specified label
$ kubectl top [[po|pods]] [[-l|--selector]] [key=value]
copy

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

Copied to clipboard