nextcloud / helm

A community maintained helm chart for deploying Nextcloud on Kubernetes.
GNU Affero General Public License v3.0
295 stars 258 forks source link

Unable to configure the helm chart appropriately for preexisting empty postgres db #535

Closed dwarf-king-hreidmar closed 4 months ago

dwarf-king-hreidmar commented 4 months ago

Describe your Issue

I'm unable to get nextcloud to connect to my pre-existing postgres DB but can install psql client in the nextcloud container and connect to my postgres db with the creds I provide.

Logs and Errors

Warnings during install:

NAME: nextcloud
LAST DEPLOYED: Mon Feb 12 03:12:08 2024
NAMESPACE: nextcloud
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
#######################################################################################################
## WARNING: You did not provide an external database host in your 'helm install' call                ##
## Running Nextcloud with the integrated sqlite database is not recommended for production instances ##
#######################################################################################################

For better performance etc. you have to configure nextcloud with a resolvable database
host. To configure nextcloud to use and external database host:

1. Complete your nextcloud deployment by running:

  export APP_HOST=127.0.0.1
  export APP_PASSWORD=$(kubectl get secret --namespace nextcloud nextcloud -o jsonpath="{.data.nextcloud-password}" | base64 --decode)

  ## PLEASE UPDATE THE EXTERNAL DATABASE CONNECTION PARAMETERS IN THE FOLLOWING COMMAND AS NEEDED ##

  helm upgrade nextcloud nextcloud/nextcloud \
    --set nextcloud.password=$APP_PASSWORD,nextcloud.host=$APP_HOST,service.type=ClusterIP,mariadb.enabled=false,externalDatabase.user=nextcloud,externalDatabase.database=nextcloud,externalDatabase.host=YOUR_EXTERNAL_DATABASE_HOST

Errors:

{"reqId":"1KJixXe2hJd3ToDMtwOy","level":2,"time":"2024-02-12T02:20:33+00:00","remoteAddr":"10.244.2.8","user":"--","app":"no app in context","method":"POST","url":"/index.php","message":"Error trying to connect as \"postgres\", assuming database is setup and tables need to be created","userAgent":"Mozilla/5.0 (X11; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0","version":"28.0.1.1","exception":{"Exception":"Doctrine\\DBAL\\Exception","Message":"Failed to connect to the database: An exception occurred in the driver: SQLSTATE[08006] [7] connection to server at \"nextcloud-postgres\" (10.108.58.116), port 5432 failed: FATAL:  password authentication failed for user \"nextcloud\n\"","Code":7,"Trace":[{"file":"/var/www/html/3rdparty/doctrine/dbal/src/Connection.php","line":452,"function":"connect","class":"OC\\DB\\Connection","type":"->","args":[]},{"file":"/var/www/html/3rdparty/doctrine/dbal/src/Connection.php","line":410,"function":"getDatabasePlatformVersion","class":"Doctrine\\DBAL\\Connection","type":"->","args":[]},{"file":"/var/www/html/3rdparty/doctrine/dbal/src/Connection.php","line":317,"function":"detectDatabasePlatform","class":"Doctrine\\DBAL\\Connection","type":"->","args":[]},{"file":"/var/www/html/lib/private/DB/ConnectionAdapter.php","line":200,"function":"getDatabasePlatform","class":"Doctrine\\DBAL\\Connection","type":"->","args":[]},{"file":"/var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php","line":121,"function":"getDatabasePlatform","class":"OC\\DB\\ConnectionAdapter","type":"->","args":[]},{"file":"/var/www/html/lib/private/Setup/PostgreSQL.php","line":55,"function":"expr","class":"OC\\DB\\QueryBuilder\\QueryBuilder","type":"->","args":[]},{"file":"/var/www/html/lib/private/Setup.php","line":356,"function":"setupDatabase","class":"OC\\Setup\\PostgreSQL","type":"->","args":["$nextcloudadminuser"]},{"file":"/var/www/html/core/Controller/SetupController.php","line":68,"function":"install","class":"OC\\Setup","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/lib/base.php","line":1002,"function":"run","class":"OC\\Core\\Controller\\SetupController","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/index.php","line":39,"function":"handleRequest","class":"OC","type":"::","args":[]}],"File":"/var/www/html/lib/private/DB/Connection.php","Line":139,"message":"Error trying to connect as \"postgres\", assuming database is setup and tables need to be created","exception":{},"CustomMessage":"Error trying to connect as \"postgres\", assuming database is setup and tables need to be created"}}
{"reqId":"1KJixXe2hJd3ToDMtwOy","level":3,"time":"2024-02-12T02:20:33+00:00","remoteAddr":"10.244.2.8","user":"--","app":"no app in context","method":"POST","url":"/index.php","message":"Failed to connect to the database: An exception occurred in the driver: SQLSTATE[08006] [7] connection to server at \"nextcloud-postgres\" (10.108.58.116), port 5432 failed: FATAL:  password authentication failed for user \"nextcloud\n\"","userAgent":"Mozilla/5.0 (X11; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0","version":"28.0.1.1","exception":{"Exception":"Doctrine\\DBAL\\Exception","Message":"Failed to connect to the database: An exception occurred in the driver: SQLSTATE[08006] [7] connection to server at \"nextcloud-postgres\" (10.108.58.116), port 5432 failed: FATAL:  password authentication failed for user \"nextcloud\n\"","Code":7,"Trace":[{"file":"/var/www/html/lib/private/Setup/PostgreSQL.php","line":112,"function":"connect","class":"OC\\DB\\Connection","type":"->","args":[]},{"file":"/var/www/html/lib/private/Setup.php","line":356,"function":"setupDatabase","class":"OC\\Setup\\PostgreSQL","type":"->","args":["$nextcloudadminuser"]},{"file":"/var/www/html/core/Controller/SetupController.php","line":68,"function":"install","class":"OC\\Setup","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/lib/base.php","line":1002,"function":"run","class":"OC\\Core\\Controller\\SetupController","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/index.php","line":39,"function":"handleRequest","class":"OC","type":"::","args":[]}],"File":"/var/www/html/lib/private/DB/Connection.php","Line":139,"message":"Failed to connect to the database: An exception occurred in the driver: SQLSTATE[08006] [7] connection to server at \"nextcloud-postgres\" (10.108.58.116), port 5432 failed: FATAL:  password authentication failed for user \"nextcloud\n\"","exception":{},"CustomMessage":"Failed to connect to the database: An exception occurred in the driver: SQLSTATE[08006] [7] connection to server at \"nextcloud-postgres\" (10.108.58.116), port 5432 failed: FATAL:  password authentication failed for user \"nextcloud\n\""}}

