Skip to main content

KTOP: Real-time Kubernetes Resource Usage Monitoring

β€” Aswin

In this blog, you will learn about a monitoring tool called ktop.

Kubernetes does not natively provide real-time resource usage monitoring and visualization, which can make it challenging to track the current performance of nodes, pods, and other resources.

This is where ktop comes in, a tool designed to display real-time metrics of Kubernetes nodes and pods within a cluster and is similar to the classic top command.

It offers a way to monitor resource usage, making it easier to manage and optimize your cluster’s performance, which can help troubleshoot performance bottlenecks, diagnose issues, and optimize resource usage.

Install ktop

Before installing ktop, make sure you have installed a metrics server in your system because it gets the metrics from the Metrics server.

If you don't have a metrics server in your system, run the following command to install it

kubectl apply -f https://raw.githubusercontent.com/techiescamp/kubeadm-scripts/main/manifests/metrics-server.yaml

Now, visit the official ktop releases page and download the latest binary for your system.

Download the tar file using the curl command as given below

curl -LO https://github.com/vladimirvivien/ktop/releases/download/v0.3.7/ktop_v0.3.7_linux_amd64.tar.gz

Extract the downloaded binary

tar -xzf ktop_*.tar.gz

Copy the ktop binary to your system's execution path

sudo mv ktop /usr/local/bin/

For other installation methods, refer to the official GitHub repo.

Get Metrics using ktop

Run the following command to get the metrics of all resources in your cluster.

ktop

You will get the metrics of every node, pod, and other details of your cluster.

In the top block, you will get the URL of your API server, cluster version, name of the current cluter you are using, user name, namespace and if ktop is connected to metrics server or not.

And, in the second block you will get the objects details like, number of namespaces, pods, PVs, etc,..

In the third block, you will get the list of every node available and their details (Version, Disk size, memory and CPU usage, etc).

The last block shows the list of every pod running on your cluster.

If you want the metrics of Pod in a specific namespace, run the following command.

ktop -n default

Ktop uses the current cluster you are configured to your system, let's say you have multiple clusters running, and you want to get the metrics of a specific cluster.

First get the context name of the cluster configured in theKubeconfig file, and run the following command to get every available context in your system.

kubectl config get-contexts

Then, use the context name of the cluster you want to get the metrics in below command

ktop --context kubernetes-admin@kubernetes

Replace kubernetes-admin@kubernetes with your cluster's context name.

If you want to get the metrics of a specific namespace, run the following command

ktop --namespace default --context kubernetes-admin@kubernetes
Aswin
Website India