example-voting-app icon indicating copy to clipboard operation
example-voting-app copied to clipboard

worker keep logging of "waiting for db"

Open hedeesaa opened this issue 6 years ago • 15 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

hedeesaa avatar Mar 03 '20 12:03 hedeesaa

Same for me.

jithinktom avatar Mar 06 '20 07:03 jithinktom

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 avatar Mar 06 '20 12:03 jithinktom

@jithinktom PR #159 added these variables to the postgres invocation, but the error persists

azrdev avatar Mar 25 '20 16:03 azrdev

Same for me, even including the Postgres user and pass on db container.

eliezerreis avatar Apr 05 '20 16:04 eliezerreis

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.

eliezerreis avatar Apr 06 '20 01:04 eliezerreis

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.

apprenticemanxxx avatar Apr 13 '20 16:04 apprenticemanxxx

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: worker

Using Kubernetes or swarm you have to build the image locally and change the image path accordingly until they fix it.

Best regards,

eliezerreis avatar Apr 14 '20 03:04 eliezerreis

@eliezerreis thank you!

I lost a few hours on this one.

mamachanko avatar May 29 '20 10:05 mamachanko

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

cadeomontanha avatar May 31 '20 06:05 cadeomontanha

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

cadeomontanha avatar May 31 '20 07:05 cadeomontanha

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;");

seuf avatar Jul 01 '20 09:07 seuf

Can someone please refresh the images in dockersamples/ Docker Hub repository? It should be pretty easy.

ahmetb avatar Jul 08 '20 17:07 ahmetb

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"

sparrowt avatar Sep 28 '20 10:09 sparrowt

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

rajamodu avatar Jan 06 '21 10:01 rajamodu

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

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

miles3719 avatar May 13 '22 10:05 miles3719

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.

BretFisher avatar Dec 17 '22 03:12 BretFisher