worker keep logging of "waiting for db"
hedeesaa opened this issue ยท 16 comments
Description
I ran the app in kubernetes but worker pod kept logging "waiting for db"
Steps to reproduce the issue, if relevant:
just follow the steps
kubectl create namespace vote
then
kubectl create -f k8s-specifications/
then kubectl logs worker...
you will meet the error of waiting for db
Same for me.
We have to pass the environment variables while running the db container -
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: "postgres"
This solved the issue for me.
@jithinktom PR #159 added these variables to the postgres invocation, but the error persists
Same for me, even including the Postgres user and pass on db container.
As I commented in another post, I just notice that Swarm and Kubernetes deployments are not going to work because images from docker hub are not updated as predicted on this pull request. In this case, you have to build the images by yourself and change the stacks and k8s-specifications to use your own images.
To me, first I start with
docker-compose up
then break, and add to docker-compose.yml:
environment:
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: "postgres"
Next,
docker-compose down -v
And again
docker-compose -up -d
It worked to me.
Hi,
Using docker-compose the image is built when running the command as others have mentioned. However, using swarm or Kubernetes, as she is trying to do, the image is pulled from the docker hub, which is outdated.
spec:
containers:
- image: dockersamples/examplevotingapp_worker
name: workerUsing Kubernetes or swarm you have to build the image locally and change the image path accordingly until they fix it.
Best regards,
@eliezerreis thank you!
I lost a few hours on this one.
Hi @hedeesa,
I found a way to make it work, however, I needed some manual interactions.
The error appears to be in the authentication method which for some reason does not return the md5 hash properly. I'm still investigating.
Error:
FATAL: password authentication failed for user "postgres"
DETAIL: Connection matched pg_hba.conf line 95: "host all all all md5"
Workaround:
Verify your db instance in Kubernetes:
kubectl get pods -n vote | grep db
db-68c5b55955-ns5w4 1/1 Running 0 123m
Inside your pod execute those commands:
apt update && apt install vim vim /var/lib/postgresql/data/pg_hba.conf
Change line 95 to 'host all all all trust'
Ref: https://www.postgresql.org/docs/9.1/auth-methods.html
Now we need to reload postgres configurations.
Change to postgres user:
su - postgres
Execute psql:
psql
Execute this command to reload configuration:
SELECT pg_reload_conf();
If you need to close connection to psql execute:
\q[ENTER]
Now we can see in worker pod this message:
Waiting for db
Waiting for db
Waiting for db
Connected to db
Found redis at 10.96.5.47
Connecting to redis
Now I believe your Example-Voting-App works in Kubernetes.
Hope I help you. See ya
I found another way to do this configs.
Include this environment variable inside your k8s-specifictions/db-deployment.yaml:
` - name: POSTGRES_HOST_AUTH_METHOD `
` value: trust`
After changing this configuration above, postgres displays this message:
WARNING: POSTGRES_HOST_AUTH_METHOD has been set to "trust". This will allow
anyone with access to the Postgres port to access your database without
a password, even if POSTGRES_PASSWORD is set. See PostgreSQL
documentation about "trust":
https://www.postgresql.org/docs/current/auth-trust.html
In Docker's default configuration, this is effectively any other
container on the same system.
It is not recommended to use POSTGRES_HOST_AUTH_METHOD=trust. Replace
it with "-e POSTGRES_PASSWORD=password" instead to set a password in
"docker run".
Important: Use this configuration only in TEST environments and following documentation recommendations
Found the Problem !
In the Worker app the Postgresql connexion string is wrong :
replace
var pgsql = OpenDbConnection("Server=db;Username=postgres;Password=postgres;");
with
var pgsql = OpenDbConnection("Host=db;Username=postgres;Password=postgres;");
Can someone please refresh the images in dockersamples/ Docker Hub repository?
It should be pretty easy.
This is still an issue so 'Step 4: Orchestration: Swarm' of https://www.docker.com/docker-desktop/getting-started-for-windows doesn't work - the votes are not registered.
As per the title of this ticket vote_worker is constantly logging: Waiting for db
Also vote_db is constantly logging: FATAL: password authentication failed for user "postgres"
Try this env for postgres db hope this voting docker stack will work.
db:
image: postgres:9.4
environment:
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: "postgres"
volumes:
- db-data:/var/lib/postgresql/data
networks:
- backend
Hi @hedeesa,
I found a way to make it work, however, I needed some manual interactions.
The error appears to be in the authentication method which for some reason does not return the md5 hash properly. I'm still investigating.
Error:
FATAL: password authentication failed for user "postgres" DETAIL: Connection matched pg_hba.conf line 95: "host all all all md5"
Workaround:
Verify your db instance in Kubernetes:
kubectl get pods -n vote | grep dbdb-68c5b55955-ns5w4 1/1 Running 0 123mInside your pod execute those commands:
apt update && apt install vim vim /var/lib/postgresql/data/pg_hba.confChange line 95 to 'host all all all trust'
Ref: https://www.postgresql.org/docs/9.1/auth-methods.html
Now we need to reload postgres configurations.
Change to postgres user:
su - postgresExecute psql:
psqlExecute this command to reload configuration:
SELECT pg_reload_conf();If you need to close connection to psql execute:
\q[ENTER]Now we can see in worker pod this message:
Waiting for db Waiting for db Waiting for db Connected to db Found redis at 10.96.5.47 Connecting to redis
Now I believe your Example-Voting-App works in Kubernetes.
Hope I help you. See ya
apt update && apt install vim vim /var/lib/postgresql/data/pg_hba.conf
just needs to be
apt update && apt install vim && vim /var/lib/postgresql/data/pg_hba.conf
missing the && between installing VIM and running it
We're sorry for the late response. Linux images have been refreshed, cleaned up, and are now multi-platform. If you're still having issues with the latest images, feel free to reopen this ticket.