title: Kubernetes - How to Change SQL DB connection string with secret and use service hostname
body: <p>I am new to Kubernetes but I have running docker-compose which basically deploys the Catalog API and Catalog DB.</p>
  <p><strong>While working with docker-compose</strong>:</p>
  <p>I have used docker-compose.override.yaml to override the connection string from local to another container we have for the database like</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>DatabaseSettings:ConnectionString=Server=catalog,1433;Database=catalogDb;User Id=sa;Password=secretPassw@rd;</code></pre>
  </div>
  </div>
  </p>
  <p>In this sense, both the containers are working and the Catalog API container is able to connect to Catalog DB Container without any issue.</p>
  <p><strong>Now, coming to the Kubernetes</strong>:</p>
  <p>I know we have a secret and config map in Kubernetes but those are for individual item replacement by adding those into the deployment kind definition in Kubernetes.</p>
  <p>I probably can add the entire connection string as Kubernetes secret and use that as an environment but I have three questions:</p>
  <ol>
  <li>Is that a correct approach?</li>
  <li>What is the server name should I specify in Kubernetes secret?</li>
  <li>Inside a secret file, can we do string interpolation or contamination like we specific SQL Password for SQL container instance but the same password can we reference while we provide the Connection string for Catalog API without writing it the same again?</li>
  </ol>
  <p>Just give you a reference, Here is what I have created:</p>
  <p><a href="https://i.stack.imgur.com/Fc7wv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Fc7wv.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/AsjoR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AsjoR.png" alt="enter image description here" /></a></p>