charts icon indicating copy to clipboard operation
charts copied to clipboard

[posgresql-ha]"Readiness probe failed" error after deployment

Open amirrezawh opened this issue 5 years ago • 8 comments

Which chart:

annotations:
  category: Database
apiVersion: v2
appVersion: 11.13.0
dependencies:
- name: common
  repository: https://charts.bitnami.com/bitnami
  version: 1.x.x
name: postgresql-ha
sources:
- https://github.com/bitnami/bitnami-docker-postgresql
- https://www.postgresql.org/
version: 7.11.0

Describe the bug Installation command that used: helm install postgresql-ha bitnami/postgresql-ha

Output of kubectl get pods:

postgresql-ha-pgpool-54b5f9d574-fjqrj              0/1     CrashLoopBackOff   9 (2m56s ago)   24m
postgresql-ha-postgresql-0                         0/1     CrashLoopBackOff   9 (4m56s ago)   24m
postgresql-ha-postgresql-1                         0/1     Running            9 (5m40s ago)   24m

Output of kubectl describe pod: 1-postgresql-ha-pgpool-54b5f9d574-fjqrj :

Warning  Unhealthy  25m  kubelet  Liveness probe failed: pgpool 14:00:37.65 INFO  ==> Checking pgpool health...
psql: FATAL:  failed to create a backend 0 connection
DETAIL:  not executing failover because failover_on_backend_error is off
  Normal   Killing    25m                kubelet  Container pgpool failed liveness probe, will be restarted
  Normal   Pulled     25m (x2 over 26m)  kubelet  Container image "docker.io/bitnami/pgpool:4.2.5-debian-10-r26" already present on machine
  Warning  Unhealthy  25m                kubelet  Readiness probe failed: psql: could not connect to server: Connection refused
           Is the server running locally and accepting
           connections on Unix domain socket "/opt/bitnami/pgpool/tmp/.s.PGSQL.5432"?
  Warning  Unhealthy  21m (x57 over 26m)  kubelet  Readiness probe failed: psql: FATAL:  failed to create a backend 0 connection
DETAIL:  not executing failover because failover_on_backend_error is off
  Warning  Unhealthy  6m47s (x55 over 24m)  kubelet  (combined from similar events): Readiness probe failed: psql: FATAL:  failed to create a backend 0 connection
DETAIL:  not executing failover because failover_on_backend_error is off
  Warning  BackOff  111s (x59 over 17m)  kubelet  Back-off restarting failed container

2-postgresql-ha-postgresql-0:

  Normal   Killing    26m                 kubelet  Container postgresql failed liveness probe, will be restarted
  Warning  Unhealthy  26m (x14 over 27m)  kubelet  Readiness probe failed: psql: could not connect to server: Connection refused
           Is the server running on host "127.0.0.1" and accepting
           TCP/IP connections on port 5432?

3-postgresql-ha-postgresql-1 :

  Warning  BackOff    8m50s (x44 over 25m)  kubelet  Back-off restarting failed container
  Warning  Unhealthy  3m46s (x77 over 28m)  kubelet  Readiness probe failed: psql: could not connect to server: Connection refused
           Is the server running on host "127.0.0.1" and accepting
           TCP/IP connections on port 5432?

Output of kubectl logs: 1-postgresql-ha-pgpool-54b5f9d574-fjqrj :

pgpool 14:27:10.10 INFO  ==> ** Starting Pgpool-II setup **
pgpool 14:27:10.16 INFO  ==> Validating settings in PGPOOL_* env vars...
pgpool 14:27:10.20 INFO  ==> Initializing Pgpool-II...
pgpool 14:27:10.21 INFO  ==> Generating pg_hba.conf file...
pgpool 14:27:10.22 INFO  ==> Generating pgpool.conf file...
pgpool 14:27:10.80 INFO  ==> Generating password file for local authentication...
pgpool 14:27:10.82 INFO  ==> Generating password file for pgpool admin user...
pgpool 14:27:10.84 INFO  ==> ** Pgpool-II setup finished! **

