title: How to connect postgresql from app using helm and kubernetes?
body: <p>I am really struggling regarding how my application which is deployed in <code>--dev namespace</code> can connect to <strong>postgreSQL</strong> database which I deployed independently using helm with <code>--database namespace</code>. What I did so far is as below.</p>
  
  <p>Database and myapp deployed different namespace. I just copy the name <code>PGHOST,PGPASSWORD</code> from some examples but I am not sure where should I use this name and is that has to be same somewhere in postgreSQL?</p>
  
  <p>Should I take care anything else to connect database or is there anything that is not best practice? Should I add a namespace to jdbc url?</p>
  
  <p>Locally we connect to database using below parameters but what should be the way after we deploy our application via helm? We are using sequelize as a client library</p>
  
  <pre><code>const connectionString = postgres://${global.config.database_username}:${global.config.database_password}@${global.config.database_host}:${global.config.database_port}/${global.config.database_name};
  </code></pre>
  
  <h2>postgres values</h2>
  
  <pre><code>## Specify PGDATABASE
  ##
  DBName: db
  </code></pre>
  
  <h2>After I deployed postgres;</h2>
  
  <pre><code>  # of replicas: 3
    service name:  my-postgres-postgresql-helm
    service port:  64000
    database name: db
    database user: admin
    jdbc url:      jdbc:postgresql://my-postgres-postgresql-helm:port
  </code></pre>
  
  <h2>deployment.yaml</h2>
  
  <pre><code>        - name: PGHOST
            valueFrom:
              configMapKeyRef:
                name: {{ .Release.Name }}-configmap
                key: jdbc-url
          - name: PGDATABASE
            value: {{ .Values.postgres.database name | quote }}
          - name: PGPASSWORD
            value: "64000"
          - name: POSTGRES_PASSWORD
            valueFrom:
              secretKeyRef:
                name: {{ template "my-mp.name" . }}
                key: POSTGRES_PASSWORD
  </code></pre>
  
  <h2>configmaps.yaml</h2>
  
  <pre><code>apiVersion: v1
  kind: ConfigMap
  metadata:
      name: {{ .Release.Name }}-configmap
      labels:
          app.kubernetes.io/name: {{ include "my-mp.name" . }}
          app.kubernetes.io/instance: {{ .Release.Name }}
          app.kubernetes.io/managed-by: {{ .Release.Service }}
          helm.sh/chart: {{ include "my-mp.chart" . }}
  data:
    jdbc-url: jdbc:postgresql://my-postgres-postgresql-helm..
  </code></pre>
  
  <h2>values.yaml</h2>
  
  <pre><code>postgres:
    service name:  my-postgres-postgresql-helm
    service port:  64000
    database name: db
    database user: admin
  </code></pre>