meteorhacks / meteord

MeteorD - Docker Runtime for Meteor Apps for Production Deployments
https://registry.hub.docker.com/u/meteorhacks/meteord/
MIT License
439 stars 371 forks source link

honour kubernetes env vars to build MONGO_URL #60

Closed patte closed 8 years ago

patte commented 8 years ago

I added this feature to be able to use the build docker images with kubernetes. Kubernetes automagically maintains ENV vars in pods/containers containing IP/port informations of neighboring services of the same cluster. To be able to run meteor in kubernets, the app container needs to find the IP/port of the mongo service. Because the mongo service name may vary depending of one's individual setup, I added the functionality to state the name of it and evaluate the corresponding env var set by kubernetes to connect to mongo.

As it can be seen in this issue, the kubernetes env var should be evaluated by the app. https://github.com/kubernetes/kubernetes/issues/1331

Another example of using the same strategy is the nginx example by google, using SERVICE_HOST_ENV_NAME in start.sh https://github.com/GoogleCloudPlatform/nginx-ssl-proxy/blob/master/start.sh

get the kubernetes mongo service name from K8S_MONGO_SERVICE_ENV_NAME and expand it to the resulting MONGO_URL if K8S_MONGO_DB_NAME is set, it gets appended to MONGO_URL ex. given by k8s env: MYAPP_MONGO_SERVICE_HOST="host" MYAPP_MONGO_SERVICE_PORT=27018 set in Dockerfile/controller.json K8S_MONGO_SERVICE_ENV_NAME="MYAPP_MONGO" K8S_MONGO_DB_NAME="myapp_prod" results in: MONGO_URL: mongodb://host:27018:/myapp_prod

arunoda commented 8 years ago

In k8s, you don't need to use these env vars. You can simply use the k8s service name instead of the IP.

So, I prefer to get it from outside.

patte commented 8 years ago

the idea behind these env vars is exactly that you can specify which k8s services names you want to use to build the mongo url. I use this to run staging and production meteor apps in the same k8s cluster and specify which mongo host/db to use in the docker file. I don't see another way of specifying it properly.