pgpool 14:27:10.88 INFO  ==> ** Starting Pgpool-II **
2021-10-16 14:27:10: pid 1: LOG:  Backend status file /opt/bitnami/pgpool/logs/pgpool_status does not exist
2021-10-16 14:27:10: pid 1: LOG:  health_check_stats_shared_memory_size: requested size: 12288
2021-10-16 14:27:10: pid 1: LOG:  memory cache initialized
2021-10-16 14:27:10: pid 1: DETAIL:  memcache blocks :64
2021-10-16 14:27:10: pid 1: LOG:  allocating (142699328) bytes of shared memory segment
2021-10-16 14:27:10: pid 1: LOG:  allocating shared memory segment of size: 142699328 
2021-10-16 14:27:11: pid 1: LOG:  health_check_stats_shared_memory_size: requested size: 12288
2021-10-16 14:27:11: pid 1: LOG:  health_check_stats_shared_memory_size: requested size: 12288
2021-10-16 14:27:11: pid 1: LOG:  memory cache initialized
2021-10-16 14:27:11: pid 1: DETAIL:  memcache blocks :64
2021-10-16 14:27:11: pid 1: LOG:  pool_discard_oid_maps: discarded memqcache oid maps
2021-10-16 14:27:11: pid 1: LOG:  Setting up socket for 0.0.0.0:5432
2021-10-16 14:27:11: pid 1: LOG:  Setting up socket for :::5432
2021-10-16 14:27:11: pid 1: LOG:  find_primary_node_repeatedly: waiting for finding a primary node
2021-10-16 14:27:11: pid 1: WARNING:  failed to connect to PostgreSQL server, getaddrinfo() failed with error "Name or service not known"
2021-10-16 14:27:11: pid 1: ERROR:  failed to make persistent db connection
2021-10-16 14:27:11: pid 1: DETAIL:  connection to host:"postgresql-ha-postgresql-0.postgresql-ha-postgresql-headless:5432" failed
2021-10-16 14:27:11: pid 1: LOG:  find_primary_node: make_persistent_db_connection_noerror failed on node 0
2021-10-16 14:27:11: pid 1: WARNING:  failed to connect to PostgreSQL server, getaddrinfo() failed with error "Name or service not known"

2-postgresql-ha-postgresql-0:

postgresql-repmgr 14:28:55.35 INFO  ==> Deploying PostgreSQL with persisted data...
postgresql-repmgr 14:28:55.41 INFO  ==> Configuring replication parameters
postgresql-repmgr 14:28:55.48 INFO  ==> Configuring fsync
postgresql-repmgr 14:28:55.51 INFO  ==> ** PostgreSQL with Replication Manager setup finished! **

postgresql-repmgr 14:28:55.57 INFO  ==> Starting PostgreSQL in background...
waiting for server to start....2021-10-16 14:28:55.898 GMT [150] LOG:  pgaudit extension initialized
2021-10-16 14:28:55.899 GMT [150] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2021-10-16 14:28:55.899 GMT [150] LOG:  listening on IPv6 address "::", port 5432
2021-10-16 14:28:55.995 GMT [150] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2021-10-16 14:28:56.665 GMT [150] LOG:  redirecting log output to logging collector process
2021-10-16 14:28:56.665 GMT [150] HINT:  Future log output will appear in directory "/opt/bitnami/postgresql/logs".
.2021-10-16 14:28:56.764 GMT [152] LOG:  database system was interrupted; last known up at 2021-10-16 14:23:52 GMT
.2021-10-16 14:28:58.537 GMT [152] LOG:  database system was not properly shut down; automatic recovery in progress
2021-10-16 14:28:58.630 GMT [152] LOG:  invalid record length at 0/1650250: wanted 24, got 0
2021-10-16 14:28:58.630 GMT [152] LOG:  redo is not required
.2021-10-16 14:28:59.191 GMT [150] LOG:  database system is ready to accept connections
 done
server started
2021-10-16 14:28:59.246 GMT [161] FATAL:  password authentication failed for user "postgres"
2021-10-16 14:28:59.246 GMT [161] DETAIL:  User "postgres" has no password assigned.
	Connection matched pg_hba.conf line 10: "local    all              all                    md5"
2021-10-16 14:28:59.246 GMT [161] LOG:  could not send data to client: Broken pipe
postgresql-repmgr 14:28:59.25 INFO  ==> ** Starting repmgrd **
[2021-10-16 14:28:59] [NOTICE] repmgrd (repmgrd 5.2.1) starting up
[2021-10-16 14:28:59] [ERROR] connection to database failed
[2021-10-16 14:28:59] [DETAIL] 
FATAL:  password authentication failed for user "repmgr"

3-postgresql-ha-postgresql-1:

postgresql-repmgr 14:32:00.35 INFO  ==> ** Starting PostgreSQL with Replication Manager setup **
postgresql-repmgr 14:32:00.39 INFO  ==> Validating settings in REPMGR_* env vars...
postgresql-repmgr 14:32:00.40 INFO  ==> Validating settings in POSTGRESQL_* env vars..
postgresql-repmgr 14:32:00.41 INFO  ==> Querying all partner nodes for common upstream node...
postgresql-repmgr 14:32:00.83 INFO  ==> Preparing PostgreSQL configuration...
postgresql-repmgr 14:32:00.89 INFO  ==> postgresql.conf file not detected. Generating it...
postgresql-repmgr 14:32:02.01 INFO  ==> Preparing repmgr configuration...
postgresql-repmgr 14:32:02.10 INFO  ==> Initializing Repmgr...
postgresql-repmgr 14:32:02.16 INFO  ==> Waiting for primary node...

Expected behavior This happened on two nodes (one worker and one master) running on kubernetes, but it was okay on kind's cluster locally. The problem was not solved by deleting pvc and reinstalling. I used nfs subdir external provisioner. Version of Helm and Kubernetes:

  • Output of helm version:
version.BuildInfo{Version:"v3.7.0", GitCommit:"eeac83883cb4014fe60267ec6373570374ce770b", GitTreeState:"clean", GoVersion:"go1.16.8"}

  • Output of kubectl version:
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.2", GitCommit:"8b5a19147530eaac9476b0ab82980b4088bbc1b2", GitTreeState:"clean", BuildDate:"2021-09-15T21:38:50Z", GoVersion:"go1.16.8", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.2", GitCommit:"8b5a19147530eaac9476b0ab82980b4088bbc1b2", GitTreeState:"clean", BuildDate:"2021-09-15T21:32:41Z", GoVersion:"go1.16.8", Compiler:"gc", Platform:"linux/amd64"}

amirrezawh avatar Oct 16 '21 14:10 amirrezawh

By adding a custom pg_hba.conf (changing all md5 to trusted) file, the problem will be solved. With a postgresql chart, that was so easy by adding your file in the files/ directory, but not with this chart, and I tried adding my config to values.yaml but nothing changed.

Is there any way for postgresql-ha too?

amirrezawh avatar Oct 17 '21 19:10 amirrezawh

hi @amirrezawh

In which cluster are you deploying the chart? I can not reproduce it in minikube, AWS and EKS. Maybe I am missing something.

What is the values that you are changing to deploy the chart? Did you used pgHbaConfiguration key to set up your own pg_hba.conf?

I found this case, maybe it helps you:

https://github.com/bitnami/charts/issues/1738

Thanks a lot

Álvaro

alvneiayu avatar Oct 18 '21 06:10 alvneiayu

hi @alvneiayu

Thank you for your response! The only thing I needed to do was set postgresql.pgHbaTrustAll to true. (I think this should be moved under pgHbaConfiguration in documentation)

