<p>I'm using GCloud, I have a kubernate cluster and a cloud sql instance.</p>

<p>I have a simple node.js app, that uses database. When I deploy with <code>gcloud app deploy</code> it has an access to a database. However, when I build a dockerimage and expose it, it cannot reach database.</p>

<ol>
<li>I expose Docker application following: <a href="https://cloud.google.com/kubernetes-engine/docs/tutorials/hello-app" rel="nofollow noreferrer">https://cloud.google.com/kubernetes-engine/docs/tutorials/hello-app</a></li>
<li>Cloud SQL deosn't have Private IP enabled, Im connecting using cloud sql proxy</li>
<li>In app.yaml I do specify <code>base_settings:cloud_sql_instances</code>. I use the same value in <code>socketPath</code> config for mysql connection.</li>
<li><p>The error in docker logs is:</p>

<p>(node:1) UnhandledPromiseRejectionWarning: Error: connect ENOENT /cloudsql/x-alcove-224309:europe-west1:learning
    at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1097:14)</p></li>
</ol>

<p>Can you please explain me how to connect to cloud sql from dockerized node application.</p>

<p>When you deploy your app on App Engine with <code>gcloud app deploy</code>, the platform runs it in a container along with a side-car container in charge of running the cloud_sql_proxy (you ask for it by specifying the <code>base_settings:cloud_sql_instances</code> in your app.yaml file).</p>

<p>Kubernetes Engine doesn't use an app.yaml file and doesn't supply this side-car container to you so you'll have to set it up. The <a href="https://cloud.google.com/sql/docs/mysql/connect-kubernetes-engine#proxy" rel="nofollow noreferrer">public doc</a> shows how to do it by creating secrets for your database credentials and updating your deployment file with the side-car container config. An example shown in the doc would look like:</p>

<pre><code>...
- name: cloudsql-proxy
  image: gcr.io/cloudsql-docker/gce-proxy:1.11
  command: ["/cloud_sql_proxy",
            "-instances=&lt;INSTANCE_CONNECTION_NAME&gt;=tcp:3306",
            "-credential_file=/secrets/cloudsql/credentials.json"]
  securityContext:
    runAsUser: 2  # non-root user
    allowPrivilegeEscalation: false
  volumeMounts:
    - name: cloudsql-instance-credentials
      mountPath: /secrets/cloudsql
      readOnly: true
...
</code></pre>
