Enabling rest@internal

Hi,

I've just setup Traefik v2.2. I'm trying to enable the rest api so i can update the configuration via rest. I'm missing something obvious i think. Curl request returns 404:

curl -d "{}" -X PUT http://localhost:8080/api/providers/rest
404 page not found

providers:
  file:
    directory: /etc/traefik/
    watch: true
  rest: true
log:
  level: DEBUG
  filePath: "/var/log/traefik/error.log"
api:
  dashboard: true
  insecure: true
entryPoints:
  web:
    address: ":80"
http:
  routers:
    rest:
      rule: Host(`localhost`) && PathPrefix(`/api/providers/rest`)
      service: rest@internal
      entryPoints:
        - traefik
    router0:
      entryPoints:
        - web
      service: service-foo
      rule: Host(`test.somedomain.com`)
  services:
    service-foo:
      loadBalancer:
        servers:
          - url: "http://10.100.253.61:30005"

Thanks,

Hi @Epea

Is all that in one file?

The dynamic configuration needs to be in its own file and referenced by the file provider defined in the static config.

In your case as you have configure the file provider to be directory: /etc/traefik/ that is where you file provider need to be.

Hi @cakiwi,

Thanks for the help. Yes that is one file. I've just tried splitting it out as per your suggestion (but i don't think i have it correct).

/etc/traefik/traefik.yml

providers:
  file:
    directory: /etc/traefik/
    watch: true
log:
  level: DEBUG
  filePath: "/var/log/traefik/error.log"
api:
  dashboard: true
  insecure: true

/etc/traefik/rest.yml

providers:
 rest: true
http:
  routers:
    rest:
      rule: Host(`localhost`) && PathPrefix(`/api/providers/rest`)
      service: rest@internal
      entryPoints:
        - traefik

I have removed my test router and service for now, and just tried the above. However, the rest endpoint still 404s.

Thanks again,

rest: true should be under providers in the static config, where file is, it is static config.

Thanks again.

I have made suggested adjustments but still no luck.

I have attached my dashboard screenshots of routers and services.

traefik.yml:

providers:
  file:
    filename: /etc/traefik/rest.yml
    watch: true
  rest: true
log:
  level: DEBUG
  filePath: "/var/log/traefik/error.log"
api:
  dashboard: true
  insecure: true

rest.yml:

http:
  routers:
    rest:
      rule: Host(`localhost`) && PathPrefix(`/api/providers/rest`)
      service: rest@internal
      entryPoints:
        - traefik

Debug log:

