pgpool / pgpool2_on_k8s

57 stars 36 forks source link

Unable to authenticate to postgres #16

Closed MatteoGioioso closed 2 years ago

MatteoGioioso commented 2 years ago

I am following those docs: https://www.pgpool.net/docs/42/en/html/example-kubernetes.html

However from the pgpool logs I am having this error:

ERROR:  backend authentication failed                                                                                                                  │
DETAIL:  backend response with kind 'E' when expecting 'R'                                                                                             │
HINT:  This issue can be caused by version mismatch (current version 3)  

I am using the postgres zalando operator at its latest version, your latest image: https://hub.docker.com/r/pgpool/pgpool, and my postgres version is 12.

This is my deployment manifest:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: pgpool
spec:
  replicas: 1
  selector:
    matchLabels:
      app: pgpool
  template:
    metadata:
      labels:
        app: pgpool
    spec:
      containers:
      - name: pgpool
        image: pgpool/pgpool
        env:
        - name: PGPOOL_PARAMS_BACKEND_HOSTNAME0
          value: "acid-minimal-cluster"
        - name: PGPOOL_PARAMS_BACKEND_PORT0
          value: "5432"
        - name: PGPOOL_PARAMS_BACKEND_WEIGHT0
          value: "1"
        - name: PGPOOL_PARAMS_BACKEND_FLAG0
          value: "ALWAYS_PRIMARY|DISALLOW_TO_FAILOVER"
        - name: PGPOOL_PARAMS_BACKEND_HOSTNAME1
          value: "acid-minimal-cluster-repl"
        - name: PGPOOL_PARAMS_BACKEND_PORT1
          value: "5432"
        - name: PGPOOL_PARAMS_BACKEND_WEIGHT1
          value: "1"
        - name: PGPOOL_PARAMS_BACKEND_FLAG1
          value: "DISALLOW_TO_FAILOVER"
        - name: PGPOOL_PARAMS_FAILOVER_ON_BACKEND_ERROR
          value: "off"
        - name: POSTGRES_USERNAME
          value: "postgres"
        - name: POSTGRES_PASSWORD
          value: "somepassword"
---
apiVersion: v1
kind: Service
metadata:
  name: pgpool
spec:
  selector:
    app: pgpool
  ports:
  - name: pgpool-port
    protocol: TCP
    port: 9999
    targetPort: 9999

Those are the services that the operator expose:

NAME                          TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   
acid-minimal-cluster          ClusterIP   10.96.232.63    <none>        5432/TCP   
acid-minimal-cluster-repl     ClusterIP   10.96.120.104   <none>        5432/TCP  

If I port-forward directly to the replica service svc/acid-minimal-cluster and connect directly to postgres using that password and user it will work, however the same thing done via pgpool fails:

Any clue on what is going wrong? Thanks.

MatteoGioioso commented 2 years ago

I partially solved this by temporarily changing the pg_hba.conf:

    - local   all             all                                   trust
    - host    all             all                0.0.0.0/0          md5
    - host    all             all             127.0.0.1/32          md5
    - host    all             all                    ::0/0          md5