Simple service discovery via environment variables
Currently, service discovery has to be performed outside of Marathon, for example with mesos-dns.
Since Marathon knows about the dependencies of an app (if you specify them), we could inject which tell you where you can reach the dependencies in to the task environment.
This is similar to how kubernetes is doing this.
I propose the following for every dependency:
<NORMALIZED SERVICE PATH>_SERVICE_PORTfor the service port. That is useful if you have a HA-Proxy like setup.
And then for N tasks (maybe three) which are chosen more or less randomly
- from the healthy tasks (if they are any)
- from the running tasks (if they are any)
- from the staging tasks (if they are any)
<NORMALIZED SERVICE PATH>_<N>_HOSTThe host name of where the task is running.<NORMALIZED SERVICE PATH>_<N>_PORT<I>The i-th port of where the task is running.<NORMALIZED SERVICE PATH>_<N>_HTTP<I>The i-th port as an HTTP URL. (can we somehow only add this if the receiver speaks HTTP?)
<NORMALIZED_SERVICE_PATH> should be the capitalized app ID with any disallowed characters replaced by _.
One can furthermore consider the app itself a dependency of itself. This can be useful for applications needing seed nodes.
We should probably prefix these environment variables but they are already pretty long...
This would be useful but I'd also like to suggest exposing the Application Port of dependencies too.
Mainly because tasks can scale out and in and fail and their assigned host and port will subsequently change but the environment variables for a running process won't get updated.
However, if I understand correctly, the application port should be much more stable.
@jstangroome "Application Ports" are already in the proposal. "Service Port" is a synonym that I prefer since it is part of the API (in PortMappings).
Kubernetes link above moved to https://github.com/kubernetes/kubernetes/blob/master/docs/user-guide/services.md#environment-variables
+1 for the feature !!!
any update on how this could be achieved as of current versions ? Thanks
Not in scope for marathon, there are other service discovery mechanisms with support for marathon already.