<p>I am configuring postgres data base and below the configuration I have created.I have pushed my docker postgres image to docker hub and I am using that container as image.In docker file I am using postgres host as <strong>db</strong> hence I have used same in my db yaml file. Already my application running in docker.Now we are moving to kubernates.How to copy exiting db data and move to kubernetes?  Above configuration is correct way to deploy pg database?</p>
<p>I am getting below error when I try to execute in database pod</p>
<pre><code>psql -U postgres -d devapp
psql: error: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket &quot;/var/run/postgresql/.s.PGSQL.5432&quot;?
</code></pre>
<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  namespace: dev-app
  name: dev-database
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: dev-database
    spec:
      nodeSelector:
        cloud.io/sec-zone-green: &quot;true&quot;
      containers:
        - name: postgres
          image:  hub.docker.net/automation/dev.postgres.1.0:latest
          env:
            - name: POSTGRES_DB
              value: devapp
            - name: POSTGRES_USER
              value: postgres
            - name: PGDATA
              value: /var/lib/postgresql/data
            - name: POSTGRES_HOST_AUTH_METHOD
              value: trust

          volumeMounts:
            - mountPath: &quot;/var/lib/postgresql/data&quot;
              name: storage-vol
          resources:
            limits:
              memory: 5Gi
              cpu: 5
            requests:
              memory: 5Gi
              cpu: 5
          ports:
            - containerPort: 5432
      volumes:
        - name: storage-vol
          persistentVolumeClaim:
            claimName: dev-nfs
</code></pre>
<p>Service</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: postgres-service
spec:
  selector:
    app: dev-database
    tier: backend
  ports:
    - protocol: TCP
      port: 5432
      targetPort: 5432
  type: NodePort
</code></pre>
<p>development yaml file</p>
<pre><code>development:
adapter: postgresql
encoding: unicode
database: devapp
username: postgres
password:
pool: 500
host: db
</code></pre>

User1984
<p>I would suggest to setup PostgresSQL in production as an external service and not in the Kubernetes cluster. Imagine in the worst case, your cluster goes down - your PostgresSQL PVC will also be gone forever and you'll not be able to retrieve back your data.</p>
<ol>
<li><p>Create PostgresSQL as an external service.</p>
</li>
<li><p>Mention the DNS of external service on which Postgres is running.</p>
</li>
</ol>
<p><strong>external-service.yml</strong></p>
<pre><code>---
apiVersion: v1
kind: Service
metadata:
  name: my-postgres-db
spec:
  type: ExternalName
  externalName: my-postgres-db-dns.xyz.io
  ports:
    - port: 5432
      targetPort: 5432
  selector:
    app: my-postgres-db
</code></pre>
