<p>I have a DOTNET Core C# Console Application and i have a string for my connection string, right now, to connect to a local MySql database i use the following connection string:</p>

<pre><code>Server=127.0.0.1;Database=database;Uid=root;Pwd=123;
</code></pre>

<p>I have set up a Google Cloud SQL MySql instance and created a database there and assigned a private IP to it. I have also created a GKE cluster. I was following this documentation on connecting from GKE to Cloud SQL using private IP:</p>

<p><a href="https://cloud.google.com/sql/docs/mysql/connect-kubernetes-engine" rel="nofollow noreferrer">https://cloud.google.com/sql/docs/mysql/connect-kubernetes-engine</a></p>

<p>In that doc, it says i need 2 kubernetes secrets, 1 for the service account credentials, that i used a key generated in the Cloud SQL instance. The other is supposed to be the database credentials. How is this secret supposed to look like, and what is my connection string supposed to look like in order to use the values indicated in the secret.</p>

<p>I have tried to ignore the database credentials secret and used the connection string as it is, only changing the ip to the given private IP, thinking that, for testing purposes should be enough, but with no success. </p>

João Reis
<p>This is how i got my connectiong string:</p>

<pre><code>var dbHost     = Environment.GetEnvironmentVariable("DB_HOST");
var dbName     = Environment.GetEnvironmentVariable("DB_NAME");
var dbUser     = Environment.GetEnvironmentVariable("DB_USER");
var dbPassword = Environment.GetEnvironmentVariable("DB_PASSWORD");

string connectionString = $"server={dbHost};database={dbName};uid={dbUser};pwd={dbPassword};";
</code></pre>

<p>And use the env on the container in the deployment yml file like this:</p>

<pre><code>     env:
        - name: DB_HOST
          value: 127.0.0.1
        - name: DB_NAME
          value: name
        - name: DB_USER
          valueFrom:
            secretKeyRef:
              name: cloudsql-db-credentials
              key: username
        - name: DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: cloudsql-db-credentials
              key: password
</code></pre>

<p>And i created a generic secret with this command:</p>

<pre><code>kubectl create secret generic cloudsql-db-credentials --from-literal=username=root --from-literal=password=123
</code></pre>
