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

Script create-api-key.js can't connect to pod combined-db-0 #3049

Closed
Docteur-RS opened this issue Dec 11, 2020 · 3 comments
Closed

Script create-api-key.js can't connect to pod combined-db-0 #3049

Docteur-RS opened this issue Dec 11, 2020 · 3 comments
Labels
Milestone

Comments

@Docteur-RS
Copy link

Describe the bug
Script create-api-key.js fails with error Error: Connection terminated unexpectedly

To Reproduce
Following the documentation at how-to-create-api-key

    1. yarn install => OK
    1. kubectl port-forward combined-db-0 5432:5432 => FAIL
unable to create listener: Error listen tcp4 127.0.0.1:5432: bind: permission denied

The port 5432 can't be assigned instead I had to port foward on 8080 like this : kubectl port-forward combined-db-0 8080:5432

    1. Setting some stuff:
export POSTGRES_HOST=127.0.0.1:8080
export POSTGRES_PASSWORD=xxxxxxx (got from secret in magda namespace)
    1. yarn create-api-key -l => FAIL
      Error: getaddrinfo ENOTFOUND http://127.0.0.1:8080
      I had to edit node_modules/pg/lib/defaults.js to update the port definition to 8080.
    1. yarn create-api-key -l => FAIL
...(waiting)...
Error: Connection terminated unexpectedly

Expected behavior
Connection to pod combined-db-0 should work and list users

Desktop (please complete the following information):
WSL: Ubuntu 16.04
Magda version : 0.0.57

@Docteur-RS Docteur-RS added the bug label Dec 11, 2020
@Docteur-RS
Copy link
Author

The port-forward issue on 5432 seems to be related to my computer. But it doesn't change the fact that connection to pod combined-db-0 is being terminated.

@t83714
Copy link
Contributor

t83714 commented Dec 15, 2020

@Docteur-RS
The port-forward on 5432 issue seems a combination of windows permission & firewall issues (the Connection terminated unexpectedly might be caused by the firewall issue).

See here and here

Can you try:

  • run kubectl with sudo
  • turn off the firewall of your local computer (or add a rule forkubectl)

You can verify the DB connection using other DB admin tool. e.g.: https://www.pgadmin.org/

The POSTGRES_HOST var is only for hostname (or IP address part) and I don't think you can include "port" info there.
If you really want to use a different port, you can edit https://github.com/magda-https://github.com/magda-io/magda/blob/c167319baf1dda104b9318e4caf050c0960aaa0a/scripts/db/getDBConfig.js#L13
Instead.
Just simply add a new field port with a different value.
e.g.:

return {
        host: host ? host : "localhost",
        database: database ? database : "auth",
        user: user ? user : "postgres",
        password: password ? password : "",
        port: 8000
    };

@Docteur-RS
Copy link
Author

@t83714 Thank's for your answer.

I added the "port" field like you did and its working ! Thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants