DEV Community

Cover image for Kubectl Demystified: Mastering the `kubectl cluster-info` Command
Naveen.S
Naveen.S

Posted on • Edited on

Kubectl Demystified: Mastering the `kubectl cluster-info` Command

ubernetes has become the de facto standard for container orchestration, and kubectl is the primary command-line tool for interacting with Kubernetes clusters. One of the most useful yet often overlooked commands in kubectl is cluster-info. This article explains what kubectl cluster-info does, when to use it, and how to leverage it effectively—especially for those preparing for the Certified Kubernetes Administrator (CKA) exam.


What is kubectl cluster-info?

The kubectl cluster-info command provides a high-level overview of your Kubernetes cluster. It displays the addresses of key components in the control plane (like the API server) and core add-ons (e.g., CoreDNS, metrics server) running in your cluster. Think of it as a quick "health check" to confirm your cluster is operational and accessible.


What Does kubectl cluster-info Do?

When executed, the command queries the Kubernetes API server (the central management point of the cluster) to retrieve information about:

  1. Control Plane Components: The API server, scheduler, controller manager, etcd, etc.
  2. Core Services: Add-ons like CoreDNS, metrics server, or the Kubernetes dashboard (if installed).

Sample Output

$ kubectl cluster-info
Kubernetes control plane is running at https://192.168.49.2:8443
CoreDNS is running at https://192.168.49.2:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Enter fullscreen mode Exit fullscreen mode

Here:

  • The control plane URL is the address of the API server.
  • CoreDNS shows the DNS service for internal cluster communication.

When to Use kubectl cluster-info

  1. Verify Cluster Connectivity

    After configuring kubectl, run this command to ensure you’re connected to the correct cluster.

  2. Troubleshooting

    If other commands fail (e.g., kubectl get pods), use cluster-info to check if the API server is reachable.

  3. CKA Exam Readiness

    During the exam, quickly validate your cluster’s status before performing tasks.


Examples and Usage

1. Basic Usage

kubectl cluster-info
Enter fullscreen mode Exit fullscreen mode

Output Explanation:

  • Confirms the API server is running and lists core services. If services like CoreDNS aren’t listed, they might not be installed or configured properly.

2. Check Specific Contexts

If you work with multiple clusters (e.g., dev, prod), use the --context flag:

kubectl cluster-info --context=my-dev-cluster
Enter fullscreen mode Exit fullscreen mode

Why This Matters:

  • Ensures you’re interacting with the intended cluster. Critical for avoiding accidents in production!

3. Enable Verbose Mode

Add -v=6 to see detailed API requests:

kubectl cluster-info -v=6
Enter fullscreen mode Exit fullscreen mode

Sample Output:

I0920 10:00:00.123456 12345 loader.go:372] Config loaded from: /home/user/.kube/config
I0920 10:00:00.234567 12345 round_trippers.go:454] GET https://192.168.49.2:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
...
Enter fullscreen mode Exit fullscreen mode

Use Case:

  • Debug connectivity issues by inspecting API server requests.

4. Dump Detailed Cluster Information

Use dump to collect extensive logs and statuses (helpful for support tickets):

kubectl cluster-info dump
Enter fullscreen mode Exit fullscreen mode

Output:

  • Logs from control plane components (API server, scheduler, etc.).
  • Resource states (pods, nodes, events).

Flags:

  • --output-directory=logs saves logs to a directory.
  • --namespaces=kube-system limits dumping to specific namespaces.

Common Errors and Fixes

Error 1: Unable to Connect to the API Server

The connection to the server <API-SERVER-URL> was refused
Enter fullscreen mode Exit fullscreen mode

Solution:

  • Check if the Kubernetes control plane is running (e.g., systemctl status kubelet on master nodes).
  • Verify your kubeconfig file points to the correct cluster (kubectl config view).

Error 2: CoreDNS Not Listed

If CoreDNS doesn’t appear in the output:

  • It might not be deployed. Install it using:
  kubectl apply -f https://github.com/kubernetes/kubernetes/blob/master/cluster/addons/dns/coredns/coredns.yaml
Enter fullscreen mode Exit fullscreen mode

CKA Exam Tips

  1. Quick Context Switching

    Use kubectl config use-context <context-name> before running cluster-info to ensure you’re on the right cluster.

  2. Validate Cluster Health

    Before starting exam tasks, run kubectl cluster-info to avoid wasting time on misconfigured clusters.

  3. Use Verbose Mode Sparingly

    While -v=6 helps debug, it adds noise. Use it only when necessary.

Image description

Conclusion

The kubectl cluster-info command is a simple but powerful tool for validating your Kubernetes cluster’s status. Whether you’re a beginner learning Kubernetes or a candidate preparing for the CKA exam, mastering this command will save time and reduce errors. Remember to combine it with other commands like kubectl get nodes and kubectl get pods -A for a comprehensive cluster overview.

Key Takeaways:

  • Use cluster-info to verify connectivity and core services.
  • Leverage --context for multi-cluster environments.
  • dump is your go-to for debugging complex issues.

With this knowledge, you’re one step closer to Kubernetes proficiency! 🚀

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

If you found this post useful, please drop a ❤️ or leave a kind comment!

Okay