liveBook · Manning

Kubectl top

As explained in Acing the Certified Kubernetes Administrator Exam, Second Edition

kubectl top is a kubectl command that displays current CPU and memory usage for Kubernetes nodes or pods.

kubectl top displays current CPU and memory utilization for Kubernetes nodes or pods. Use it during troubleshooting and autoscaling work to observe consumption rather than merely configured resource requests. section 8.2.2 section 5.1.5

Use the command at two operational scopes:

  • `kubectl top no` reports node CPU and memory usage, including percentages of node capacity. section 8.2.2
  • `kubectl top pod` reports CPU and memory usage for pods, making workload consumption visible to Horizontal Pod Autoscaler checks. section 5.1.5
  • Compare utilization with `kubectl describe node`, whose Allocated section shows pod resource requests and limits; these are different measurements. section 8.2.2

Verify node utilization

After a metrics server is available, run `kubectl top no`. A node might report `265m` CPU and `972Mi` memory, representing 13% CPU and 49% memory on a two-core, 2Gi node. If metrics are unavailable, install metrics-server and, where required by the kind setup, add the `--kubelet-insecure-tls` argument. section 8.2.2

Verify pod metrics for autoscaling

Run `kubectl top pod` after configuring a CPU request and starting metrics-server. The command can show nginx pods at `0m` CPU and a few MiB of memory; the HPA can then report a concrete target such as `cpu: 0%/80%` instead of `<unknown>`. section 5.1.5

root@kind-control-plane:~# kubectl top no
NAME                 CPU(cores)   CPU(%)   MEMORY(bytes)   MEMORY(%)   
kind-control-plane   265m         13%      972Mi           49%

Inspect representative node-level CPU and memory output, including absolute usage and capacity percentages. section 8.2.2

root@kind-control-plane:/# kubectl top pod | egrep "CPU|nginx"
NAME                      CPU(cores)   MEMORY(bytes)   
nginx-5c799c6d5f-4lkr9    0m           3Mi             
nginx-5c799c6d5f-8w494    0m           2Mi

Inspect representative pod-level metrics used to replace an HPA CPU target of `<unknown>` with an observed value. section 5.1.5

How Acing the Certified Kubernetes Administrator Exam, Second Edition covers it

How deep it goes
Explains node and pod commands, metrics-server setup, output interpretation, and utilization-versus-allocation distinctions without detailing metrics-server internals.
Examples
Uses kind node output, nginx pod metrics, CPU requests, and HPA targets as operational examples.
What it assumes
Assumes basic kubectl and Kubernetes resource knowledge, while teaching metrics-server setup and the difference between usage and allocation.
What you can do after
Diagnose resource consumption and verify whether pod metrics are available for HPA reporting.
How it connects
Connects metrics server, resource requests, Horizontal Pod Autoscaler, and kubectl describe node.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Acing the Certified Kubernetes Administrator Exam, Second Edition. The section links point to the parts of the book it draws on.