kubectl top: Command Reference for CI/CD
See real CPU and memory usage, not just configured requests.
kubectl top reports actual resource consumption from the metrics API, answering "is this pod near its limit?". This reference covers the flags and the metrics-server dependency that makes top fail on bare CI clusters.
Common flags and usage
- top nodes: per-node CPU (millicores) and memory (bytes)
- top pods: per-pod usage in the current namespace
- top pods -A: across all namespaces
- --containers: break a pod down per container
- --sort-by=cpu|memory: order the output
Example
shell
kubectl top nodes
kubectl top pods -n prod --sort-by=memory
kubectl top pod -l app=web --containersIn CI
top needs metrics-server, which is not installed on kind/minikube/bare clusters by default ("Metrics API not available"). Install it first, and on kind/minikube add --kubelet-insecure-tls. Metrics lag ~15-60s after a pod starts, so wait one scrape interval before asserting on usage.
Key takeaways
- top requires metrics-server; bare CI clusters lack it by default.
- Metrics lag a scrape interval; do not read top immediately after start.
- --containers and --sort-by make top useful for triage.
Related guides
kubectl Cheat Sheet: Commands for Everyday KubernetesA kubectl cheat sheet - get, describe, logs, apply, rollout, debug, and context commands for daily Kubernetes…
kubectl describe: Command Reference for CI/CDReference for kubectl describe: render a resource plus its Events to debug ImagePullBackOff, CrashLoopBackOff…
kubectl get: Command Reference for CI/CDReference for kubectl get: list resources, output formats, label and field selectors, jsonpath extraction, an…
kubectl scale: Command Reference for CI/CDReference for kubectl scale: set replica counts, conditional scaling with --current-replicas, why an HPA figh…