In Kubernetes, every administrator needs a trusty tool to navigate the complex network of nodes. Enter kubectl get nodes
, the ultimate command that unveils the secrets of your cluster.
The introduction of the kubectl get nodes
command in the Kubernetes command-line ecosystem was driven by the need for administrators and developers to retrieve information about the cluster’s nodes.
In this blog, we’ll walk you through the basics of this command, helping you gain the confidence and expertise to navigate and manage your Kubernetes environment like a pro. Get ready to take control of your clusters with ease!
We will cover:
kubectl get nodes
lists all nodes registered in a Kubernetes cluster. Each node represents a worker machine (virtual or physical) where pods run. The command shows the node name, status (e.g., Ready), roles (like control-plane), age, and Kubernetes version.
When you execute this command, it communicates with the Kubernetes API server and retrieves the necessary information from the cluster’s control plane.
The kubectl get nodes
command fetches the current state of all nodes in the cluster and displays the information in a tabular format, as shown below.
$ kubectl get nodes
Output:
NAME STATUS ROLES AGE VERSION
node-1 Ready <none> 7d v1.21.3
node-2 Ready <none> 7d v1.21.3
node-3 Ready <none> 7d v1.21.3
The output columns that are fetched are:
- NAME: The name of the node within the cluster.
- STATUS: The current status of the node, indicating whether it is ready, not ready, or unreachable.
- ROLES: Any roles assigned to the node, such as master, worker, etcd.
- AGE: The duration since the node was created or added to the cluster.
- VERSION: The Kubernetes version is running on the node.
- INTERNAL-IP: The internal IP address assigned to the node.
- EXTERNAL-IP: The external IP address assigned to the node, if applicable.
kubectl get nodes
provides a quick overview of each node’s status, roles, age, version, and readiness. This helps identify unhealthy or unreachable nodes (e.g., in NotReady
state), outdated kubelet versions, or imbalanced role assignments. Regular checks support proactive maintenance, scaling, and debugging.
In short, open a terminal where your kubeconfig is configured, and run:
kubectl get nodes
This lists all nodes in the current Kubernetes cluster, showing their names, statuses, roles, and resource details. Before running the command, make sure your kubectl
context points to the correct cluster.
However, this command has some prerequisites to satisfy.
Step 1: Install kubectl
You’ll need to install the kubectl command-line tool if you haven’t already. You can find installation instructions specific to your operating system in the official Kubernetes documentation: https://kubernetes.io/docs/tasks/tools/
Step 2: Configure kubectl
Once kubectl is installed, you must configure it to connect to your cluster. This involves specifying the address and authentication credentials of your cluster.
If you’re using a Kubernetes cluster managed by a cloud provider, you might have a configuration file such as kubeconfig available.
Step 3: Run kubectl get nodes
In the terminal or command prompt, type kubectl get nodes
and press Enter. This will execute the command and retrieve the node information from the cluster.
Step 4: Output
The command will display the node information in a tabular format, including the earlier columns (NAME, STATUS, ROLES, AGE, VERSION, INTERNAL-IP, EXTERNAL-IP). The output will show the current state of all the nodes in your cluster.
Note: Some columns mentioned above only use flags like -o wide
to the command.
$ kubectl get nodes -o wide
Output:
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION
node-1 Ready master 7d v1.21.3 192.168.1.10 <none> Ubuntu 18.04.5 LTS 4.15.0-142-generic docker://20.10.6
node-2 Ready worker 7d v1.21.3 192.168.1.11 <none> Ubuntu 18.04.5 LTS 4.15.0-142-generic docker://20.10.6
node-3 Ready worker 7d v1.21.3 192.168.1.12 <none> Ubuntu 18.04.5 LTS 4.15.0-142-generic docker://20.10.6
Kubectl helps in retrieving information in several scenarios, such as:
- Cluster overview:
kubectl get nodes
provides a quick overview of the nodes present in your Kubernetes cluster. It allows you to see each node’s current status, availability, and resource allocation. This information is useful for understanding your cluster’s overall health and capacity.
Kubernetes is a container orchestration tool that maintains a cluster of nodes. Nodes are similar to virtual machines that run our applications in a containerized form. Administrators require a command-line tool to effectively manage the cluster to obtain the node’s crucial information.
- Troubleshooting:
kubectl get nodes
can help you identify the problem that is specific to a particular node. You can check the health of the node better and analyze root causes. - Node capacity planning: If you need to plan resource allocation or capacity scaling,
kubectl get nodes
provides insights into the available resources on each node.
You can clarify how CPU and memory are allocated and how it is utilized for the current workloads. This gives you visibility and an understanding of how you can plan your future infrastructures.
- Inspecting operational state: The
kubectl get nodes
command provides an overview of the nodes’ operational state, which includes information based on their readiness, schedulability, etc. - Upgrades and maintenance: it is important to have an understanding of the current state of the nodes. This command helps us confirm whether the nodes are ready and available before initiating maintenance tasks.
Consider an environment with multiple nodes and different applications with several environments that need deployment. How will you distinguish and segregate your environments and applications in such a scenario?
Labels enable logical and physical segregation of workloads based on different environments.
For example, let’s say we have two nodes and two different environments of an application (Production and Staging) in a cluster. All you have to do is apply labels to the nodes using a command called kubectl label node key=value
.
Once labeled, you can use this in your pod configurations to distribute workloads equally.
To view the labels created in nodes, you can use the command, kubectl get nodes --show-labels=true
.
The following is an example output of how labels are displayed. Observe the last column.
$ kubectl get nodes --show-labels=true
Output:
NAME STATUS ROLES AGE VERSION LABELS
node-1 Ready <none> 1d v1.21.3 disk=ssd,environment=production
node-2 Ready <none> 1d v1.21.3 disk=hdd,environment=staging
Filtering nodes by labels using kubectl get node --selector
You can filter Kubernetes nodes by labels using the kubectl get nodes --selector
(or -l
) flag followed by the label key or key-value pair. For example:
kubectl get nodes -l node-role.kubernetes.io/worker
This command returns nodes with the label node-role.kubernetes.io/worker
, commonly used to identify worker nodes.
You can filter by multiple labels using comma separation:
kubectl get nodes -l "env=prod,tier=backend"
Advanced label selectors using operators like in
, !=
, and notin
are supported within the --selector
syntax:
kubectl get nodes --selector='env in (prod,staging)'
Use kubectl get nodes --show-labels
to display all labels on nodes for discovery and debugging. Note that --field-selector
is separate and filters based on resource fields rather than labels.
To retrieve the pods scheduled on each node in a Kubernetes cluster, you can use the kubectl get pods --all-namespaces -o wide
command.
This command fetches information about all the pods across all namespaces and includes additional details like the node on which each pod is running. You can also view this information for specific namespaces.
Here’s how you can use the command:
- Open a terminal and ensure that kubectl is installed and configured to connect to your Kubernetes cluster.
- Run the command: Enter the following command:
kubectl get pods --all-namespaces -o wide
The -o wide
option is used to display the entire information of pods (such as kubectl detele pod). It includes:
-
- Internal IP of each node (used for cluster communication)
- External IP if available (e.g., public cloud instances)
- Operating System and architecture (e.g., linux/amd64)
- Container runtime (e.g,. containerd or Docker)
- Kubelet version running on each node
- Node hostname
- Display the output: The command will display a tabular output with different columns. The NODE column indicates the node on which each pod is running.
Here’s an example of the output for the command
$ kubectl get pods -o wide
Output:
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE
default my-pod-1 1/1 Running 0 1d 10.244.0.1 node-1
default my-pod-2 1/1 Running 0 1d 10.244.0.2 node-2
kube-system kube-proxy-abcde 1/1 Running 0 1d 10.244.0.3 node-1
kube-system kube-proxy-fghij 1/1 Running 0 1d 10.244.0.4 node-2
In the example above, pods from different namespaces are listed, along with their statuses, IP addresses, and the nodes they are running on.
There are multiple use cases for using this command.
1. Monitor the status and availability of nodes in the cluster.
This displays the number of nodes and their status, whether it is ready or not. A simple kubectl get nodes
would fetch this for you. It can be used for troubleshooting purposes as well.
2. Understand the available resources on each node for capacity planning.
This is useful when you need a node’s CPU and memory details. To get this information, run the following command.
kubectl get nodes -o custom-columns=NAME:.metadata.name,CPU:.status.capacity.cpu,MEMORY:.status.capacity.memory
3. Filter nodes based on specific labels assigned to them.
If we recollect, after we enabled some labels on the nodes for better management of workloads, this is one of the most widely used use cases.
Let’s say there is an issue in the production environment, and you need to troubleshoot the node that has pods belonging to only production. This information is just one command away!
kubectl get nodes -l environment=production
Note: -l
and –labels
do the same operation
After running kubectl get nodes
, common troubleshooting steps depend on the output status of the nodes. If nodes show as NotReady
or missing, the following actions help diagnose the issue:
- Check node status and conditions – Run
kubectl describe node <node-name>
to examine conditions such asReady
,MemoryPressure
, orDiskPressure
, which can indicate resource or health issues. - Verify kubelet status – On the affected node, ensure the kubelet service is active using
systemctl status kubelet
orjournalctl -u kubelet
for logs. - Inspect network connectivity – Confirm the node can reach the control plane API server, and there are no firewall or DNS issues blocking communication.
- Check container runtime – Verify the container runtime (e.g., containerd, Docker) is running correctly, as kubelet depends on it to manage pods.
- Review CNI plugin status – Network issues often stem from misconfigured or non-functional CNI plugins. Check logs and configurations in
/etc/cni
or withkubectl get pods -n kube-system
.
If you need assistance managing your Kubernetes projects, look at Spacelift. It brings with it a GitOps flow, so your Kubernetes Deployments are synced with your Kubernetes Stacks, and pull requests show you a preview of what they’re planning to change.
To take this one step further, you could add custom policies to reinforce the security and reliability of your configurations and deployments. Spacelift provides different types of policies and workflows that are easily customizable to fit every use case. For instance, you could add plan policies to restrict or warn about security or compliance violations or approval policies to add an approval step during deployments.
You can try Spacelift for free by creating a trial account or booking a demo with one of our engineers.
kubectl get nodes
is another one amongst kubectl commands (like kubectl config set-context
) that are used to retrieve the details of nodes running in the Kubernetes cluster and their status.
Whether you need an overview of your cluster, troubleshooting assistance, capacity planning insights, or the ability to filter nodes based on specific labels, kubectl get nodes
is your go-to tool.
The most flexible CI/CD automation tool
Spacelift is an alternative to using homegrown solutions on top of a generic CI. It helps overcome common state management issues and adds several must-have capabilities for infrastructure management.