Fabio: Specify Consul service name in Fabio config

Created on 5 Feb 2017  路  10Comments  路  Source: fabiolb/fabio

Hi,
Can I specify the Consul service name (in addition to the tags) in Fabio.
I have been going over the properties file and the TCP+SNI example mentioned, but not able to determine
if I can specify a certain service name as well.
_* My use case being that of simple TCP or TCP+SNI_

Regards,
Shantanu

Most helpful comment

@shantanugadgil I mean that in your example above you have two fabio instances:

alb1.foo.com and alb2.foo.com both pointing to the same consul cluster ...

You want alb1 to only expose services meant for v1 apps and alb2 to only expose services for v2 apps. You can do this by setting the tag prefix on each host. From the documentation:

# registry.consul.tagprefix configures the prefix for tags which define routes.
#
# Services which define routes publish one or more tags with host/path
# routes which they serve. These tags must have this prefix to be
# recognized as routes.
#
# The default is
#
# registry.consul.tagprefix = urlprefix-

If you modify the configuration for alb1.foo.com to be registry.consul.tagprefix = alb1- and alb2.foo.com to be registry.consul.tagprefix = alb2- then you can choose which proxy advertises a service by how it is tagged.

When you register "appv1foo" you tag it alb1-/foo/ and when you register "appv2foo" you tag it alb2-/foo/. Now, when you access alb1.foo.com/foo/index.html you will be sent to the service tagged with alb1-/foo/ and when you access alb2.foo.com/foo/index.html you will be sent to the service tagged with alb2-/foo/.

Does that help?

All 10 comments

I'm not sure I understand what you mean. Can you elaborate, please?

The Consul could have multiple services registered, right?
If multiple services register the same 'tag', I think wrong backends could get pick up.

Where I am coming from is:
http://gobetween.io/documentation.html#Discovery
(ref the 'consul' section)

_* I hope I am missing something obvious in the Fabio config ?!_

Regards,
Shantanu

You can have different services using the same urlprefix tag when you are migrating one endpoint from one service to another. That's a valid use case.

To make this more explicit: It is perfectly fine to have different services A and B expose /foo if they both provide the same functionality for /foo. Only you can determine that. If they behave differently they this is most likely a mistake but there are valid use cases for this.

Closing for now. Please feel free to comment and I'll re-open if necessary.

... and I am back ...

I'll try to elaborate on my new use case. (pretty similar to the first one, but L7 this time).

I have a Nomad + Consul cluster used by dev/qa. This cluster is used to run "services" pertaining to various versions of an app.
(Lets call them appv1 and appv2)
Each team run their own version of the app outside the cluster. (minor implementation detail, not relevant to problem at hand)
Services needed by the apps run on this cluster as Docker containers; potentially multiple on a single machine.

The way the app talks to the "serivces" is via an "alb" (Fabio)

Within the cluster there are two types of machines; "alb" and "worker".
Each instance of the app will get its own "alb" instance (running Fabio) within the cluster.

The "worker" machines host services corresponding to multiple apps.
The actual services corresponding to each app instance could be run anywhere in the cluster (they are Docker containers)

Lets assume there are two albs; alb1 and alb2 (for the two versions of the same appv1 and appv2)
Each "app" has two services:
appv1foo (/foo), appv1bar (/bar)
appv2foo (/foo), appv2bar (/bar)

My problem start here; which was and is my question:

How would alb1 know that the "/foo" traffic it receives, has to be routed ONLY to Docker containers of "appv1foo" and NOT to containers of "appv2foo"

So, if the individual services were "under" a specific name, Fabio could be then configured to forward only to services of a particular name.

Thus if "appv1foo" and "appv1bar" were under a Consul service named "appv1svc", then I could configured "alb1" to forward traffic only to services under "appv1svc".
This would prevent traffic pertaining to "appv1" going to backends of "appv2"

BTW, my original need for the L4 (TCP+SNI) running quite well using Gobetween.
Gobetween does have this additional "service name" filter.

Hope this clarifies my use-case.

Regards,
Shantanu

As pointed out by Frank above, you can have a different urlprefix tag configured on each Fabio instance. You could have alb1 and alb2 instead of the default urlprefix on those instances and tag the consul services accordingly.

@leprechau
I am experimenting with the L7 thing again, and will report back if things work as I expect/want them to.

Though, I am still confused by a few things ...
You _do_ mean that there will be multiple "Fabio" instances within the same Consul cluster, right? (diverting traffic to only to the relevant services of appv1 and appv2 from the example above)

Also, I have always thought that the urlprefix tag is a backend tag thing and nothing to do with the Fabio instance itself.

Anyway, I launch multiple versions of the services and see how things fare.

Regards,
Shantanu

@shantanugadgil I mean that in your example above you have two fabio instances:

alb1.foo.com and alb2.foo.com both pointing to the same consul cluster ...

You want alb1 to only expose services meant for v1 apps and alb2 to only expose services for v2 apps. You can do this by setting the tag prefix on each host. From the documentation:

# registry.consul.tagprefix configures the prefix for tags which define routes.
#
# Services which define routes publish one or more tags with host/path
# routes which they serve. These tags must have this prefix to be
# recognized as routes.
#
# The default is
#
# registry.consul.tagprefix = urlprefix-

If you modify the configuration for alb1.foo.com to be registry.consul.tagprefix = alb1- and alb2.foo.com to be registry.consul.tagprefix = alb2- then you can choose which proxy advertises a service by how it is tagged.

When you register "appv1foo" you tag it alb1-/foo/ and when you register "appv2foo" you tag it alb2-/foo/. Now, when you access alb1.foo.com/foo/index.html you will be sent to the service tagged with alb1-/foo/ and when you access alb2.foo.com/foo/index.html you will be sent to the service tagged with alb2-/foo/.

Does that help?

Beautiful .... This should work for me.

Just happened to stumble upon another older similar issue:
https://github.com/fabiolb/fabio/issues/551

Cross posting just for reference.

@shantanugadgil Great, glad that helped.

Was this page helpful?
0 / 5 - 0 ratings