<p>I've two docker images, one is a webserver and the other is a backend Rest application. I deployed those images in an Openshift cluster. I want to configure my pods where the webserver is running to access the pods where the backend Rest application is running but I can't figure out how I can specify to my front-end pods that they have to communicate with my back-end service. I can only reach the pod ip but that's not what I want as I want to keep scalability advantage.</p>

<p>I tried to access it like this:</p>

<ol>
<li>via a defined route: svc-backend.router.default.svc.cluster.local</li>
<li>via his service name: svc-backend.environment.svc.cluster.local</li>
<li>via his ip adress (internal): 172.30.214.192</li>
<li>via master host + service name: master.svc-backend.environment.svc.cluster.local</li>
</ol>

<p>Nothing worked sadly. Can anyone explain to me how to communicate in openshift between pods and services?</p>

<p>The best thing you can do is deploy those 2 pods in the same project so you can keep the communication internally:</p>

<pre><code>$ oc new-project test
$ oc new-app registry:5000/frontend-image
$ oc new-app registry:5000/backend-image
</code></pre>

<p>This will automatically create a deploymentconfig and create your pod + container + a replication controller (for high availability, it will check if the pod is still running) + a service.</p>

<p>A service is an important aspect. This is actually a loadbalancer which will distribute the traffic between multiple pods. The <code>oc new-app</code> will check which ports are exposed an create a service above the ports.
So for example you can scale up your frontend pod to 3, than the service will distribute visitor1 to pod1 and another visitor to pod2 etc. A service is stable so its IP will not change. A service IP starts with 172.30.xx.xx.  So traffic sended to this IP will be forwarded to your pod(s). So for save internal network it's the best to connect services. You can connect to the service name which will be translated to the service IP. (If there is some weird case that you have to recreate your service you can create it with the same name so you don't have to change your appconfigs).</p>

<p>E.g.
I have an application which is connected with a mysql database.
In the conf of my application I'm pointing to connect with host: mysql. This is the name of the service of my MySQL. </p>

<pre><code>             connection: {
                 host: 'mysql',
                 user: 'xx-user',
                 password: 'xx',
                 database: 'db',
charset: 'utf8'
</code></pre>

<p>You can check your service:</p>

<pre><code>$ oc get svc
</code></pre>

<p>or in the webconsole</p>

<p><a href="https://i.stack.imgur.com/DCmKu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DCmKu.png" alt="enter image description here"></a></p>

<p>So for your application you have to point to the service-name of your backend. (I first have to start the database because otherwise the deployment of my app will fail because it would not find the database). So you first have to deploy your backend + create the service and point to that service name in the config of your frontend.</p>

<p>Sometimes you aren't able to keep everything internally. Than you have to create routes on your services. This will expose your service to the outside and you can communicate over routes. 
Than you have to point to those routes in your configs. The routes will be translated by the OpenShift router and the router will forward it to the right service.
Give some feedback if things aren't clear.</p>

<p><strong>EDIT 1:</strong></p>

<pre><code>nslookup mysql                                                          
Server:         172.30.0.1                                                      
Address:        172.30.0.1#53                                                   

Name:   mysql.test.svc.cluster.local                                       
Address: 172.30.195.xx   
</code></pre>

<p><strong>EDIT 2:</strong>
Start mysql in OpenShift (use ephemeral template: user=test, password=test, database=test.
Go inside your container and try to authenticate in the following way:
You'll define your user, password and host (host = servicename). This will also work with your service IP: 172.30.xxx)</p>

<pre><code>sh-4.2$ mysql -utest -ptest -hmysql                                     
Warning: Using a password on the command line interface can be insecure.        
Welcome to the MySQL monitor.  Commands end with ; or \g.                       
Your MySQL connection id is 48880                                               
Server version: 5.6.26 MySQL Community Server (GPL)                             

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.    

Oracle is a registered trademark of Oracle Corporation and/or its               
affiliates. Other names may be trademarks of their respective                   
owners.                                                                         

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  

mysql&gt; 
</code></pre>
