šŸ¶
Kubernetes

kubectl Commands to Get Kubernetes Master Node Details

By Jan on 02/06/2025

Learn how to use the kubectl command to retrieve detailed information about your Kubernetes master nodes and their status.

kubectl Commands to Get Kubernetes Master Node Details

Table of Contents

Introduction

Kubernetes, the powerful container orchestration system, often requires you to delve into its inner workings for troubleshooting or monitoring. The kubectl command-line tool serves as your window into the cluster, providing a wealth of information about its components and their status.

Step-by-Step Guide

To find detailed information about your Kubernetes cluster and its components, you can use the kubectl command-line tool. Here's a breakdown:

1. Check kubectl Version and Connection:

Begin by verifying your kubectl version and connection to the cluster:

kubectl version

This command displays both the client and server versions. If you encounter an error, ensure your kubectl configuration is correct and you have network connectivity to the cluster.

2. Get Cluster-Wide Information:

Use the following command to retrieve general information about your cluster:

kubectl cluster-info

This provides details like the Kubernetes master endpoint and any configured plugins.

3. Inspect Nodes:

To list the nodes in your cluster and their status:

kubectl get nodes

For a more detailed view of a specific node, including its resources and conditions:

kubectl describe node <node-name>

Replace <node-name> with the actual name of the node.

4. Examine Master Components:

While you can't directly access master components like the API server and kubelet using kubectl get, you can obtain information about them through other means:

  • API Server: The kubectl version command shows the API server version.
  • Kubelet: You typically need to SSH into individual nodes to interact with the kubelet service directly.

5. Explore Other Resources:

kubectl allows you to inspect various other resources within your cluster. Some common commands include:

  • List pods: kubectl get pods
  • Describe a pod: kubectl describe pod <pod-name>
  • Get logs from a container: kubectl logs <pod-name> -c <container-name>

Important Notes:

  • Replace placeholders like <node-name> and <pod-name> with actual names.
  • Use the -n <namespace> flag to specify a namespace other than the default.
  • Refer to the official Kubernetes documentation for a comprehensive list of kubectl commands and options.

Code Example

This document provides examples of using the kubectl command-line tool to inspect a Kubernetes cluster. It covers checking kubectl and server versions, getting cluster information, listing and describing nodes, understanding how to indirectly inspect master components, and exploring resources like pods. Remember to replace placeholders with actual values and refer to the official Kubernetes documentation for a complete list of kubectl commands.

This guide provides practical examples of using the kubectl command-line tool to gather information about your Kubernetes cluster.

1. Verify kubectl Version and Connection:

# Check kubectl client and server versions
kubectl version

# Example Output:
# Client Version: version.Info{Major:"1", Minor:"26", GitVersion:"v1.26.1", ...}
# Server Version: version.Info{Major:"1", Minor:"25", GitVersion:"v1.25.3", ...}

2. Get Cluster-Wide Information:

# Retrieve general cluster information
kubectl cluster-info

# Example Output:
# Kubernetes master is running at https://kubernetes.default.svc.cluster.local:443
# ...

3. Inspect Nodes:

# List all nodes and their status
kubectl get nodes

# Example Output:
# NAME                 STATUS   ROLES           AGE     VERSION
# node1.example.com   Ready    control-plane   2d10h   v1.25.3
# node2.example.com   Ready    <none>          2d10h   v1.25.3

# Get detailed information about a specific node
kubectl describe node node1.example.com

# Example Output:
# Name:               node1.example.com
# Roles:              control-plane
# ...
# System Info:
#   Operating System:  linux
#   Architecture:        amd64
# ...

4. Examine Master Components (Indirectly):

# API Server version is shown in the 'kubectl version' output

# To interact with kubelet, SSH into the desired node:
ssh user@node1.example.com

# Once connected, you can use system commands to inspect the kubelet service.

5. Explore Other Resources:

# List pods in all namespaces
kubectl get pods -A

# List pods in a specific namespace
kubectl get pods -n kube-system

# Describe a specific pod
kubectl describe pod my-pod -n my-namespace

# Get logs from a container within a pod
kubectl logs my-pod -c my-container -n my-namespace

Remember:

  • Replace placeholders like <node-name>, <pod-name>, <container-name>, and <namespace> with actual values.
  • Consult the official Kubernetes documentation for a comprehensive list of kubectl commands and options: https://kubernetes.io/docs/reference/kubectl/

Additional Notes

  • Context Switching: If you work with multiple clusters, use kubectl config get-contexts to list available contexts and kubectl config use-context <context-name> to switch between them.
  • Formatting Output: kubectl offers various output formats like YAML, JSON, and custom columns. Use the -o or --output flag for customization (e.g., kubectl get pods -o wide).
  • Resource Limits: Be mindful of resource limits when inspecting large clusters. Commands like kubectl get pods -A (all namespaces) can return a significant amount of data. Consider filtering or using pagination (--limit, --page) for better performance.
  • Live Data: The information retrieved by kubectl is a snapshot in time. For real-time monitoring, consider tools like kubectl top, watch, or dedicated monitoring solutions.
  • Security: Protect your kubectl configuration (usually located in ~/.kube/config) as it contains credentials to access your cluster.
  • Beyond the Basics: This guide covers fundamental inspection commands. kubectl offers a rich set of features for managing deployments, services, secrets, and more. Explore the official documentation to unlock its full potential.
  • Troubleshooting: If kubectl commands fail, carefully examine the error messages. They often provide clues about configuration issues, resource constraints, or problems within the cluster.
  • Community Resources: The Kubernetes community is vast and active. Online forums, Slack channels, and Stack Overflow are excellent resources for seeking help and sharing knowledge.

