<p>I used this tutorial: <a href="https://severalnines.com/blog/using-kubernetes-deploy-postgresql" rel="nofollow noreferrer">https://severalnines.com/blog/using-kubernetes-deploy-postgresql</a></p>

<p>With my configuration on Kubernetes which is based off the official Docker Image I keep getting:</p>

<pre><code>psql -h &lt;publicworkernodeip&gt; -U postgres -p &lt;mynodeport&gt; postgres
Password for user postgres: example
psql: FATAL:  password authentication failed for user "postgres"
DETAIL:  Role "postgres" does not exist.
Connection matched pg_hba.conf line 95: "host all all all md5"
</code></pre>

<p>yamls:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: postgres-config
  labels:
    app: postgres
data:
  POSTGRES_DB: postgres
  POSTGRES_USER: postgres
  POSTGRES_PASSWORD: example
</code></pre>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: postgres
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
        - name: postgres
          image: postgres:11
          imagePullPolicy: Always
          ports:
            - containerPort: 5432
          envFrom:
            - configMapRef:
                name: postgres-config
          volumeMounts:
            - mountPath: /var/lib/postgresql/data
              name: postgres
      volumes:
        - name: postgres
          persistentVolumeClaim:
            claimName: postgres-pv-claim
</code></pre>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: postgres
  labels:
    app: postgres
spec:
  type: NodePort
  ports:
   - port: 5432
  selector:
   app: postgres
</code></pre>

<pre><code>kind: PersistentVolume
apiVersion: v1
metadata:
  name: postgres-pv-volume
  labels:
    type: local
    app: postgres
spec:
  storageClassName: manual
  capacity:
    storage: 12Gi
  accessModes:
    - ReadWriteMany
  hostPath:
    path: "/mnt/data"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: postgres-pv-claim
  labels:
    app: postgres
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 12Gi
</code></pre>

atkayla
<p>try to login using the below command</p>

<p>psql -h $(hostname -i) -U postgres</p>

<pre><code>kubectl exec -it postgres-566fbfb87c-rcbvd sh

# env
POSTGRES_PASSWORD=example
POSTGRES_USER=postgres
POSTGRES_DB=postgres


# psql -h $(hostname -i) -U postgres
Password for user postgres:
psql (11.2 (Debian 11.2-1.pgdg90+1))
Type "help" for help.

postgres=# \c postgres
You are now connected to database "postgres" as user "postgres".
postgres=#
</code></pre>
