<p>I need to make available a mysql database hosted in namespace A to an application that is deployed in namespace 'B'. </p>

<p>Thus far, I've tried a few methods, most promising of which was using a combination of Endpoint and service like so:</p>

<pre><code>kind: Service
apiVersion: v1
metadata:
  name: mysql
spec:
  ports:
    - port: 3306
      targetPort: 31234
---
kind: Endpoints
apiVersion: v1
metadata:
  name: mysql
subsets:
  - addresses:
      - ip: 12.34.567.8
    ports:
      - port: 31234
</code></pre>

<p>While one instance of a mysql container has already been spinned off in namespace 'A', and exposed at 31234 via NodePort configuration.</p>

<p>The Application has an init container, init-mysql that pings the mysql instance, with host name 'mysql' and correct credentials. 
I expected the Application to start up as usual, but it was stuck in pod initializing state. 
When I tried to check the logs of the init-mysql, I got only the following:</p>

<pre><code>Warning: Using a password on the command line interface can be insecure.
</code></pre>

<p>The commands that are in use for the initContainer 'init-mysql' are:</p>

<pre><code>          command:
            - sh
            - -c
            - 'mysqladmin ping -hmysql -P3306 -uusername -ppassword'
</code></pre>

hisdudeness
<p>This question was asked <a href="https://stackoverflow.com/questions/37221483/service-located-in-another-namespace">here</a></p>

<p>I am posting the accepted answer from Paul (community wiki) for better visibility:</p>

<blockquote>
  <p>I stumbled over the same issue and found a nice solution which does
  not need any static ip configuration:</p>
  
  <p>You can access a service via it's <a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/" rel="nofollow noreferrer">DNS name</a> (as mentioned by you):
  <em>servicename.namespace.svc.cluster.local</em></p>
  
  <p>You can use that DNS name to reference it in <a href="https://kubernetes.io/docs/concepts/services-networking/service/#services-without-selectors" rel="nofollow noreferrer">another namespace via a
  local service</a>:</p>
  
  <pre class="lang-yaml prettyprint-override"><code>kind: Service
apiVersion: v1
metadata:
  name: service-y
  namespace: namespace-a
spec:
  type: ExternalName
  externalName: service-x.namespace-b.svc.cluster.local
  ports:
  - port: 80
</code></pre>
</blockquote>
