<p>We have 2 services in our cluster in the same namespace, each using their own database like below:
<a href="https://i.stack.imgur.com/whVfc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/whVfc.png" alt="enter image description here"></a></p>

<p>We added 2 ServiceEntry corresponding to each database:</p>

<pre><code>---
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: service-1
  namespace: mynamespace
spec:
  exportTo:
    - "."
  hosts:
    - service1-db.xxx.com
  ports:
    - number: 5432
      name: tcp
      protocol: tcp
  resolution: DNS
  location: MESH_EXTERNAL
...

---
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: service-2
  namespace: mynamespace
spec:
  exportTo:
    - "."
  hosts:
    - service2-db.xxx.com
  ports:
    - number: 5432
      name: tcp
      protocol: tcp
  resolution: DNS
  location: MESH_EXTERNAL
...
</code></pre>

<p>The resulting interaction looks like this, which is not expected:</p>

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

<p>Any clues on what we are missing?</p>

droidbot
<p>So, at the end, it happens that the ServiceEntry does not work just based on the host names, but it needs addresses too.</p>
<p>Here is what worked:</p>
<pre><code>---
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: service-1
  namespace: mynamespace
spec:
  exportTo:
    - &quot;.&quot;
  hosts:
    - service1-db.xxx.com
  addresses:
    - xx.xx.xx.xx/32
  ports:
    - number: 5432
      name: tcp
      protocol: tcp
  resolution: NONE
  location: MESH_EXTERNAL
...

---
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: service-2
  namespace: mynamespace
spec:
  exportTo:
    - &quot;.&quot;
  hosts:
    - service2-db.xxx.com
  addresses:
    - xx.xx.xx.yy/32
  ports:
    - number: 5432
      name: tcp
      protocol: tcp
  resolution: NONE
  location: MESH_EXTERNAL
...
</code></pre>
<p>Here are the excerpts from <a href="https://istio.io/docs/reference/config/networking/service-entry/" rel="noreferrer">the documentation</a> that led us to this conclusion.</p>
<blockquote>
<p>If the Addresses field is empty, traffic will be identified solely based on the destination port. In such scenarios, the port on which the service is being accessed must not be shared by any other service in the mesh.</p>
<p>Note that when resolution is set to type DNS and no endpoints are specified, the host field will be used as the DNS name of the endpoint to route traffic to.</p>
</blockquote>
<p>NOTE: While this helped resolve this particular instance, it opens up another different question of working with dynamic ip addresses, like some app trying to access AWS secrets manager. The ip address of such services keep changing and there is no way to tie it down to a service entry. So, we added service entries only for the known external traffic and allowed others to be unknown. In Kiali (visualiser for Istio), these &quot;unknowns&quot; are displayed as PassThroughClusters, which is annoying, but only half the problem.</p>
