There are multiple ways to get the IP address of a particular pod. One way is using kubectl describe
command as follows:
kubectl describe po nginx-776567f984-nkp9z | grep -i ip
Output:
IP: 172.17.0.14
IPs:
IP: 172.17.0.14
Type: Projected (a volume that contains injected data from multiple sources)
Another way to get the IP address is using kubectl get
command as follows:
kubectl get pods nginx-776567f984-nkp9z -o wide
Output:
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-776567f984-nkp9z 1/1 Running 0 5m16s 172.17.0.14 minikube <none> <none>
Now, let's see how to ping one pod from another. We will first get the name of all the pods that are running with nginx
image. For that, we will use the following command:
kubectl get pods -l app=frontend -o wide
Output:
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-776567f984-nkp9z 1/1 Running 0 11m 172.17.0.14 minikube <none> <none>
nginx-776567f984-w9bsl 1/1 Running 0 11m 172.17.0.12 minikube <none> <none>
Once we get all the pods, we will copy any one of the pod names and run the exec
command as follows:
kubectl exec -ti nginx-776567f984-nkp9z -- bash
Output:
root@nginx-776567f984-nkp9z:/#
Now, you are inside the pod. Let's see all the available interfaces using the ifconfig
command. I am seeing following error, so ifconfig
is not available by default in nginx
container.
bash: ifconfig: command not found
Let's install necessary packages to run ping test,
To install the
ifconfig
, run:apt update
andapt install net-tools
.To install ping, in the terminal and type:
apt install iputils-ping
.
Show ethernet interfaces:
ifconfig
Output:
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.14 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:ac:11:00:0e txqueuelen 0 (Ethernet)
RX packets 6315 bytes 9259871 (8.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1750 bytes 97053 (94.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Now, to ping one pod from another, you can use the following command. Notice from the above output we are using the IP of another pod for the ping command.
ping 172.17.0.12
Output:
PING 172.17.0.12 (172.17.0.12) 56(84) bytes of data.
64 bytes from 172.17.0.12: icmp_seq=1 ttl=64 time=0.055 ms
64 bytes from 172.17.0.12: icmp_seq=2 ttl=64 time=0.118 ms
64 bytes from 172.17.0.12: icmp_seq=3 ttl=64 time=0.117 ms
Top comments (0)