This post will illustrate methods to get Kubernetes node IP address using the following outline:
- Method 1: Get Kubernetes Node IP Address Using “kubectl get” Command
- Method 2: Get Kubernetes Node IP Address in Yaml Format
- Method 3: Get Kubernetes Node IP Address Using “kubectl describe” Command
- Method 4: Get Kubernetes Node IP Address by Accessing Node Shell
- Method 5: Get Kubernetes Node IP Address Using “kubectl debug” Command
- Method 6: Get Kubernetes Node IP Address by Accessing Container IP
- Conclusion
Method 1: Get Kubernetes Node IP Address Using “kubectl get” Command
Sometimes users are required to check the node IP address for node-to-node communication or for debugging purposes. Occasionally, the user may need to access the application running on the host machine outside the cluster. To access the node IP address in Kubernetes, the user can view the nodes list in a wide format. For demonstration, go through the following procedure.
Step 1: Start Multi-Node Cluster
To start a multi-node minikube cluster, the user needs to run Docker on the system. After that, launch the Windows PowerShell with administrative rights and execute the below command to run the multi-node minikube cluster:
Here, the minikube will automatically choose the “Docker” driver and run the cluster nodes in separate Docker containers:
Step 2: Get Node IP Address
To get the node IP address, list down the nodes in a wide format. In the below command, the “-o” option is utilized to specify the output format:
Under the “INTERNAL-IP” column, the user can view the node’s IP addresses as shown below:
Method 2: Get Kubernetes Node IP Address in Yaml Format
To get more details about the node, IP address, and hostname or to access the IP address rather than in wide format, the user can view the kubernetes node in yaml format. For this purpose, simply use the “kubectl get nodes <node-name> -o yaml” command:
Under the “addresses” key, check the node IP address and its type:
Method 3: Get Kubernetes Node IP Address Using “kubectl describe” Command
The Kubernetes describe command shows the detailed summary of Kubernetes resources such as Kubernetes node information, status, containers, and so on. To get the node IP address, the user can inspect the node and generate the detailed node summary using the “kubectl describe node <node-name>” command:
From the below output, you can view the detailed summary of Kubernetes node “multinode-m02”
Here, under the “Addresses” key, find the node IP address as well as the hostname of the node:
Method 4: Get Kubernetes Node IP Address by Accessing Node Shell
Another possible way to access the node IP address is by accessing the node interactive shell. The nodes that are running inside the minikube Kubernetes cluster and their interactive shell are accessed through the “minikube” command. After accessing the shell, the user can find the node IP address through the “ip address” command.
For illustration, follow the below instructions.
Step 1: Access Node Interactive Shell
To access the node shell of the minikube cluster, utilize the “minikube ssh -n <node-name> -p <cluster-name>” command:
In the above command, the “-n” is used to specify the node, and “-p” is defining the cluster profile name:
Step 2: Find Node IP Address
After accessing the node shell, execute the “ip address” command to fetch the node IP address:
Here, you can see we have effectively got the node IP address:
Method 5: Get Kubernetes Node IP Address Using “kubectl debug” Command?
Not every Kubernetes developer uses the minikube cluster. The above section is only applicable to the minikube cluster. To access the Node interactive shell and to find the IP address, the user can utilize the “kubectl debug” command. After accessing the shell, the user needs to access the host directory in the current shell and access the IP address through the “ip address” command. For practical demonstration, follow the listed instructions.
Step 1: Access Node Shell
The “kubectl debug” command is utilized to interact with the Kubernetes resources. To interact with Kubernetes nodes, use the “kubectl debug node/<node-name> -it –image=<debug-image-name>” command. Here, an image is required for debugging. For instance, we have utilized the “ubuntu” image:
Step 2: Access host Root Directory
After accessing the interactive shell of the Kubernetes node, access the “/host” root directory in the current shell to execute the root commands:
Step 3: Access IP Address
Now, access the IP address of the node through the given command:
The below pointed “inet” address is the IP address of “multinode-m02”:
Method 6: Get Kubernetes Node IP Address by Accessing Container IP
Most users run the Kubernetes node in Docker containers. To find the IP address of a node in Kubernetes, the user can access, and inspect the container that runs the nodes. For illustration, go through the below steps.
Step 1: Access Docker Containers
To check the running container, the user can open the Docker Desktop. From the “Containers” menu, check the running containers. To access the IP address of the node, click on the container:
Step 2: Access the IP Address
Next, navigate to the “Inspect” menu, and scroll down to the end. Here, the user can view the IP address of a node in the “IPAddress” key:
Alternatively, the user can run the “docker inspect <cont-name> | findstr “IPAddress”” command in PowerShell to access the IP address of the node running in the container:
We have covered the methods to find the Kubernetes node IP address.
Conclusion
To access the Kubernetes node IP address, the user can utilize various methods such as accessing the IP address using the “kubectl get node -o wide/yaml” command, accessing a detailed summary of a node using “kubectl describe node” command, accessing node interactive shell and executing “ip address” command. If the node is running inside the container, then the user can find the IP address by inspecting the Docker container. This post has illustrated how to get a kubernetes node IP address.