Skip to content
Latchkey

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 --containers

In 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →