<p>I am trying to link together two Kubernetes Services located in different namespaces like <a href="https://stackoverflow.com/questions/37221483/service-located-in-another-namespace">this</a>. Linking them over DNS, with type ExternalName.</p>

<p>In namespace called "db" I wish to have a Deployment with a database. To be able to have 1 database that can be shared by different projects. To have one Persistent Volume.</p>

<p>But somehow it does not work like expected.</p>

<p><strong>Service inside namespace "db":</strong></p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    app: db-srv
  name: db-srv
  namespace: db
spec:
  ports:
  - name: "db-postgres"
    port: 5432
    targetPort: 5432
  selector:
    app: db
status:
  loadBalancer: {}
</code></pre>

<p><strong>Service located in "myspace"-namespace that connects to db:</strong></p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    app: myspace-db-service
  name: myspace-db-service
  namespace: myspace
spec:
  type: ExternalName
  externalName: db-srv.db.svc.cluster.local
  ports:
  - port: 5433
    # targetPort: 5432
status:
  loadBalancer: {}
</code></pre>

<p>The backend attaches to myspace-service on Port 5433.</p>

<p>Are the ports wrong?</p>

Espen Finnesand
<p>The answer is that ports on the Service with ExternalType and the Service that it connects to need to be the same. Using targetPort on the ExternalType does not work.</p>

<p><strong>This is correct:</strong>  </p>

<blockquote>
  <p>SVC(externalType) => PORT (5433) => SVC(other namespace) on PORT(5433)
  => targetPort</p>
</blockquote>

<p><strong>This is NOT correct:</strong>  </p>

<blockquote>
  <p>SVC(externalType) => PORT (5433) => TARGETPORT (5432) => SVC(other
  namespace) on PORT(5432) => targetPort</p>
</blockquote>
