<h2>I have a microservices project which has:</h2>
<ul>
<li>user-service</li>
<li>post-service</li>
</ul>
<h2>Let's talk about the user-service to explain the problem:</h2>
<p>After deploying the k8s objects like deployment that contains the user image, pods are created and each pod contains the user container and the cloud-sql-proxy container in a sidecar pattern.</p>
<p>Now inside this pod, I am using Prisma inside the user container to connect to the cloud sql proxy container inside the same pod on this url: <code>postgresql://username:password@localhost/db_name?host=/cloudsql/gcp_project:us-central1:db</code></p>
<h2>Problem:</h2>
<p>When I log the user-service pod, I find this error:</p>
<p><code>Error: P1013: The provided database string is invalid. invalid port number in database URL. Please refer to the documentation in https://www.prisma.io/docs/reference/database-reference/connection-urls for constructing a correct connection string. In some cases, certain characters must be escaped. Please check the string for any illegal characters.</code></p>
<p>My Dockerfile:</p>
<pre><code>FROM node:alpine

WORKDIR /app

COPY . .

RUN npm install

# Copy the start.sh into the container
COPY start.sh .

# Make the shell script executable
RUN chmod +x start.sh

# Execute the shell script
CMD [&quot;/bin/sh&quot;, &quot;start.sh&quot;]
</code></pre>
<h3>Inside start.sh</h3>
<p>#!/bin/bash</p>
<p>cd src/</p>
<p>npx prisma db push</p>
<p>cd ..</p>
<p>npm start</p>
<p>Inside the src/ directory I have the prisma/ dir.</p>
<h3>Note: I have also tried replacing ':' with %3A in the DB string param, but it did not work.</h3>
<h2>Deployment File</h2>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: user-depl
  namespace: social-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: user
  template:
    metadata:
      labels:
        app: user
    spec:
      containers:
        - name: user
          image: &lt;image_name&gt;
          resources:
            limits:
              cpu: &quot;500m&quot;
              memory: &quot;512Mi&quot;
            requests:
              cpu: &quot;250m&quot;
              memory: &quot;256Mi&quot;
        - name: cloud-sql-proxy
          image: gcr.io/cloud-sql-connectors/cloud-sql-proxy:2.1.0
          args:
            - &quot;--structured-logs&quot;
            - &quot;--port=5432&quot;
            - &quot;PROJECT_ID:asia-south1:POSTGRES_INSTANCE_NAME&quot;
            - &quot;--credentials-file=/secrets/service_account.json&quot;

          securityContext:
            runAsNonRoot: true
          volumeMounts:
            - name: cloudsql-sa-volume
              mountPath: /secrets/
              readOnly: true
          resources:
            requests:
              memory: &quot;768Mi&quot;
              cpu: &quot;500m&quot;

      volumes:
        - name: cloudsql-sa-volume
          secret:
            secretName: cloudsql-sa

---
# Cluster IP service for user service
apiVersion: v1
kind: Service
metadata:
  name: user-srv
  namespace: social-app
spec:
  selector:
    app: user
  ports:
    - name: user
      protocol: TCP
      port: 5001
      targetPort: 5001
</code></pre>
<p>I have also checked if the cloud-sql-proxy container is running or not by logging it, and the message that it is ready for connections.</p>
<p>When I run this command: <code>npx prisma db push</code> using the shell script, I am expecting prisma to successfully connect to the cloudsql proxy container which will connect to the cloudsql instance on google cloud.</p>

John Mactavish
<p>There seems to be a bit of confusion happening here.</p>
<p>The Cloud SQL Proxy can be deployed to connect to Cloud SQL via two different options:</p>
<p>a) <a href="https://github.com/GoogleCloudPlatform/cloud-sql-proxy#configuring-port" rel="nofollow noreferrer">TCP connection over a port</a> (default)</p>
<p>b) <a href="https://github.com/GoogleCloudPlatform/cloud-sql-proxy#configuring-unix-domain-sockets" rel="nofollow noreferrer">Unix domain socket</a> (using the <code>--unix-socket</code> flag)</p>
<p>It seems as though your configuration is deploying the Cloud SQL Proxy to connect via TCP connection (using <code>--port</code>) but your application (Prisma config) is attempting to connect via a Unix socket (by using host as query param, <a href="https://www.prisma.io/docs/concepts/database-connectors/postgresql#connecting-via-sockets" rel="nofollow noreferrer">Prisma docs</a>).</p>
<p>Your deployment YAML looks fine as is to me, it should successfully setup the proxy to listen for a TCP connection on <code>127.0.0.1:5432</code> of your pod. You should be able to just update your application and Prisma URL accordingly to the following:</p>
<pre><code>postgresql://username:password@127.0.0.1:5432/db_name
</code></pre>