time="2020-07-09T17:15:16Z" level=info msg="Traefik version 2.2.2 built on 2020-07-08T15:30:29Z"
time="2020-07-09T17:15:16Z" level=debug msg="Static configuration loaded {\"global\":{\"checkNewVersion\":true},\"serversTransport\":{\"maxIdleConnsPerHost\":200},\"entryPoints\":{\"http\":{\"address\":\":80\",\"transport\":{\"lifeCycle\":{\"graceTimeOut\":10000000000},\"respondingTimeouts\":{\"idleTimeout\":180000000000}},\"forwardedHeaders\":{},\"http\":{}},\"traefik\":{\"address\":\":8080\",\"transport\":{\"lifeCycle\":{\"graceTimeOut\":10000000000},\"respondingTimeouts\":{\"idleTimeout\":180000000000}},\"forwardedHeaders\":{},\"http\":{}}},\"providers\":{\"providersThrottleDuration\":2000000000,\"file\":{\"watch\":true,\"filename\":\"/etc/traefik/rest.yml\"},\"rest\":{}},\"api\":{\"insecure\":true,\"dashboard\":true},\"log\":{\"level\":\"DEBUG\",\"filePath\":\"/var/log/traefik/error.log\",\"format\":\"common\"}}"
time="2020-07-09T17:15:16Z" level=info msg="\nStats collection is disabled.\nHelp us improve Traefik by turning this feature on :)\nMore details on: https://docs.traefik.io/contributing/data-collection/\n"
time="2020-07-09T17:15:16Z" level=info msg="Starting provider aggregator.ProviderAggregator {}"
time="2020-07-09T17:15:16Z" level=debug msg="Start TCP Server" entryPointName=http
time="2020-07-09T17:15:16Z" level=debug msg="Start TCP Server" entryPointName=traefik
time="2020-07-09T17:15:16Z" level=info msg="Starting provider *file.Provider {\"watch\":true,\"filename\":\"/etc/traefik/rest.yml\"}"
time="2020-07-09T17:15:16Z" level=info msg="Starting provider *traefik.Provider {}"
time="2020-07-09T17:15:16Z" level=debug msg="Configuration received from provider file: {\"http\":{\"routers\":{\"rest\":{\"entryPoints\":[\"traefik\"],\"service\":\"rest@internal\",\"rule\":\"Host(`localhost`) \\u0026\\u0026 PathPrefix(`/api/providers/rest`)\"}}},\"tcp\":{},\"udp\":{},\"tls\":{}}" providerName=file
time="2020-07-09T17:15:16Z" level=debug msg="Configuration received from provider internal: {\"http\":{\"routers\":{\"api\":{\"entryPoints\":[\"traefik\"],\"service\":\"api@internal\",\"rule\":\"PathPrefix(`/api`)\",\"priority\":2147483646},\"dashboard\":{\"entryPoints\":[\"traefik\"],\"middlewares\":[\"dashboard_redirect@internal\",\"dashboard_stripprefix@internal\"],\"service\":\"dashboard@internal\",\"rule\":\"PathPrefix(`/`)\",\"priority\":2147483645}},\"services\":{\"api\":{},\"dashboard\":{},\"noop\":{},\"rest\":{}},\"middlewares\":{\"dashboard_redirect\":{\"redirectRegex\":{\"regex\":\"^(http:\\\\/\\\\/(\\\\[[\\\\w:.]+\\\\]|[\\\\w\\\\._-]+)(:\\\\d+)?)\\\\/$\",\"replacement\":\"${1}/dashboard/\",\"permanent\":true}},\"dashboard_stripprefix\":{\"stripPrefix\":{\"prefixes\":[\"/dashboard/\",\"/dashboard\"]}}}},\"tcp\":{},\"tls\":{}}" providerName=internal
time="2020-07-09T17:15:16Z" level=info msg="Starting provider *rest.Provider {}"
time="2020-07-09T17:15:16Z" level=debug msg="Added outgoing tracing middleware rest@internal" middlewareType=TracingForwarder entryPointName=traefik routerName=rest@file middlewareName=tracing
time="2020-07-09T17:15:16Z" level=debug msg="Creating middleware" middlewareName=traefik-internal-recovery middlewareType=Recovery entryPointName=traefik
time="2020-07-09T17:15:16Z" level=debug msg="No default certificate, generating one"
time="2020-07-09T17:15:17Z" level=debug msg="Added outgoing tracing middleware api@internal" entryPointName=traefik routerName=api@internal middlewareName=tracing middlewareType=TracingForwarder
time="2020-07-09T17:15:17Z" level=debug msg="Added outgoing tracing middleware rest@internal" entryPointName=traefik routerName=rest@file middlewareName=tracing middlewareType=TracingForwarder
time="2020-07-09T17:15:17Z" level=debug msg="Added outgoing tracing middleware dashboard@internal" entryPointName=traefik routerName=dashboard@internal middlewareName=tracing middlewareType=TracingForwarder
time="2020-07-09T17:15:17Z" level=debug msg="Creating middleware" entryPointName=traefik routerName=dashboard@internal middlewareName=dashboard_stripprefix@internal middlewareType=StripPrefix
time="2020-07-09T17:15:17Z" level=debug msg="Adding tracing to middleware" routerName=dashboard@internal middlewareName=dashboard_stripprefix@internal entryPointName=traefik
time="2020-07-09T17:15:17Z" level=debug msg="Creating middleware" middlewareType=RedirectRegex entryPointName=traefik routerName=dashboard@internal middlewareName=dashboard_redirect@internal
time="2020-07-09T17:15:17Z" level=debug msg="Setting up redirection from ^(http:\\/\\/(\\[[\\w:.]+\\]|[\\w\\._-]+)(:\\d+)?)\\/$ to ${1}/dashboard/" middlewareName=dashboard_redirect@internal middlewareType=RedirectRegex entryPointName=traefik routerName=dashboard@internal
time="2020-07-09T17:15:17Z" level=debug msg="Adding tracing to middleware" middlewareName=dashboard_redirect@internal entryPointName=traefik routerName=dashboard@internal
time="2020-07-09T17:15:17Z" level=debug msg="Creating middleware" entryPointName=traefik middlewareName=traefik-internal-recovery middlewareType=Recovery
time="2020-07-09T17:15:17Z" level=debug msg="No default certificate, generating one"

Looks good so far.

What error are you getting now? Try enabling the access log too.

Yes, I came to the same conclusion. Access log shows it's getting caught by the api service i think:

127.0.0.1 - - [09/Jul/2020:17:21:41 +0000] "PUT /api/providers/rest HTTP/1.1" 404 19 "-" "-" 1 "api@internal" "-" 0ms

Because it's matching ^/api ? Can i reorder the internal api route?

I'm not sure if you can bind to the insecure entrypoint like that. I got the rest provider working earlier(for the first time) using both a route and --provider.rest.insecure

docker run --rm -it -p 8080:8080 traefik:2.2 --providers.rest=true --providers.rest.insecure=true --api.insecure=true --log.level=DEBUG --accesslog=true

I have success!

I have created an entry point on 8081, and set this to be used for the rest - this has worked ok. It would be good to get it running on 8080, but I couldn't work out how to set the priority or override the default router for the api. But no problem. I can work with this.

Thank you for taking the time to help.

1 Like

Ah, perhaps i need the rest.insecure - i'll give that a try too!

Yes! It was rest.insecure: true that was required! I've removed the entry point and route i made, and it works perfectly still.

Thanks again for your help!