Get a Kubernetes Pod IP Address

A pod is a group of containers that are running on the same host and share the same filesystem. Containers in a pod share network and IPC namespace. Pods can be created and managed by Kubernetes and deployed together on the same host or different hosts.

In this post, we will show you how to get the IP address of a Kubernetes pod in a simple and clean format without scrolling over an output.

Deploy a Pod and Get IP

Let’s go ahead and deploy a pod using the following command.

kubectl run nginx --image=nginx 

Now that the pod has been deployed, let’s get its IP address. To format the output into a clean and simple output, I’m using JSONPath Query language.

kubectl get pod nginx --output custom-columns=NAME:metadata.name,POD_IP:status.podIP 

The output is shown below.

NAME    POD_IP
nginx   10.1.0.13

Don’t forget to view the last article on the topic Deploy a Pod in Kubernetes with only One Command

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.