<p>My app can't seem to connect to the proxy thus my Cloudsql Database.</p>

<p>Below are my setup:</p>

<p>my-simple-app.yaml</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    name: web
  name: web
spec:
  replicas: 2
  selector:
    matchLabels:
      name: web
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
  minReadySeconds: 5
  template:
    metadata:
      labels:
        name: web
    spec:
      nodeSelector:
        cloud.google.com/gke-nodepool: default-pool
      containers:
      - image: joelaw/nameko-hello:0.2
        name: web
        env:
          - name: DB_HOST
            value: 127.0.0.1
          - name: DB_PASSWORD
            valueFrom:
              secretKeyRef:
                name: cloudsql-db-credentials
                key: password
          - name: DB_USER
            valueFrom:
              secretKeyRef:
                name: cloudsql-db-credentials
                key: username
        ports:
        - containerPort: 3000
          name: http-server
      - image: gcr.io/cloudsql-docker/gce-proxy:1.09
        name: cloudsql-proxy
        command: ["/cloud_sql_proxy", "--dir=/cloudsql",
                  "-instances=spheric-veric-task:asia-southeast1:authdb:5432",
                  "-credential_file=/secrets/cloudsql/credentials.json"]
        volumeMounts:
          - name: cloudsql-instance-credentials
            mountPath: /secrets/cloudsql
            readOnly: true
          - name: ssl-certs
            mountPath: /etc/ssl/certs
          - name: cloudsql
            mountPath: /cloudsql
      volumes:
        - name: cloudsql-instance-credentials
          secret:
            secretName: cloudsql-instance-credentials
        - name: ssl-certs
          hostPath:
            path: /etc/ssl/certs
        - name: cloudsql
          emptyDir:
</code></pre>

<p>I had setup the secrets correctly I suppose.</p>

<p>Below are some data that I collected from the instance:</p>

<p>The pod live happily:</p>

<pre><code>web-69c7777c68-s2jt6   2/2       Running   0          9m
web-69c7777c68-zbwtv   2/2       Running   0          9m
</code></pre>

<p>When I run: <code>kubectl logs web-69c7777c68-zbwtv -c cloudsql-proxy</code></p>

<p>It recorded this:</p>

<pre><code>2019/04/04 03:25:35 using credential file for authentication; email=auth-db-user@spheric-verve-228610.iam.gserviceaccount.com
2019/04/04 03:25:35 Listening on /cloudsql/spheric-veric-task:asia-southeast1:authdb:5432/.s.PGSQL.5432 for spheric-veric-task:asia-southeast1:authdb:5432
2019/04/04 03:25:35 Ready for new connections

</code></pre>

<p>Since the app is not configured to connect to the db, what I did is to ssh into the pod with: </p>

<pre><code>kubectl exec -it web-69c7777c68-mrdpn -- /bin/bash
# Followed by installing postgresql driver:
apt-get install postgresql
# Trying to connect to cloudsql:
psql -h 127.0.0.1 -p 5432 -U
</code></pre>

<p>When I run psql in the container:</p>

<pre><code>psql: could not connect to server: Connection refused
        Is the server running on host "127.0.0.1" and accepting
        TCP/IP connections on port 5432?
</code></pre>

<p>Can anyone of you kindly advise what should I do to connect to the DB?</p>

Joe. L
<p>You are specifying the instance connection string wrong, and so the proxy is listening on a unix socket in the <code>/cloudsql/</code> directory instead of to a TCP port.</p>

<p>To tell the proxy to listen on a TCP port, use the following:</p>

<pre><code>-instances=&lt;INSTANCE_CONNECTION_NAME&gt;=tcp:5432
</code></pre>

<p>Otherwise, the following format creates a unix socket (defaulting to the <code>/cloudsql</code> directory):</p>

<pre><code>-instances=&lt;INSTANCE_CONNECTION_NAME&gt;
</code></pre>
