<p>I'm trying to map an existing azure mssql server to my kubernetes cluster as a service but it seems my application cannot connect to it.</p>

<p>Here's my config file, what am I doing wrong? Maybe it's because I'm doing this on a specific namespace?</p>

<pre><code>---
apiVersion: v1
kind: Service
metadata:
  name: my-database
spec:
  type: ExternalName
  externalName: mydb.database.windows.net
</code></pre>

<p>Then, in my application, I just use the following string:</p>

<pre><code>spring.datasource.url: jdbc:sqlserver://my-database:1433;databaseName=DATABASE_DEV
</code></pre>

<p>If I use the database host, mydb.database.windows.net, everything works fine so it is not a connection problem but rather something related to my service conf...</p>

Phate
<p>A solution is to create <a href="https://kubernetes.io/docs/concepts/services-networking/service/#services-without-selectors" rel="nofollow noreferrer">Service without a selector</a>, then an <code>Endpoints</code> object for the <code>Service</code>. Similar to my answer here:
<a href="https://stackoverflow.com/questions/53433440/kubernetes-pod-unable-to-connect-to-rabbit-mq-instance-running-locally/53449625#53449625">Kubernetes pod unable to connect to rabbit mq instance running locally</a></p>

<p>Just disregard the talk about localhost...</p>
