Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traefik with Consul catalog backend + Registrator #1039

Closed
mindnuts opened this issue Jan 16, 2017 · 1 comment
Closed

Traefik with Consul catalog backend + Registrator #1039

mindnuts opened this issue Jan 16, 2017 · 1 comment

Comments

@mindnuts
Copy link

mindnuts commented Jan 16, 2017

What version of Traefik are you using (traefik version)?

1.1.2 camembert

What is your environment & configuration (arguments, toml...)?

Config.toml to enable Consul Catalog backend

[consulCatalog]
endpoint = "172.17.8.101:8500"
domain = "service.consul"
prefix = "traefik"

Rules.toml (File backend which works correctly)

# rules
[backends]  
  [backends.backend2]
    [backends.backend2.maxconn]
      amount = 10
      extractorfunc = "request.host"
    [backends.backend2.LoadBalancer]
      method = "drr"
    [backends.backend2.servers.server1]
    url = "http://172.17.8.101:4040/"
    weight = 1
    [backends.backend2.servers.server2]
    url = "http://172.17.8.101:4000/"
    weight = 2

  [backends.backend3]    
    [backends.backend3.servers.server1]
    url = "http://172.17.8.101:5030/"
    weight = 1

  [backends.backend4]    
    [backends.backend4.servers.server1]
    url = "http://172.17.8.101:7050/"
    weight = 1 
  [backends.web-backend]
    [backends.web-backend.servers.server1]
      url = "http://172.17.8.101:3080/"
      weight = 1 
    [backends.web-backend.servers.server2]
      url = "http://172.17.8.101:3088/"
      weight = 1 

[frontends]  
  [frontends.frontend2]
    backend = "backend2"
    passHostHeader = true
    priority = 10    
      [frontends.frontend2.routes.test_1]
      rule = "Host:admin-ewr.com"
  

  [frontends.frontend3]
    backend = "backend3"
    passHostHeader = true    
      [frontends.frontend3.routes.path1]
      rule = "PathPrefix:/search"


  [frontends.storage]
    backend = "backend4"
    passHostHeader = true    
      [frontends.storage.routes.path1]
      rule = "Path:/files/new;Method: POST"

  [frontends.web]
    backend = "web-backend"
    passHostHeader = true    
      [frontends.web.routes.path1]
      rule = "HostRegexp:{subdomain:[a-z]+}.ewr.com"

What did you do?

Trying to get Traefik working with consul catalog backend working. The file backend works correctly. The Consul Catalog node endpoint reports the Service data correctly:

"core-01:web1:80":{
    "ID":"core-01:web1:80",
    "Service":"web",
    "Tags":[
    "traefik.frontends.web.backend=web-backend",
    "traefik.frontends.web.passHostHeader=true",
    "traefik.frontends.web.routes.path1.rule=HostRegexp:{subdomain:[a-z]+}.ewr.com",
    "traefik.backends.web-backend.servers.server1.url=http://172.17.8.101:46755/",
    "traefik.backends.web-backend.servers.server1.weight=1"
    ],
    "Address":"",
    "Port":46755,
    "EnableTagOverride":false,
    "CreateIndex":883,
    "ModifyIndex":883
}

What did you expect to see?

The path1 rule to be picked

What did you see instead?

image
Traefik route is default one instead of path1 rule

Not sure what i am doing wrong.

EDIT: Pasting the screenshot of Backend for Web and it seems it is creating the name with the tags:
image

@mindnuts
Copy link
Author

NVM..........got it working. If anyone else lands here looking for an answer here is what i did.

Below i register three instances of my "web" service with one frontend and 3 backend servers. Consul expects unique IDs for your service instances, the name does not have to be unique.

curl -X PUT -H "Content-Type: application/json" --data '{ "address": "172.17.8.101", "id" : "web1",   "Name": "web",  "Port": 46755, "Tags": [
        "traefik.frontends.web.backend=web-backend",
        "traefik.frontends.web.passHostHeader=true",
        "traefik.frontend.rule=HostRegexp:{subdomain:[a-z]+}.ewr.com",
        "traefik.backend.loadbalancer=drr",
        "traefik.backends.web-backend.servers.server1.url=http://172.17.8.101:46755/",
        "traefik.backend.weight=1"
    ]}' http://172.17.8.101:8500/v1/agent/service/register

curl -X PUT -H "Content-Type: application/json" --data '{ "address": "172.17.8.101", "id" : "web2",   "Name": "web",  "Port": 46756, "Tags": [
        "traefik.frontends.web.backend=web-backend",
        "traefik.frontends.web.passHostHeader=true",
        "traefik.frontend.rule=HostRegexp:{subdomain:[a-z]+}.ewr.com",
        "traefik.backend.loadbalancer=drr",
        "traefik.backends.web-backend.servers.server2.url=http://172.17.8.101:46756/",
        "traefik.backend.weight=1"
    ]}' http://172.17.8.101:8500/v1/agent/service/register

curl -X PUT -H "Content-Type: application/json" --data '{ "address": "172.17.8.101", "id" : "web3",   "Name": "web",  "Port": 46757, "Tags": [
        "traefik.frontends.web.backend=web-backend",
        "traefik.frontends.web.passHostHeader=true",
        "traefik.frontend.rule=HostRegexp:{subdomain:[a-z]+}.ewr.com",
        "traefik.backend.loadbalancer=drr",
        "traefik.backends.web-backend.servers.server3.url=http://172.17.8.101:46757/",
        "traefik.backend.weight=1"
    ]}' http://172.17.8.101:8500/v1/agent/service/register

Now it looks like this on Traefik dashboard, calls are sent dynamically to each of them in a round robin fashion:
image

@traefik traefik locked and limited conversation to collaborators Sep 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants