then in the next step i deployed a spring boot application (myApp) in global mode on 2 servers lets call it myAppServer1 and myAppServer2.
Now if i call traefikUrl:8510/myApp it should route me to one of the the 2 myApp Servers and remove the myApp prefix. For Example if i call treafikUrl:8510/myApp/site2 it should remove "myApp" and route me to "myAppServer2/site2" but all i get is Bad Gateway..
The traefik-proxy network is an overlay network (docker network create --driver=overlay traefik-proxy)
Hi @Stargate, there are a few things to fix to have this working:
First of all, remove all labels traefik.port as this label does not exist anymore in Traefik v2.0 (you can validate this assumption with the reference documentation for dynamic configuration for Docker e.g. "labels": https://docs.traefik.io/v2.0/reference/dynamic-configuration/docker/)
What is the port on which the Spring app is listening to (and exposed by the Docker images)? As you specified the label - traefik.http.services.myapp_service.loadbalancer.server.port=8515, then it means that Traefik contacts the docker container of "myApp" to its port 8515: Spring must be listening to this port (instead of the default 8080).
You should not expose Traefik's dashboard without protection: you might want to remove the published port 8512:8080 from Traefik's container, and add the right labels to traefik's container to expose the dashboard in secured mode, which implies removing the flag --api.insecure as well.(reference: https://docs.traefik.io/v2.0/operations/dashboard/#secure-mode).
If you are not able to make it work, can you provide the full Traefik's container logs with debug enabled here so we can dive in the errors?
i have removd the traefik.port labels and i added a port to the myApp Application (8515:8080)
and i changed the traefik.http.services.myapp_service.loadbalancer.server.port to 8080. Which port is the right for the loadbalancer label is it the internal container port "8080" or the exposed 8515 ?
it seems to work with port 8080.
Now if i call traefikUrl:8600 it will route me to myApp1:8080 or myApp2:8080
First of all, you only have to deal with exposed ports (aka. private only) between Traefik and the backend services: you can remove the directive
ports:
- 8515:8080
from the service myApp.
Your configuration seems right for the label traefik.http.services.myapp_service.loadbalancer.server.port : 8080 seems like the default port which Spring is listening on, hence the private port exposed by the container on the private network. Traefik will forward requests from the outside to this port.
Are you facing issues now or is it working? (I'm not sure if I understood correctly)
yes it worked now. But i have currently a problem with the dashboard in secure mode. If i enter traefikUrl:8512/dashboard (the basic auth did not work) i cann see the dashboard screen but all is grayed out and i can not see the services and routers..
The reason of the "grayed out" is because your web browser already have the HTML/JS/CSS of the dashboard in its local cache, but there is an issue when contacting the backend to update data: clean up your cache.
If you still have an issue, I'll need the following elements to help:
The result of the command curl --verbose --location --insecure -o /dev/null http://traefikUrl:8512/dashboard/
The logs (with debug enabled) from Traefik's container
Hi @Stargate, I tried to reproduce you case and caught 2 errors in the docker service of Traefik:
First:
traefik_traefik.1.wdn1uhibsxbi@docker-desktop | time="2019-10-26T09:41:52Z" level=warning msg="Could not find network named 'traefik-proxy' for container 'traefik_traefik.1'! Maybe you're missing the project's prefix in the label? Defaulting to first available network." container=traefik-traefik-wdn1uhibsxbio80neggxkglg6 serviceName=traefik-traefik providerName=docker
=> You might not have this error: it is related to the space between the last line of the command: > yaml node and networks:. When checking the Docker API, I saw that the Traefik container was not attached to the network traedfik-proxy. By removing the empty line and redeploying, this error went away
Second:
--providers.docker.exposedbydefault=false
This flag means that Traefik takes in account only the containers which have the label traefik.enable set to true. But Traefik itself do not have this label in your snippet, so it ignores itself and the configuration is never created.
=> Add the label - traefik.enable=true to Traefik itself.
Third:
When using Swarm, Traefik cannot determines the exposed port automatically as how it does with Docker Engine. It is mandatory to specify this port as if there were multiple ports. I don't know why (yet) but you must create a "dummy" service with a port, which won't be used but is still required.
=> Add the label traefik.http.services.api-dummy.loadbalancer.server.port=99999 to the Traefik service.
but i get still two different error messages with "port ist missing" but so far this message has no effect all works fine. But i dont know why this message appears
traefik | time="2019-10-31T09:00:50Z" level=error msg="port is missing" providerName=docker container=myApp-6nybt4u2572n9wkxj38py1ngd
traefik | time="2019-10-31T09:00:50Z" level=error msg="port is missing" providerName=docker container=myApp-ozw4no2nvv249ij1jra4bfo1a
traefik | time="2019-10-31T09:01:05Z" level=error msg="port is missing" container=myApp-6nybt4u2572n9wkxj38py1ngd providerName=docker
traefik | time="2019-10-31T09:01:05Z" level=error msg="port is missing" container=myApp-ozw4no2nvv249ij1jra4bfo1a providerName=docker
here is a similar bug but i have set a loadbalancer port: "traefik.http.services.myapp_service.loadbalancer.server.port=8080"