Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

login issue #173

Open
rbeygi opened this issue Mar 6, 2024 · 0 comments
Open

login issue #173

rbeygi opened this issue Mar 6, 2024 · 0 comments

Comments

@rbeygi
Copy link

rbeygi commented Mar 6, 2024

Hi

I've installed v1.17 and i set superuserpassword and replicapassword and config primary init script for create custom user but i can not login with postgres user and replication does not work and every time I've got below error

FATAL: password authentication failed for user "postgres"

I check the env on container and all envs are exist and several times I've tried to change pg_hba config file.
these are my files.

kind: ConfigMap
metadata:
  name: postgres-conf
  namespace: test-psql
data:
  primary_init_script.sh: |
    #!/bin/bash
    set -e

    dt=$(date '+%d/%m/%Y %H:%M:%S');
    echo "$dt - Running init script the 1st time Primary PostgreSql container is created...";

    echo "$dt - Running: psql -v ON_ERROR_STOP=1 --username $POSTGRES_USER --dbname $POSTGRES_DB ...";

    psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
    CREATE USER '$POSTGRES_MY_USERNAME' WITH PASSWORD '$POSTGRES_MY_DB_PASSWORD';
    CREATE DATABASE '$POSTGRES_MY_DB';
    \connect $POSTGRES_MY_DB';
    GRANT ALL ON SCHEMA public TO '$POSTGRES_MY_USERNAME';
    EOSQL

    echo "$dt - Init script is completed";

  backup_database.sh: |
    #!/bin/bash
    set -e

    dt=$(date '+%d/%m/%Y %H:%M:%S');
    fileDt=$(date '+%d_%m_%Y_%H_%M_%S');
    backUpFileName="$KUBEGRES_RESOURCE_NAME-backup-$fileDt.gz"
    backUpFilePath="$BACKUP_DESTINATION_FOLDER/$backUpFileName"

    echo "$dt - Starting DB backup of Kubegres resource $KUBEGRES_RESOURCE_NAME into file: $backUpFilePath";
    echo "$dt - Running: pg_dumpall -h $BACKUP_SOURCE_DB_HOST_NAME -U postgres -c | gzip > $backUpFilePath"

    pg_dumpall -h $BACKUP_SOURCE_DB_HOST_NAME -U postgres -c | gzip > $backUpFilePath

    if [ $? -ne 0 ]; then
      rm $backUpFilePath
      echo "Unable to execute a BackUp. Please check DB connection settings"
      exit 1
    fi

    echo "$dt - DB backup completed for Kubegres resource $KUBEGRES_RESOURCE_NAME into file: $backUpFilePath";

  postgres.conf: |
    # Replication configs
    listen_addresses = '*'
    max_wal_senders = 10
    # wal_keep_segments = 48 #in Mb
    max_connections = 5000
    shared_buffers = 128MB
    # Logging
    # log_destination = 'stderr,csvlog'
    # logging_collector = on
    # log_directory = 'pg_log'
    # log_filename= 'postgresql-%Y-%m-%d_%H%M%S.log'

  pg_hba.conf: |
    # TYPE  DATABASE        USER            ADDRESS                 METHOD
    # Replication connections by a user with the replication privilege
    host    replication     replication     all                     md5
    # As long as it is authenticated, all connections allowed except from "0.0.0.0/0"
    local   all             all                                     md5
    host    all             all             all                     md5
    host    all             all             0.0.0.0/0               reject

#############

kind: Secret
metadata:
  name: postgres-secret
  namespace: test-psql
type: Opaque
stringData:
  superUserPassword: "QWEqwe123"
  replicationUserPassword: "QWEqwe123"
  myDbUserPassword: "qweqweqwe"
  myDbUser: "test"
  myDbName: "test"

#########

apiVersion: kubegres.reactive-tech.io/v1
kind: Kubegres
metadata:
  name: postgresql-replica
  namespace: test-psql
spec:
  replicas: 3
  image: 'postgres:16.1'
  customConfig: postgres-conf
  failover:
    isDisabled: false
  database:
    size: 1Gi
  backup:
    schedule: '*/15 * * * *'
    pvcName: postgres-backup-pvc
    volumeMount: /var/lib/backup
  env:
    - name: POSTGRES_USER
      value: "postgres"
    - name: POSTGRES_PASSWORD
      valueFrom:
        secretKeyRef:
          name: postgres-secret
          key: superUserPassword
    - name: POSTGRES_REPLICATION_PASSWORD
      valueFrom:
        secretKeyRef:
          name: postgres-secret
          key: replicationUserPassword
    - name: POSTGRES_MY_DB_PASSWORD
      valueFrom:
        secretKeyRef:
          name: postgres-secret
          key: myDbUserPassword
    - name: POSTGRES_MY_USERNAME
      valueFrom:
        secretKeyRef:
          name: postgres-secret
          key: myDbUser
    - name: POSTGRES_MY_DB
      valueFrom:
        secretKeyRef:
          name: postgres-secret
          key: myDbName
  probe:
    livenessProbe:
      exec:
        command:
          - sh
          - '-c'
          - exec pg_isready -U postgres -h $POD_IP
      failureThreshold: 10
      initialDelaySeconds: 60
      periodSeconds: 20
      successThreshold: 1
      timeoutSeconds: 15
    readinessProbe:
      exec:
        command:
          - sh
          - '-c'
          - exec pg_isready -U postgres -h $POD_IP
      failureThreshold: 3
      initialDelaySeconds: 5
      periodSeconds: 5
      successThreshold: 1
      timeoutSeconds: 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant