helm / charts

⚠️(OBSOLETE) Curated applications for Kubernetes
Apache License 2.0
15.49k stars 16.8k forks source link

[stable/postgres] does not create user or database #9269

Closed chris-malloy-mri closed 5 years ago

chris-malloy-mri commented 5 years ago

Is this a request for help?: NO


Is this a BUG REPORT or FEATURE REQUEST? (choose one): BUG

Version of Helm and Kubernetes: Helm 2.11.0 Kubernetes 1.12

Which chart: stable/postgres

What happened: did not create user or database

What you expected to happen: create user and database

How to reproduce it (as minimally and precisely as possible):

  postgresqlUsername: exampleuser
  postgresqlPassword: examplePassword123
  postgresqlDatabase: exampledb

  service:
    type: LoadBalancer
  persistence:
    storageClass: "-"
  master:
    persistence:
        existingClaim: "existing-claim" # this is a NFS PV

  readinessProbe:
    enabled: true
  livenessProbe:
    enabled: true

  replication:
    enabled: false

Anything else we need to know: If you exec into the container and create the user and database manually everything else works well. You may also need to delete the empty volume from the volumeClaimTemplates in statefulset.yaml.

The bitnami chart for MySQL already works great. It would be nice to make this chart consistent with that one.

tompizmor commented 5 years ago

Hi,

I just installed the chart with the following command and the database and user were created:

$ helm install --name test --set postgresqlUsername=tomas,postgresqlPassword=qwer1234,postgresqlDatabase=tomasdb stable/postgresql

Checking the logs of the postgresql pod:

nami    INFO  Initializing postgresql
postgre INFO  ==> No injected postgresql.conf file found. Creating default postgresql.conf file...
postgre INFO  ==> No injected pg_hba.conf file found. Creating default pg_hba.conf file...
postgre INFO  ==> Deploying PostgreSQL from scratch...
postgre INFO  ==> Creating database tomasdb...
postgre INFO  ==> Creating user "tomas"...
postgre INFO  ==> Granting access to "tomas" to the database tomasdb...
postgre INFO  ==> Configuring PostgreSQL...
postgre INFO  ==> Configuring replication parameters...
postgre INFO  ==> Configuring permissions for config files...
postgre INFO
postgre INFO  ########################################################################
postgre INFO   Installation parameters for postgresql:
postgre INFO     User: tomas
postgre INFO     Password: **********
postgre INFO     Database: tomasdb
postgre INFO   (Passwords are not shown for security reasons)
postgre INFO  ########################################################################
postgre INFO
nami    INFO  postgresql successfully initialized

Can you share your postgresql pod log?

chris-malloy-mri commented 5 years ago

If I disable persistence as well your command works for me and creates the database:

helm install --name test --set postgresqlUsername=tomas,postgresqlPassword=qwer1234,postgresqlDatabase=tomasdb,persistence.enabled=false stable/postgresql

When I try running with my current settings for a NFS existing persistent volume claim I have the following logs:

Welcome to the Bitnami postgresql container
Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-postgresql
Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-postgresql/issues
 nami    INFO  Initializing postgresql
postgre INFO  ==> No injected postgresql.conf file found. Creating default postgresql.conf file...
postgre INFO  ==> No injected pg_hba.conf file found. Creating default pg_hba.conf file...
postgre INFO  ==> Deploying PostgreSQL with persisted data...
postgre INFO  ==> Cleaning stale postmaster.pid file...
postgre INFO  ==> Configuring PostgreSQL...
postgre INFO  ==> Configuring replication parameters...
postgre INFO  ==> Configuring permissions for config files...
postgre INFO 
postgre INFO  ########################################################################
postgre INFO   Installation parameters for postgresql:
postgre INFO     Persisted data and properties have been restored.
postgre INFO     Any input specified will not take effect.
postgre INFO   This installation requires no credentials.
postgre INFO  ########################################################################
postgre INFO 
nami    INFO  postgresql successfully initialized

I was missing some changes I made to statefulset.yaml in the OP. I removed the volume claim template and created a volume to use an existing persistent volume claim:

Remove or otherwise disable the entire volumeClaimTemplates section. Add this to the container volumes (bottom of the file):

      {{- if and .Values.persistence.enabled .Values.master.persistence.existingClaim }}
      - name: data
        persistentVolumeClaim:
            claimName: {{ .Values.master.persistence.existingClaim }}
      {{ end }}

Even though the existing persistent volume claim is just an empty folder, Postgres seems to think it is restoring an existing data folder and skips DB initialization.

tompizmor commented 5 years ago

The issue is that your PostgreSQL installation is already initialized so it is ignoring the options to create a custom database.

These options are only taking into account the first time postgresql is initialized as you can see in your pod logs:

postgre INFO  ########################################################################
postgre INFO   Installation parameters for postgresql:
postgre INFO     Persisted data and properties have been restored.
postgre INFO     Any input specified will not take effect.
postgre INFO   This installation requires no credentials.
postgre INFO  ########################################################################

I guess the fisrt time you initialize postgresql you didn't create a custom database isn't it?

chris-malloy-mri commented 5 years ago

When I run this chart the data directory for Postgres is empty. I'm not sure why it thinks it is restoring something. How do I tell Postgres to initialize?

pm-mck commented 5 years ago

I don't know if this helps at all, but I just ran into an issue where if I specified the postgresqlDatabase=postgres during the helm install, it will not create a password, despite one being provided, and will display the same

This installation requires no credentials.

message as noticed in the previous message from @tompizmor, even during the initial install.

I've nuked my pvc's and even completely wiped minikube off my machine and reinstalled the chart and I can consistently reproduce this. I think something is failing during initialization and postgresql just restarts itself and carries on like nothing is the matter. I wonder if this issue is related to the one I'm having.

As an example, this fails:

helm install --name postgres --set 'postgresqlUsername=postgres' --set 'postgresqlPassword=postgres' --set 'postgresqlDatabase=postgres' stable/postgresql

but this works

helm install --name postgres --set 'postgresqlUsername=postgres' --set 'postgresqlPassword=postgres' --set 'postgresqlDatabase=xxx' stable/postgresql
tompizmor commented 5 years ago

The first command fails because the database postgres already exists by default.

nami    INFO  Initializing postgresql
postgre INFO  ==> No injected postgresql.conf file found. Creating default postgresql.conf file...
postgre INFO  ==> No injected pg_hba.conf file found. Creating default pg_hba.conf file...
postgre INFO  ==> Deploying PostgreSQL from scratch...
postgre INFO  ==> Creating database postgres...
Error executing 'postInstallation': ERROR:  database "postgres" already exists

Regarding the initialization issue, PostgreSQL will initialize only if the PostgreSQL data dir is empty, but there is no way to force PostgreSQL to initialize. Maybe there are some hidden files inside the data directory?

pm-mck commented 5 years ago

Ah, it's actually killing the container then restarting it, I didn't look at the previous logs to see what was going on. Thanks for the advice.

tompizmor commented 5 years ago

No problem! Is there anything else I can help with?

chris-malloy-mri commented 5 years ago

I'm currently looking at the docker image for this chart. I can't figure out why it is not initializing the database when my data directory is empty.

tompizmor commented 5 years ago

Can you share the modification that you did to the templates and instructions to try to reproduce the issue on our side?

chris-malloy-mri commented 5 years ago

I've made a reproducible case: https://github.com/chris-malloy-mri/charts/commit/e4bc9e98f7b37b0f7eb3546df88e5c5cb211a440

To run it, just create the pvc with kubectl and run the previous example setting existingClaim. My NFS had the empty folder created and 777 set for permissions.


cd stable/postgresql
kubectl apply -f test-pvc.yaml
helm install --name test --set postgresqlUsername=tomas,postgresqlPassword=qwer1234,postgresqlDatabase=tomasdb,persistence.existingClaim=test-postgres-claim .```
chris-malloy-mri commented 5 years ago

Fixed in current version.

(with https://github.com/helm/charts/pull/9952 applied)

hak33m16 commented 4 years ago

Is there an easy way to tell what version this occurred in, and what version it was fixed in? I've been looking around for 10m or so to no avail