<p>I have tried two different applications, both consisting of a web application frontend that needs to connect to a relational database. </p>

<p>In both cases the frontend application is unable to connect to the database. In both instances the database is also running as a container (pod) in OpenShift. And the web application uses the service name as the url. Both applications have worked in other OpenShift environments.</p>

<p>Version</p>

<ul>
<li>OpenShift Master: v1.5.1+7b451fc </li>
<li>Kubernetes Master: v1.5.2+43a9be4</li>
<li>Installed using Ansible Openshift</li>
<li>Single node, with master on this node</li>
<li>Host OS: CentOS 7 Minimal</li>
</ul>

<p>I am not sure where to look in OpenShift to debug this issue. The only way I was able to reach the db pod from the web pod was using the cluster ip address.</p>

<p>In order for the internal DNS resolution to work, you need to ensure <code>dnsmasq.service</code> is running, <code>/etc/resolv.conf</code> contains the IP address of the OCP node itself instead of other DNS servers (these should be in <code>/etc/dnsmasq.d/origin-upstream-dns.conf</code>).</p>

<p>Example:</p>

<pre><code># ip a s eth0
    ...
        inet 10.0.0.1/24


# cat /etc/resolv.conf 
    ...
    nameserver 10.0.0.1
    # nameserver updated by /etc/NetworkManager/dispatcher.d/99-origin-dns.sh
</code></pre>

<p>^^ note the dispatcher script in the /etc/resolv.conf</p>

<pre><code># systemctl status dnsmasq.service
    ● dnsmasq.service - DNS caching server.
       Loaded: loaded (/usr/lib/systemd/system/dnsmasq.service; enabled; vendor preset: disabled)
       Active: active (running)


# cat /etc/dnsmasq.d/origin-dns.conf 
    no-resolv
    domain-needed
    server=/cluster.local/172.18.0.1
</code></pre>

<p>^^ this IP should be kubernetes service IP (<code>oc get svc -n default</code>)</p>

<pre><code># cat /etc/dnsmasq.d/origin-upstream-dns.conf 
    server=&lt;dns ip 1&gt;
    server=&lt;dns ip 2&gt;
</code></pre>

<p>If the OpenShift is running on some kind of OpenStack instance, AWS or similar, it might happen that <code>cloud-init</code> does not trigger the NetworkManager dispatcher script, therefore the <code>resolv.conf</code> is not modified to point to <code>dnsmasq</code>. Try to restart whole network, e.g.:</p>

<pre><code># systemctl restart network.service
</code></pre>

<p>I hope this helps.</p>
