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
