title: How to connect a Kubernetes cluster to and external SQL Server
body: <p>I have a running Kubernetes cluster running multiple nodes. I want to connect my application (built on .Net) to an external SQL Server.</p>
  <p>My connection string Looks like this</p>
  <pre><code>&quot;ConnectionStrings&quot;: {
      &quot;DefaultConnection&quot;: &quot;Server= 192.168.2.68; database=ArcadiaAuthenServiceDB;user id=pbts;password=exTened;MultipleActiveResultSets=True;&quot;
  },
  </code></pre>
  <p>I was able to connect to DB Environment by whitelisting each node IP to allow connection to the external SQL Server.</p>
  <p>I can successfully telnet DB IP and port.</p>
  <p>I added this <code>Server= 192.168.2.68; database=ArcadiaAuthenServiceDB;user id=pbts;password=exTened;MultipleActiveResultSets=True;</code> to configmap on K8s</p>
  <p>In my `service.YAML deployment I added the configmap as an environmental variable. And was able to connect.</p>
  <p>Instead of using configmap I'd love to use secrets, how can I achieve this?</p>
  <p>However, I know this connection isn't secured enough. What best practice can I use to achieve this connectivity.</p>
  <p>How can I ensure that I do not have to always whitelist node IP if I choose to increase k8s nodes?</p>
  <pre><code>apiVersion: v1
  kind: ConfigMap
  metadata:
    name: mssql-config
    namespace: dev
  data:
    database_uri: Server= 192.168.2.68; database=ArcadiaAuthenServiceDB;user id=pbts;password=exTened;MultipleActiveResultSets=True;
  </code></pre>
  <p>Environmental Variables</p>
  <pre><code>env:
            - name: Logging__LogLevel__Default
              value: Debug
            - name: Logging__LogLevel__Microsoft.AspNetCore
              value: Debug
            - name: ConnectionStrings__DefaultConnection
              valueFrom:
                configMapKeyRef:
                  name: mssql-config
                  key: database_uri
  </code></pre>