marathon icon indicating copy to clipboard operation
marathon copied to clipboard

Simple service discovery via environment variables

Open kolloch opened this issue 11 years ago • 6 comments

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_PORT for 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>_HOST The 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...

kolloch avatar Jun 04 '15 17:06 kolloch

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 avatar Jul 27 '15 22:07 jstangroome

@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).

kolloch avatar Jul 28 '15 08:07 kolloch

Kubernetes link above moved to https://github.com/kubernetes/kubernetes/blob/master/docs/user-guide/services.md#environment-variables

air avatar Sep 14 '15 18:09 air

+1 for the feature !!!

knesenko avatar Apr 07 '16 18:04 knesenko

any update on how this could be achieved as of current versions ? Thanks

junneyang avatar Apr 11 '16 09:04 junneyang

Not in scope for marathon, there are other service discovery mechanisms with support for marathon already.

jasongilanfarr avatar Nov 23 '16 18:11 jasongilanfarr