Summary

This guide provides a quick overview of using the kubectl command-line tool to gather information about your Kubernetes cluster.

| Information | Command | Description

Conclusion

kubectl is your go-to tool for understanding your Kubernetes cluster. From verifying versions to inspecting individual nodes and exploring resources, the commands presented here provide a foundation for effective cluster management and troubleshooting. Remember to consult the official Kubernetes documentation and leverage community resources as you dive deeper into the world of container orchestration.

References

  • Command line tool (kubectl) | Kubernetes Command line tool (kubectl) | Kubernetes | Kubernetes provides a command line tool for communicating with a Kubernetes cluster's control plane, using the Kubernetes API. This tool is named kubectl. For configuration, kubectl looks for a file named config in the $HOME/.kube directory. You can specify other kubeconfig files by setting the KUBECONFIG environment variable or by setting the --kubeconfig flag. This overview covers kubectl syntax, describes the command operations, and provides common examples. For details about each command, including all the supported flags and subcommands, see the kubectl reference documentation.
  • The connection to the server <host>:6443 was refused - did you ... The connection to the server :6443 was refused - did you ... | Hello guys. Everything was working on a kubernetes cluster with a master and three nodes. After a restart in all machines I started receiving this error when trying to run any kubectl command. #> kubectl version Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.0", GitCommit:"925c127ec6b946659ad0fd596fa959be43f0cc05", GitTreeState:"clean", BuildDate:"2017-12-15T21:07:38Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"linux/amd64"} The connection to the server 135.122.6.50:644...
  • kubectl Quick Reference | Kubernetes kubectl Quick Reference | Kubernetes | This page contains a list of commonly used kubectl commands and flags. Note:These instructions are for Kubernetes v1.32. To check the version, use the kubectl version command. Kubectl autocomplete BASH source <(kubectl completion bash) # set up autocomplete in bash into the current shell, bash-completion package should be installed first. echo "source <(kubectl completion bash)" >> ~/.bashrc # add autocomplete permanently to your bash shell. You can also use a shorthand alias for kubectl that also works with completion:
  • Microk8s: how to get the node external-ip, like "minikube ip ... Microk8s: how to get the node external-ip, like "minikube ip ... | Using microk8s 1.18 on Ubuntu 20.04. Iā€™d like to get the external ip of the node. Similar to minikube ip as shown in the Istio Ingress Gateways documentation. Question: How to get the IP address of the node so to allow remote clients outside of the cluster to access services installed within the cluster? In my example, this address would be 192.168.1.98. Maybe it is possible to grep it from microk8s.kubectl cluster-info However all I can see is the loopback IP 127.0.0.1. $ microk8s.kubectl c...
  • Master Kubernetes Node Commands: The Ultimate kubectl ... Master Kubernetes Node Commands: The Ultimate kubectl ... | Explore essential Kubernetes commands for efficient cluster management, including kubectl get, exec, and rollout, vital for system admins and devs.
  • Kubectl error couldn't get current server API group list - General ... Kubectl error couldn't get current server API group list - General ... | Good afternoon everybody! I am in need of assistance with my kubernetes clusters. Everything was fine yesterday, but today after I updated my ubuntu I canā€™t get to connect to my working space to my clusters. Whenever I try to get the ā€˜kubectl get podsā€™, it appears the following message: E0706 15:32:33.989368 635117 memcache.go:265] couldnā€™t get current server API group list: Get ā€œhttps://0.0.0.0:33341/api?timeout=32sā€: EOF Any advice in how to solve this issue? Cluster information: Kubern...
  • Kubectl Cheat Sheet - 15 Kubernetes Commands & Objects Kubectl Cheat Sheet - 15 Kubernetes Commands & Objects | See the helpful list of each commonly used category or component of Kubernetes (K8S) with appropriateĀ kubectl commands for quick reference!
  • Secret token not generating - Discuss Kubernetes Secret token not generating - Discuss Kubernetes | Hi, I am new to K8s and this forum. Started to install K8s in my pc lab. I am able to open the k8s dashboard where it is asking for token and kubeconfig file, but my command is not generating any token. Below are the commands I am using: $ kubectl create serviceaccount dashboard -n default $ kubectl create clusterrolebinding dashboard-admin -n default --clusterrole=cluster-admin --serviceaccount=default:dashboard Above 2 are working fine. Below one is not generating any output : $ kubectl g...
  • What is Kubectl Get Nodes and How to Use It What is Kubectl Get Nodes and How to Use It | What does the kubectl get nodes command do? Learn how and when to run it and how to view the labels created in nodes.

Were You Able to Follow the Instructions?

šŸ˜Love it!
šŸ˜ŠYes
šŸ˜Meh-gical
šŸ˜žNo
šŸ¤®Clickbait