Skip to content

kubectl top command

The kubectl top command is used to display resource usage information for cluster nodes and Pods^[400-devops__06-Kubernetes__k8s-ithelp__Day24__README.md]. It includes two subcommands, node and pod, which report Metrics such as CPU and memory utilization^[400-devops__06-Kubernetes__k8s-ithelp__Day24__README.md].

Usage

To view the resource usage of nodes:

[kubectl](<./kubectl.md>) top node

This command outputs columns for CPU cores (absolute and percentage) and Memory (bytes and percentage)^[400-devops__06-Kubernetes__k8s-ithelp__Day24__README.md].

To view the resource usage of Pods within a specific namespace:

[kubectl](<./kubectl.md>) top pods -n <namespace>

This lists the CPU (cores) and Memory (bytes) consumption for each Pod in the specified namespace^[400-devops__06-Kubernetes__k8s-ithelp__Day24__README.md].

Dependencies

The kubectl top command relies on the Metrics Server to function^[400-devops__06-Kubernetes__k8s-ithelp__Day24__README.md]. Metrics Server acts as a cluster-level data aggregator that collects Metrics from kubelet and exposes them via the API Server (typically at /apis/[Metrics](<./metrics.md>).k8s.io)^[400-devops__06-Kubernetes__k8s-ithelp__Day24__README.md].

It is important to note that Metrics Server stores data only in memory and does not retain historical data; if the service restarts, previous Metrics are lost^[400-devops__06-Kubernetes__k8s-ithelp__Day24__README.md]. Additionally, some cluster environments (like Docker-Desktop's Kubernetes) do not install Metrics Server by default, requiring manual installation before kubectl top can be used^[400-devops__06-Kubernetes__k8s-ithelp__Day24__README.md].

Sources

  • 400-devops__06-Kubernetes__k8s-ithelp__Day24__README.md