title: Helm Deployment: Connecting Kubernetes to Postgres DB in Cloud SQL
body: <p>So I am deploying my spring boot app using helm. I am following a pre-existing formula used by our company to try and accomplish this task, but for some reason I am unable.</p>
  
  <p>my <code>postgresql-secrets.yml</code> file contains the following</p>
  
  <pre><code>apiVersion: v1
  kind: Secret
  metadata:
    name: {{ template "codes-chart.fullname" . }}-postgresql
    labels:
      app: {{ template "codes-chart.name" . }}
      release: {{ .Release.Name }}
      heritage: {{ .Release.Service }}
  data:
    SPRING_DATASOURCE_URL: {{ .Values.secrets.springDatasourceUrl | b64enc }}
    SPRING_DATASOURCE_USERNAME: {{ .Values.secrets.springDatasourceUsername | b64enc}}
    SPRING_DATASOURCE_PASSWORD: {{ .Values.secrets.springDatasourcePassword | b64enc}}
  </code></pre>
  
  <p>This picks up the values in the values.yaml file </p>
  
  <pre><code>secrets:
     springDatasourceUrl: PLACEHOLDER
     springDatasourceUsername: PLACEHOLDER
     springDatasourcePassword: PLACEHOLDER
  </code></pre>
  
  <p>The place holders are being overwritten in helm using a variable override in the environment.</p>
  
  <p>the secrets are referenced in the <code>envFrom:</code> of the <code>codes-deployment.yaml</code></p>
  
  <pre><code>          envFrom:
              - configMapRef:
                name: {{ template "codes-chart.fullname" . }}-application
  
              - secretRef:
                name: {{ template "codes-chart.fullname" . }}-postgresql
  </code></pre>
  
  <p>my helm file structure is as follows:</p>
  
  <pre><code>|helm
  |-codes
  |--configmaps
  |---manifest
  |----manifest-codes-configmap.yaml
  |--templates
  |---application-deploy-job.yaml
  |---application-manifest-configmap.yaml
  |---application-register-job.yaml
  |---application-unregister-job.yaml
  |---codes-application-configmap.yaml
  |---codes-deployment.yaml
  |---codes-hpa.yaml
  |---codes-ingress.yaml
  |---codes-service.yaml
  |---postgresql-secret.yaml
  |--values.yaml
  |--Chart.yaml
  </code></pre>
  
  <p>The issues seems to be with the <code>SPRING_DATASOURCE_URL</code>:
  if i use the private ip of the cloudsql db, then it says it is not accepting connections</p>
  
  <p>if i use the jdbc url format:</p>
  
  <p>ex: <code>(jdbc:postgresql://google/&lt;DATABASE_NAME&gt;?cloudSqlInstance=&lt;INSTANCE_CONNECTION_NAME&gt;&amp;socketFactory=com.google.cloud.sql.postgres.SocketFactory&amp;user=&lt;POSTGRESQL_USER_NAME&gt;&amp;password=&lt;POSTGRESQL_USER_PASSWORD&gt;)</code></p>
  
  <p>then I get an 403 authentication error.</p>
  
  <p>What am I doing wrong?</p>