A few interface rules in the integration of Traefik Consul

I use Traefik to balance the load between the various services registered in the Consul.

I use the consul-catalog configuration and redefine the external interface routing rule for one of the services, adding a tag when defining the service in the consul:

tags=['traefik.frontend.rule=PathPrefixStrip:/api,Host:api.service.consul']

I expect that /api, and will api.service.consulallow my service, however it is only /apisuccessful, however it api.service.consulreturns a 404 error.

In other words, only the first rule is considered. If I switch the tag:

tags=['traefik.frontend.rule=Host:api.service.consul,PathPrefixStrip:/api']

Then it api.servie.consulresolves, and /apireturns a 404 error.

I believe the docs suggest that this configuration is supported. Has anyone else had success in defining multiple rules using consul tags?

+8
source share
3 answers

Edit: Starting from version v1.7, for the consul directory you can use: multiple external interfaces for one service

tags=[
"traefik.frontends.foo.rule=Host:api.service.consul",
"traefik.frontends.bar.rule=PathPrefixStrip:/api",
]

The answer can be seen at https://github.com/containous/traefik/issues/2417 :

  • ,an operator OR (operating within comparison, for example Host:foo.com,bar.com)
  • ;It is the operator AND (only works between mapper, for example Host:foo.com;Path:/bar)

So for your example use:

tags=["traefik.frontend.rule=Host:api.service.consul;PathPrefixStrip:/api"]

Documentation links:

+13

this,

tags=["traefik.frontend.rule=Host:api.service.consul;PathPrefixStrip:/api"]

.

https://docs.traefik.io/basics/

https://docs.traefik.io/configuration/backends/consulcatalog/

0

[[: , , . ]], , api.server.consol/api - URL-, . , , , , ( ).

, , , Host Path, : ( )

[frontends.frontend_1.routes.rule_1]
  backend = "the_backend"
  rule = "PathPrefix:/api"

[frontends.frontend_2.routes.rule_1]
  backend = "the_backend"
  rule = "Host:api.service.consul"

. , - , ? ?:

tags=[
   'traefik.frontends.frontend_1.rule=Host:api.service.consul",
   "traefik.frontends.frontend_2.rule=PathPrefixStrip:/api']

Change The syntax above was a bit broken, and now I fixed it. The documentation is here: https://docs.traefik.io/v1.7/configuration/backends/consulcatalog/#multiple-frontends-for-a-single-service (now I see ldez in the recently edited answer).

-1
source

Source: https://habr.com/ru/post/1680932/


All Articles