Working on same container:

root@nextcloud-566949875f-8gbr5:/var/www/html# psql -U nextcloud -d nextcloud -h nextcloud-postgres
Password for user nextcloud:
psql (15.5 (Debian 15.5-0+deb12u1), server 15.2 (Debian 15.2-1.pgdg110+1))
Type "help" for help.

nextcloud=#

Describe your Environment

nextcloud:
  host: $fqdn
  existingSecret:
    enabled: true
    secretName: nextcloud
    usernameKey: username
    passwordKey: password

internalDatabase:
  enabled: false

externalDatabase:
  enabled: true
  type: postgresql
  existingSecret:
    enabled: true
    secretName: nextcloud
    usernameKey: dbusername
    passwordKey: dbpassword
    hostKey: host
    database: nextcloud

persistence:
  enabled: true
  existingClaim: nextcloud

Additional context, if any

I've tried both 15.2 and 16.1 postgres images I get errors about setting flags on the helm install even though i have the values set in a custom values file. I'm using this command: /opt/binaries/helm install -f nextcloud-site.yaml nextcloud nextcloud/nextcloud -n nextcloud Even if I go to the gui after initial setup it has everything filled in for me except the admin creds and the postgres user password. I can connect to this DB with the appropriate password from the container its self after using apt to install a psql client. I can see the appropriate variables set on :

provokateurin commented 4 months ago

Can you check that the values in the config.php file match your credentials? They are only set once at the start so they might not be up-to-date

dwarf-king-hreidmar commented 4 months ago

I've gone and deleted the persistent volume that I'm managing outside of this and started from scratch. I can see the proper values in the install page on the nextcloud web page after it starts up. The password I enter fails there too. I'm copying it from the same password vault I use for testing with the psql command. Still, during initial startup or when I use the web install it just fails to connect to the DB.

dwarf-king-hreidmar commented 4 months ago

I did notice this about the config.php file though and it seems off. Unclear where the newline is coming from but my env variable doesn't seem to have one. :

',  
'dbpassword' => '$MYPASSWORD  
',

Alas, even if I manually fix this and restart apache2 with apache2 graceful or apache2 restart the service still comes back up and greets me with the install screen and no password works to configure the DB on the web installer either.

dwarf-king-hreidmar commented 4 months ago

To be explicit here. I'm running my own postgres server and not using the option to use the bitnami subchart. The IP and domain names both work if I use psql client directly installed with apt on the image. In my testing I pull directly from the env variables. I also try those variables on the web installer and no dice.

Also, I never run my helm commands with the set flag as suggested because I figure thats taken care of with the custom values file. Also figure since the env variables are set and correct I shouldn't need the flag in addition. Let me know if that is not true.

dwarf-king-hreidmar commented 4 months ago

I went ahead and created my own nextcloud manifest instead of using this helm chart and everything works. Not sure whats up here but since I'm not using the helm chart anymore I'm going to close out the issue.