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

Unable to run the application in docker and K8s #1

Open
sahil-sharma opened this issue Nov 23, 2018 · 8 comments
Open

Unable to run the application in docker and K8s #1

sahil-sharma opened this issue Nov 23, 2018 · 8 comments

Comments

@sahil-sharma
Copy link

Hello,
I tried to run the application first in docker then in K8s but failed to bring the app in both the scenarios.

Docker use-case
OS: Ubuntu:16.04
Docker version: 17.12.1-ce
RAM: 4GB

Postgres container:

$ docker run --name some-postgres \
-h mypostgres \
-p 5432:5432 \
-e POSTGRES_DATABASE=url_shortener_db \
-e POSTGRES_USER=user \
-e POSTGRES_PORT=5432 \
-e POSTGRES_HOST=mypostgres \
-e POSTGRES_PASSWORD=mysecretpassword \
-d postgres

URL-Shortner app

$ docker run -d --name url-app \
-p 8080:8080 \
--link some-postgres:mypostgres \
xcoulon/go-url-shortener:0.2.0

URL-Shortner app is unable to connect to the Postgres DB as the DB is listening on localhost:5432. Despite I set the hostname of the DB container and link the DB container to the app container. Logically, it should connect to the DB over the hostname. But, the DB itslef is listening on the localhost:5432 hence connections from the outside won't be accepted. I checked the code and you've hardcoded it as "localhost".
Error:
db
Please advise how can I run the application in docker containers.

Kubernetes use-case
OS: Ubuntu:16.04
K8s cluster: 1.12 (Kubeadm single node)

I have all the YAML files.
I created secrets at first. Then I created the configmap.yaml.
Then created PV-PVC for PostgreSQL and it created successfully.

all

Then created postgres {deployment and service}. It has been created but the volumes didn't mount.

post-desc

There is no change in the YAML files. Can you please look into this?

@xcoulon
Copy link
Owner

xcoulon commented Nov 23, 2018

hello @sahil-sharma. For the Docker use-case, you will probably need to set an env variable to the webapp container to define the hostname for the Postgres DB. The localhost value that you mentioned above is a default value, but the actual value is passed by the POSTGRES_HOST env var as defined in https://github.com/xcoulon/go-url-shortener/blob/master/templates/webapp-deploymentconfig.yml#L33-L34. So in your case, that might be some-postgres.

For your k8s use case, I cannot see any error in your screenshot, am I missing something? The last event for the postgres pod is: Started Container

@sahil-sharma
Copy link
Author

Thanks for your quick response.
Yes, there is no error. That's why I am unable to wrap my head around that what could be the issue.
Usually, this is the expected behaviour:
dep
But, in my case, I am not getting any such message. I think volume is not mounted hence unable to store the data and run the app.
Any inputs. Can you try it from your end?

@xcoulon
Copy link
Owner

xcoulon commented Nov 23, 2018

@sahil-sharma can you try with the templates from 3d47f6e ? The master branch contains templates that are aimed at OpenShift deployment (ie, with some OpenShift extensions that are not available in the upstream K8s distro)

@sahil-sharma
Copy link
Author

Sure. Let me try.
I tried with docker and passing -e POSTGRES_HOST=some-postgres and got this error:
ssl

@xcoulon
Copy link
Owner

xcoulon commented Nov 23, 2018

Sure. Let me try.
I tried with docker and passing -e POSTGRES_HOST=some-postgres and got this error:
ssl

ok, I think you're missing the other env vars defined in the template: see your Connecting to Postgres database... log message, which is missing the dbname and username values. See https://github.com/xcoulon/go-url-shortener/blob/master/templates/database-deployment.yml#L17-L36

@sahil-sharma
Copy link
Author

You mean to say I have to provide all the details of Postgres the app container as it is:
POSTGRES_PASSWORD
POSTGRES_USER
POSTGRES_DATABASE
POSTGRES_PORT
POSTGRES_HOST
Is my understanding right on this? Please correct me.

@xcoulon
Copy link
Owner

xcoulon commented Nov 23, 2018

You mean to say I have to provide all the details of Postgres the app container as it is:
POSTGRES_PASSWORD
POSTGRES_USER
POSTGRES_DATABASE
POSTGRES_PORT
POSTGRES_HOST
Is my understanding right on this? Please correct me.

yes, in the Docker command to start the webapp, you need to specify those env vars. This is what the deployment config does in https://github.com/xcoulon/go-url-shortener/blob/master/templates/database-deployment.yml#L17-L36

@sahil-sharma
Copy link
Author

hello @xcoulon,

I tried to run the application using the specific templates from the commit you mentioned and it worked fine. But, I am unable to find any difference. Though the postgres pod is still showing Created container, Started container. But, the data persists. Thanks for the help!

Now, I am exploring how to configure a static/dynamic volume creation using GlusterFS/Ceph/Rook sort of. Because, the approach you used is fine when you're not scaling your DB pods. The moment we have to scale the DB then we need something similar. Is my understanding correct on this?

Let me try and if I will be able to achieve this then I will send you a PR. You can share any links which could help me to achieve this and I want to set-up monitoring and logging for this. Any inputs on this would be of great help. I can do the testing if you have something else I will try to monitor it.

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

No branches or pull requests

2 participants