My cluster was created with kubeadm on my own servers. I have another problem now:

postgresql-repmgr 07:17:51.62 INFO  ==> Starting PostgreSQL in background...
waiting for server to start....2021-10-18 07:17:52.137 GMT [149] LOG:  pgaudit extension initialized
2021-10-18 07:17:52.138 GMT [149] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2021-10-18 07:17:52.138 GMT [149] LOG:  listening on IPv6 address "::", port 5432
2021-10-18 07:17:52.303 GMT [149] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2021-10-18 07:17:52.940 GMT [149] LOG:  redirecting log output to logging collector process
2021-10-18 07:17:52.940 GMT [149] HINT:  Future log output will appear in directory "/opt/bitnami/postgresql/logs".
2021-10-18 07:17:53.207 GMT [151] LOG:  database system was interrupted; last known up at 2021-10-18 07:17:36 GMT
....2021-10-18 07:17:57.879 GMT [158] FATAL:  the database system is starting up
....2021-10-18 07:18:02.215 GMT [151] LOG:  database system was not properly shut down; automatic recovery in progress
2021-10-18 07:18:02.311 GMT [151] LOG:  invalid record length at 0/15695D8: wanted 24, got 0
2021-10-18 07:18:02.311 GMT [151] LOG:  redo is not required
.2021-10-18 07:18:03.145 GMT [149] LOG:  database system is ready to accept connections
 done
server started
2021-10-18 07:18:03.264 GMT [167] FATAL:  database "postgres" does not exist
postgresql-repmgr 07:18:03.27 INFO  ==> ** Starting repmgrd **
[2021-10-18 07:18:03] [NOTICE] repmgrd (repmgrd 5.2.1) starting up
2021-10-18 07:18:03.391 GMT [170] FATAL:  role "repmgr" does not exist
[2021-10-18 07:18:03] [ERROR] connection to database failed
[2021-10-18 07:18:03] [DETAIL] 
FATAL:  role "repmgr" does not exist

[2021-10-18 07:18:03] [DETAIL] attempted to connect using:
  user=repmgr password=C0eDOTBgDi connect_timeout=5 dbname=repmgr host=postgres-ha-2-postgresql-ha-postgresql-0.postgres-ha-2-postgresql-ha-postgresql-headless.default.svc.cluster.local port=5432 fallback_application_name=repmgr options=-csearch_path=

I know that I need to create "postgres" database on pod's container manually, but whenever I try to do that, Kubernetes terminates the container (or pod itself). Is there any solution for this? (I tried the postgres.database parameter, but it didn't work.)

amirrezawh avatar Oct 18 '21 07:10 amirrezawh

Problem solved by:

helm install postgres --set postgresql.pgHbaTrustAll=true\
>  --set postgresql.livenessProbe.initialDelaySeconds=600\
>  --set postgresql.readinessProbe.initialDelaySeconds=600\
>  bitnami/postgresql-ha

I will close this issue, thank you @alvneiayu

amirrezawh avatar Oct 18 '21 13:10 amirrezawh

hi @amirrezawh

Happy to hear this. You're welcome and thanks a lot for sharing your solution.

Álvaro

alvneiayu avatar Oct 18 '21 13:10 alvneiayu

Thanks @amirrezawh

Instead of 600 seconds (10 minutes) I used.

  livenessProbe:
    failureThreshold: 10
    initialDelaySeconds: 120
    periodSeconds: 60
  readinessProbe:
    failureThreshold: 10
    initialDelaySeconds: 120
    periodSeconds: 60

This allowed my nodes to come up after 2 minutes; but would keep trying for another 10 minutes.

Your post was just what I needed to get past this problem!

david618 avatar Apr 13 '22 16:04 david618

Hi, Thanks for sharing your settings.

rafariossaa avatar Apr 18 '22 07:04 rafariossaa

These settings work for my PostgreSQL HA cluster too Thank you

Ethonwu avatar Feb 20 '24 02:02 Ethonwu