The service "myService@file" does not exist

Hello. I'm on Traefik 2.0.1. Not sure what I'm doing wrong here. I have this dynamic configuration:

http:
  routers:
    router0:
      entryPoints:
      - web
      middlewares:
      - httpsRedirect
      service: myService
      rule: Host(`example.com`)
    router1:
      entryPoints:
      - webSecure
      service: myService
      rule: Host(`example.com`)
      tls:
        options: default
    middlewares:
      httpsRedirect:
        redirectScheme:
          scheme: https
    services:
      myService:
        loadBalancer:
          servers:
          - url: http://localhost:8080

But, I'm getting these errors on startup:

"entryPointName":"web","msg":"the service \"myService@file\" does not exist","routerName":"router0@file"
"entryPointName":"webSecure","msg":"the service \"myService@file\" does not exist","routerName":"router1@file"

However, you can clearly see that myService is defined in the services block. What am I missing?

Hello,

It's aYAML issue: the indentation of the blocks middlewares and services is wrong.

http:
  routers:
    router0:
      entryPoints:
        - web
      middlewares:
        - httpsRedirect
      service: myService
      rule: Host(`example.com`)
    router1:
      entryPoints:
        - webSecure
      service: myService
      rule: Host(`example.com`)
      tls:
        options: default

  middlewares:
    httpsRedirect:
      redirectScheme:
        scheme: https

  services:
    myService:
      loadBalancer:
        servers:
          - url: http://localhost:8080
1 Like

Hm... I updated my dynamic config to this:

http:
  routers:
    router0:
      entryPoints:
        - web
      middlewares:
        - httpsRedirect
      service: myService
      rule: Host(`example.com`)
    router1:
      entryPoints:
        - webSecure
      service: myService
      rule: Host(`example.com`)
      tls:
        options: default
    middlewares:
      httpsRedirect:
        redirectScheme:
          scheme: https
    services:
      myService:
        loadBalancer:
          servers:
            - url: http://localhost:8080

I added two mores spaces to entryPoints, middlewares, and servers.

But, still getting:

"entryPointName":"web","msg":"the service \"myService@file\" does not exist","routerName":"router0@file"
"entryPointName":"webSecure","msg":"the service \"myService@file\" does not exist","routerName":"router1@file"

I used some online YAML to TOML converter, maybe someone can spot something wrong in the TOML?

[http]
  [http.routers]
    [http.routers.router0]
    entryPoints = [ "web" ]
    middlewares = [ "httpsRedirect" ]
    service = "myService"
    rule = "Host(`example.com`)"

    [http.routers.router1]
    entryPoints = [ "webSecure" ]
    service = "myService"
    rule = "Host(`example.com`)"
      [http.routers.router1.tls]
      options = "default"

    [http.routers.middlewares]
      [http.routers.middlewares.httpsRedirect]
        [http.routers.middlewares.httpsRedirect.redirectScheme]
        scheme = "https"

    [http.routers.services]
      [http.routers.services.myService]
        [http.routers.services.myService.loadBalancer]
          [[http.routers.services.myService.loadBalancer.servers]]
          url = "http://localhost:8080"

Also, I think the two spaces don't matter.

image

It appears that

foo:
- one
- two
- three

bar:
  - one
  - two
  - three

are equivalent.

I repeat: it's YAML indentation issue: routers, middlewares and services must be at the same level:

http:
  routers:
    router0:
      entryPoints:
        - web
      middlewares:
        - httpsRedirect
      service: myService
      rule: Host(`example.com`)
    router1:
      entryPoints:
        - webSecure
      service: myService
      rule: Host(`example.com`)
      tls:
        options: default
  middlewares:
    httpsRedirect:
      redirectScheme:
        scheme: https
  services:
    myService:
      loadBalancer:
        servers:
          - url: http://localhost:8080

TOML is not indentation based (i.e. the indentation is not used)

[http.routers.router0]
  entryPoints = ["web"]
  middlewares = ["httpsRedirect"]
  service = "myService"
  rule = "Host(`example.com`)"

[http.routers.router1]
  entryPoints = ["webSecure"]
  service = "myService"
  rule = "Host(`example.com`)"

  [http.routers.router1.tls]
    options = "default"

[http.middlewares.httpsRedirect.redirectScheme]
  scheme = "https"

[http.services.myService.loadBalancer]
  [[http.services.myService.loadBalancer.servers]]
    url = "http://localhost:8080"

Aaaah, yep. That's what it was! Thanks!! I had services under routers, when it should have been on the same level. Just like you said.