cancel
Showing results for 
Search instead for 
Did you mean: 
HansVandeweghe
Mission Specialist
Mission Specialist
  • 321 Views

chapter2 lab - Deploying Simple Applications - can't connect to postgres

Jump to solution

I'm doing the ch02s07 lab, but can't get my todo-list app to connect to the DB.

Pod logs: Could not connect to database:error: password authentication failed for user "developer"

 

When I check my posgres pod (created from the postgres (ephemeral) template), I dont see the todo_list db.

 

Screenshot From 2024-12-19 10-25-17.pngScreenshot From 2024-12-19 10-26-13.png

Anyone see what I'm doing wrong?  Screenshot From 2024-12-19 10-27-58.pngScreenshot From 2024-12-19 10-28-29.png

1 Solution

Accepted Solutions
HansVandeweghe
Mission Specialist
Mission Specialist
  • 298 Views

OK... what worked for me... editing the DeploymentConfig Environment Variables.

POSTGRESQL_USER, POSTGRESQL_PASSWORD, POSTGRESQL_DATABASE were created as secrets.  (the Secrets seem to match default values, so for example "sampledb" instead of "todo_list").

After manually setting values to :

POSTGRESQL_USER = developer

POSTGRESQL_PASSWORD = developer (not "test"  -- found correct password here: https://github.com/RedHatTraining/DO288-apps/blob/main/apps/deploy-review/todo-list/db.js)Screenshot From 2024-12-19 16-55-09.png

POSTGRESQL_DATABASE = todo_list

things seem to start work.

Hope it helps someone facing this error.

But would be interested to also hear if I was the only one seeing this. (that means I'm doing something incorrect)

View solution in original post

4 Replies
HansVandeweghe
Mission Specialist
Mission Specialist
  • 299 Views

OK... what worked for me... editing the DeploymentConfig Environment Variables.

POSTGRESQL_USER, POSTGRESQL_PASSWORD, POSTGRESQL_DATABASE were created as secrets.  (the Secrets seem to match default values, so for example "sampledb" instead of "todo_list").

After manually setting values to :

POSTGRESQL_USER = developer

POSTGRESQL_PASSWORD = developer (not "test"  -- found correct password here: https://github.com/RedHatTraining/DO288-apps/blob/main/apps/deploy-review/todo-list/db.js)Screenshot From 2024-12-19 16-55-09.png

POSTGRESQL_DATABASE = todo_list

things seem to start work.

Hope it helps someone facing this error.

But would be interested to also hear if I was the only one seeing this. (that means I'm doing something incorrect)

Ravi_Shanker
Flight Engineer
Flight Engineer
  • 271 Views

I had a similar query for DB_PASSWORD variable in the exercise. Your observation is partially correct. The application has to connect using the username and password provided in database. However in the application if no username  password is specified it takes the default mentioned in code -

 

const { Client } = require("pg"); const host = process.env.DB_HOST || "postgresql"; const user = process.env.DB_USER || "developer"; const password = process.env.DB_PASSWORD || "developer"; const database = "todo_list"; const client = new Client({ host, user, database, password }); 

While starting the application, providing the DB_PASSWORD variable with value test makes it connect with DB and the pod is created. So the correct method to solve this would be to use the test password in the application to connect to DB.

Certification ID: 111-010-393
HansVandeweghe
Mission Specialist
Mission Specialist
  • 250 Views

Out of interest, does that mean you managed to get Postgres (Ephemeral) deployed (with the custom parameters for the username, password, dbname) using the instructions from the lab solution?  

Ravi_Shanker
Flight Engineer
Flight Engineer
  • 249 Views

Yes using the details provided in the lab:

Database Service Name: postgresql

PostgreSQL Connection Username: developer

PostgreSQL Connection Password: test

PostgreSQL Database Name: todo_list

Application Name: todo-list

Application Image: registry.ocp4.example.com:8443/redhattraining/openshift-dev-deploy-review-todo-list

Certification ID: 111-010-393
Join the discussion
You must log in to join this conversation.