Multiple providers with the same HTTP Path rule

Based on multiple providers with the same rule · Issue #9599 · traefik/traefik · GitHub I am reposting the question here for further discussion.

I'll try to explain what I have done so far and my further confusion.

What I have:

  • Traefik Proxy v 2.9.6 (also tried with 3.0.0-beta2)

  • a standalone EC2 with Trafik Proxy running on it, in the same VPC as that of the ECS cluster, and he standalone EC2 is part of the Nomad cluster.

  • an ECS service (of a simple web server for now) which desired count == 2.
    the message this services echoes in the HTML is HELLO FROM ECS.
    the ECS deployment is successful with two containers running.

  • a Nomad service which runs the same "simple web server", but with a different HTML message; HELLO FROM NOMAD.
    the Nomad service is successful with two containers running.

What I want to do:

  • clients will connect to the Traefik Proxy machine, and I want the ECS and Nomad backends to be served with equal weightage (approximate equal will also do)

What is happening:
When I start both the ECS and Nomad services, Traefik routes all HTTP requests to a single backend, the Nomad ones.
If I stop the Nomad services, then the ECS backends start to be served.

  • The Traefik Proxy's config files are as follows:

Static Configuration:

## Static configuration; traefik.yaml

global:
  checkNewVersion: false
  sendAnonymousUsage: false

entryPoints:
  web:
    address: :80

  websecure:
    address: :443

  traefik:
    address: :8080

api:
  insecure: true
  dashboard: true

pilot:
  dashboard: false

log:
  level: DEBUG

accessLog:
  format: common

providers:
  ecs:
    exposedByDefault: false
    autoDiscoverClusters: false
    clusters:
    - myecsclustername
    region: 'my-aws-region'
    ecsAnywhere: false

  consulCatalog:
    exposedByDefault: false

  nomad:
    exposedByDefault: false

  file:
    filename: dynamic_config.yaml

Dynamic Configuration:

## Dynamic configuration; dynamic_config.yaml

http:
  services:
    app:
      weighted:
        services:
        - name: service-web-scratch-ecs-web-scratch-ecs
          weight: 1
        - name: web-scratch-nomad
          weight: 1

ECS Details:

  • ECS service name: web-scratch-ecs
  • container definition name: web-scratch-ecs
  • part of container definition:
      dockerLabels = {
        "traefik.enable" : "true",
        "traefik.http.routers.myproxy.rule": "Path(`/hello`)",
        "traefik.http.routers.myproxy.priority": "1",
      }

Nomad Details:

  • Nomad service definition:
      service {
        provider = "nomad"   # I have even tried using the `consul` provider to see if that changes anything.

        name = "web-scratch-nomad"
        port = "http"
        tags = [
          "traefik.enable=true",
          "traefik.http.routers.myproxy.rule=Path(`/hello`)",
          "traefik.http.routers.myproxy.priority=1",
        ]

        check {
          name     = "health"
          type     = "http"
          path     = "/"
          interval = "30s"
          timeout  = "10s"
        }
      } # service

Note: the above configs are slightly updated since the original GitHub issue, but still not working as expected

Based on GitHub issue and the following comment multiple providers with the same rule · Issue #9599 · traefik/traefik · GitHub I have many questions :sos:

  • I am confused by "global router", how to do that? Any example?

  • Also, in the issue @ldez mentioned "services without routers", but I am completely lost as to how to do that, all examples have a router as part of the examples. :frowning_face:

At this moment, I am going round in circles, and I am now sure I am doing something fundamentally wrong in the static+dynamic config wrong to begin with.

Also, I have started to wonder if what I am asking is doable in a completely label based method using dynamic configuration.

My backends are dynamic, potentially scaling up and down from time to time, so using fixed url backend is not possible! :cry:

Do let me know if any more information is needed about the setup.

Regards,
Shantanu Gadgil

Hello @shantanugadgil,

I wouldn't create routers on your ECS/nomad service, and I would use solely the File provider.
I would use the app service you created, and I would attach a router to it that would match the rule you want. It would look something like this:

http:
  services:
    app:
      weighted:
        services:
        - name: service-web-scratch-ecs-web-scratch-ecs@ecs # <- I've used the `@ecs` form to reference services defined by the ecs provider
          weight: 1
        - name: web-scratch-nomad@nomad # <- same with `@nomad`
          weight: 1
  routers:
    app:
      service: app
      rule: Path(`/hello`)
2 Likes

Thank you @tommoulard

The configuration you showed indeed works!!!

Now the output consistently toggles between the two different messages.

Output of the while loop running curl now looks like:

...
HELLO FROM NOMAD<br>
HELLO FROM ECS<br>
HELLO FROM NOMAD<br>
HELLO FROM ECS<br>
HELLO FROM NOMAD<br>
HELLO FROM ECS<br>
...

... so I can say that this works now.

Thanks for the example, I wouldn't have been able to put together this just by reading the docs and the example within them.

For my next steps, I shall convert the file provider destination to a directory, so I can repeat the same for multiple services.
And, yes, of course, cleanup the nomenclature a bit.

Thanks again!!!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.