Postgres on Kubernetes password authentication failed

5/6/2019

I used this tutorial: https://severalnines.com/blog/using-kubernetes-deploy-postgresql

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

psql -h <publicworkernodeip> -U postgres -p <mynodeport> 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"

yamls:

apiVersion: v1
kind: ConfigMap
metadata:
  name: postgres-config
  labels:
    app: postgres
data:
  POSTGRES_DB: postgres
  POSTGRES_USER: postgres
  POSTGRES_PASSWORD: example
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
apiVersion: v1
kind: Service
metadata:
  name: postgres
  labels:
    app: postgres
spec:
  type: NodePort
  ports:
   - port: 5432
  selector:
   app: postgres
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
-- atkayla
docker
kubernetes
postgresql

1 Answer

5/7/2019

try to login using the below command

psql -h $(hostname -i) -U postgres

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=#
-- P Ekambaram
Source: StackOverflow