<p>I have a .NET Core pod that needs to access to SQL Server pod in Kubernetes(docker-desktop).
Using port forwarding I can connect to that SQL Server from SQL Server Management Studio. But when I trying to connect from .NET Core pod then it says</p>
<blockquote>
<p>The server was not found or was not accessible</p>
</blockquote>
<p>Here is the error from log</p>
<pre><code>[04:28:38 Error] Microsoft.EntityFrameworkCore.Database.Connection
An error occurred using the connection to database 'MyTestDatabase' on server 'tcp:sqlserver-service,1433'.

[04:28:38 Error] Microsoft.EntityFrameworkCore.Query
An exception occurred while iterating over the results of a query for context type 'Web.Data.ApplicationDbContext'.
Microsoft.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 40 - Could not open a connection to SQL Server)
</code></pre>
<p>My Connection String in Container</p>
<pre><code>Server=tcp:sqlserver-service,1433;User ID=sa;Password=myPass12;Initial Catalog=MyTestDatabase;MultipleActiveResultSets=true;Connection Timeout=30;
</code></pre>
<p>SQL Server deployment yml file</p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: sqldata
spec:
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteMany
  hostPath:
    path: &quot;/sqldata&quot;
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: dbclaim
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 2Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: sqlserver
spec:
  replicas: 1
  selector:
    matchLabels:
      app: sqlserver
  template:
    metadata:
      labels:
        app: sqlserver
    spec:
      volumes:
        - name: sqldata-storage
          persistentVolumeClaim:
            claimName: dbclaim
      terminationGracePeriodSeconds: 10
      initContainers:
       - name: volume-permissions
         image: busybox
         command: [&quot;sh&quot;, &quot;-c&quot;, &quot;chown -R 10001:0 /var/opt/mssql&quot;]
         volumeMounts:
         - mountPath: &quot;/var/opt/mssql&quot;
           name: sqldata-storage
      containers:
        - name: sqlserver1
          image: mcr.microsoft.com/mssql/server
          ports:
            - containerPort: 1433
          env:
            - name: MSSQL_PID
              value: &quot;Developer&quot;
            - name: SA_PASSWORD
              value: &quot;myPass12&quot;
            - name: ACCEPT_EULA
              value: &quot;Y&quot;
          volumeMounts:
          - mountPath: &quot;/var/opt/mssql/data&quot;
            name: sqldata-storage
---
apiVersion: v1
kind: Service
metadata:
  name: sqlserver-service
spec:
  ports:
  - name: sqlserver
    port: 1433
    targetPort: 1433
    protocol: TCP
  selector:
    name: sqlserver
  type: LoadBalancer
  
</code></pre>
<p>Connect from SQL Server Management Studio</p>
<p><a href="https://i.stack.imgur.com/6yrR5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6yrR5.png" alt="enter image description here" /></a></p>
<p>Surely I am missed something.</p>
<p>Thanks in advance</p>

<p>It`s my bad. Actually selector of service was wrong.</p>
<pre><code> selector:
    name: sqlserver
</code></pre>
<p>It should be</p>
<pre><code> selector:
    app: sqlserver
</code></pre>
<p>Thank you all</p>
