Some of the common issues you might face during Openshift development are that one Pod is not able to reach another Pod. This can be because of network/security reasons, however it's important to be able to check quickly the connectivity between two Pods. Let's see how we can do it.
The list of available commands in a Linux container is usually minimal so that the container image is not bloated. So you will not probably find telnet / netcat or ping. Don't panic!
One thing you will be able to find on most container images are the curl and wget commands. Another even more powerful tool you will be able to find in every Linux based container is the python shell. Let's see how to check connectivity in both cases.
Our starting point is a set of Pods which are running say a Php image that is scaled to two Pods:
$ oc get pods NAME READY STATUS RESTARTS AGE demo-1-9qvxx 1/1 Running 0 12m demo-1-iyhfw 1/1 Running 0 6m
The first thing we will need to do, is checking the IP Address assigned to the Pods:
$ oc describe pod demo-1-9qvxx | grep IP IP: 172.17.0.2 $ oc describe pod demo-1-iyhfw | grep IP IP: 172.17.0.3
Great. Now let's launch a remote shell into one of the two Pods:
$ oc rsh demo-1-9qvxx
Let's enter now the following list of commands, which will execute Python commands from the interactive shell:
$ python Python 2.7.5 (default, Aug 2 2016, 04:20:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import socket >>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) >>> ip='172.17.0.3' >>> port= 8080 >>> s.connect((ip,port))
So, as PHP binds the server on port 8080, you should expect the above commands to complete without errors. It means that intra pod communication works! You can try varying the port and re-executing the connect command to check what happens in case you aren't able to connect to the other Pod:
>>> port= 80 >>> s.connect((ip,port)) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib64/python2.7/socket.py", line 224, in meth return getattr(self._sock,name)(*args) socket.error: [Errno 111] Connection refused
On the other hand, if you just need a simpler and less structured approach, you can just run the curl or wget command as shown here:
$ curl http://172.17.0.3:8080/index.html