I have two Traefiks (T1 & T2), each one with their constraints. So, basically two environments, but on the same Docker Swarm infrastructure.
I want to create a entry on the first one (T1) to route to a service on the second one. I think it could be done by using file provider, such the following example:
I didn't test it, by when connect on the T1 I was able to execute curl http://my-service-name-here/. But I'd like to do it by using the labels.
I know that services.[service-name].loadbalancer.servers[x].url is not available on Docker Swarm (even when not using the IP address, but the service name). Is there a way to configure on T1 a router to a service linked to T2? I cant configure directly on the service, because it does not have the T1 constraint, so the service cannot "see" T1.
Sure, loadbalancer.servers.url is available in Docker Swarm. It is just not available in Docker dynamic config via labels, you need to use providers.file with a dynamic config file.
Shouldn’t it work with Configuration Discovery and a constraint for both services? (Doc)
Here is a simple example, that doesn't fully utilize TLS, you would need to setup a wildcard cert (with LetsEncrypt). And the rule in traefik-dynamic.yml could be improved, using something like *.lab.example.com.
traefik-ext listens externally on 80 and 443, creates TLS certs. It recognizes services with traefik.ext=true label. Every request not matching the discovered "ext" services will be forwarded to traefik-int via the traefik-dynamic.yml configuration file.
traefik-int only listens in Docker network internally on port 80, no TLS, discovers services using traefik.int=true label.
Here is another template using only a docker-compose file.
traefik-int is labeled with traefik.ext=true, so it is automatically picked up by traefik-ext, and using entrypoint websecure, it is (incl. /dashboard/) practically available externally.
Again, it's missing a TLS wildcard certresolver for traefik-ext and all requests unknown to traefik-ext are passed to traefik-int using rule=PathPrefix(`/`).
Other "internal" services must use label traefik.int=true and entrypoint web.
Thank you for your help. It worked perfectly to my propose.
I just had to make a small change on your approach, because since both traefik are referencing api@internal, they were showing the same result (from the external one).
My workaround was to enable the --api.insecure=true and use the port=8080 on the internal Traefik. Of course I will have to create the middlewares (auth and ipwhitelist) to do not expose it to the other services inside the swarm.
My question is: was my approach the best solution? Is there another way to reference the api@internal on the internal traefik without conflicting with the external one?
I've just figure out that my approach to protect the API makes no sense. It will be applied to the proxy layer (accessing from outside). Another service could still access the traefik API (traefik-int:8080), even with whitelist and auth.