Kubernetes

Kubectl Cluster-Info Command

Kubernetes provides a powerful set of tools and features that make it easier for developers to manage complex applications and deploy them in a scalable infrastructure. One of the most commonly used commands is the “kubectl cluster-info” command which is used to retrieve an information about the Kubernetes cluster. This article explains the purpose of the “kubectl cluster-info” command and its variations.

What Is Kubectl Cluster-Info?

The “kubectl cluster-info” command provides an overview of the Kubernetes cluster. The distributed key-value store that stores the configuration information for the cluster, etcd, and other Kubernetes components are displayed together with the state of the Kubernetes control plane comprising the Kubernetes API server, Kubernetes version, the Kubernetes dashboard URL. It also provides information on the Kubernetes version, the container runtime, and the operating system that run on each node in the cluster.

By running the “kubectl cluster-info,” you can quickly get an idea of the overall health of the cluster and identify any potential issues. It helps you to troubleshoot any issues with the Kubernetes cluster.

To use the “kubectl cluster-info” command, the first thing that you need is a running Kubernetes cluster. If you don’t have one, you can easily set up a local Kubernetes cluster using a tool like Minikube. Once you have a running cluster, you can use the “kubectl cluster-info” command to retrieve an information about the cluster.

Before we begin, we need to have a running Kubernetes cluster. On our local system, we can set up a single-node Kubernetes cluster using the minikube tool. Let us set up the Kubernetes cluster using the minikube cluster.

Step 1: Starting a Minikube Cluster

Before we can use the “kubectl cluster-info” command, we need to have a running Kubernetes cluster. Once we have the cluster up and running, we can use the “kubectl cluster-info” command to get an information about the cluster. In this example, we start a Minikube cluster using the following command:

~$ minikube start

When you execute this command, it shows the following output:

Step 2: Running the Kubectl Cluster-Info

Now that our cluster is running, we can run the “kubectl cluster-info” command to get an overview of the Kubernetes cluster. This command is executed by running the following command in your minikube cluster:

~$ kubectl cluster-info

The output of this command provides an information on all the services including the addresses. When the user sets the “kubernetes.io/cluster-service” label to “true” for the clusters, the “kubectl cluster-info” provides the master information for those clusters. When we run the “kubectl cluster-info” command, we’ll see a similar output to the following:

As you can see in the output, this output tells us that the Kubernetes control plane is running at a specific IP address and port and that the CoreDNS (a DNS server for Kubernetes) is also running.

The Kubernetes master is running at https://192.168.49.2:8443. The CoreDNS is running at https://192.168.49.2:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

The first line provides the URL of the Kubernetes API server which is used to interact with the Kubernetes cluster. The second line provides the URL of the CoreDNS service which is used for DNS resolution within the Kubernetes cluster. We can use this information to connect to our Kubernetes cluster and manage its resources.

Step 3: Using the Kubectl Cluster-Info Dump

The “kubectl cluster-info dump” command is used to dump the information about the cluster which can later be used for diagnosis and troubleshooting the Kubernetes cluster. It includes information about the Kubernetes control plane, nodes, state, API version, pods, labels, annotations, services, and more. The following command is executed in the minikube cluster to get the required information:

~$ kubectl cluster-info dump

The output of the “kubectl cluster-info dump” command is quite extensive and is typically used to troubleshoot the issues with the Kubernetes cluster. It provides a detailed snapshot of the current state of the cluster which can be helpful in identifying any potential issues. Refer to the following snapshot of the “kubectl cluster-info dump” command:

As you can see in the output, this command displays a large amount of output including the Kubernetes API server’s configuration, the controller manager’s configuration, and the scheduler’s configuration. It also includes information about the etcd database which is used by the Kubernetes cluster to store its configuration data. All this information is dumped in the “stdout” by default.

Step 4:# Using the Kubectl Cluster-Info Dump –Output-Directory

By default, the “kubectl cluster-info dump” command outputs the results to the console. However, it is possible to dump the output to a file using the “–output-directory” option. This option specifies the directory where the output files should be written instead of the console. You can specify the directory address with the “kubectl cluster-info dump” just like the complete command in the following:

~$ kubectl cluster-info dump --output-directory=/path/to/cluster-state

This writes the output of the “kubectl cluster-info dump” command to the directory that is specified by the “–output-directory” option which is the /path/to/cluster-state. See the following given output in the snapshot:

The output shows that the “kubectl cluster-info dump –output-directory=/path/to/cluster-state”

creates a directory named “cluster-state” in the “/path/to” directory and stores the output files in that directory.

Step 5: Using the Kubectl Cluster-Info Dump –All-Namespaces

The “kubectl cluster-info” also works with the Kubernetes namespaces. The “kubectl cluster-info dump –all-namespaces” command dumps the information on all namespaces in the Kubernetes cluster if they are set to “true”. By default, the value of the “–all-namespaces” argument is false, so the “kubectl cluster-info dump –all-namespaces” does not dump any information about the namespaces until the user specifically sets the value of the –all-namespaces to “true”. Run the following command in your minikube cluster to get the desired output:

~$ kubectl cluster-info dump --all-namespaces

This command is useful when you need to get an overview of all the resources in the Kubernetes cluster including pods, services, and other resources.

Conclusion

One of the most useful commands in kubectl is the “kubectl cluster-info” which provides essential information about the current Kubernetes cluster. The “kubectl cluster-info” command is an amazing tool that keeps a lot of information about the Kubernetes cluster.

In this article, we dived into how to use this command and what kind of information you can expect to see. It is used to display the cluster’s endpoint and namespace, as well as the detailed information about the Kubernetes cluster’s API server, controller manager, and scheduler. The “kubectl cluster-info dump” command provides an even more detailed information and can be used to store the output in a directory. The “–all-namespaces” option can be used to include an information about all namespaces in the Kubernetes cluster.

About the author

Kalsoom Bibi

Hello, I am a freelance writer and usually write for Linux and other technology related content