Problems using Traefik with the app on different nodes

This is my initial proxy configuration

version: "3.8"

services:
  traefik:
    image: "traefik:latest"
    command:
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--providers.docker.swarmMode=true"
      - "--entrypoints.web.address=:80"
      - "--accesslog"
      - "--log.level=DEBUG"
      - "--api=true"
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
    deploy:
      placement:
        constraints:
          - node.role == manager
      labels:
        - "traefik.enable=true"
        - "traefik.docker.network=traefik-net"
        - "traefik.http.services.api.loadbalancer.server.port=8080"
        - "traefik.http.routers.api.rule=Host(`traefik.mydomain.test`)"
        - "traefik.http.routers.api.service=api@internal"
        - "traefik.http.routers.api.entrypoints=web"
    networks:
      - traefik-net

networks:
  traefik-net:
    external: true

my service

version: '3.8'
services:
  myapp:
    image: myapp
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=traefik-net"
      - "traefik.http.routers.myapp.rule=Host(myapp.test.com`)"
      - "traefik.http.routers.myapp.service=myapp"
      - "traefik.http.services.myapp.loadbalancer.server.port=3000"
      - "traefik.http.routers.myapp.entrypoints=web"
      - "traefik.http.services.myapp.loadbalancer.passhostheader=true"
    deploy:
      placement:
        constraints:
          - node.hostname == nodeworker1
    networks:
      - traefik-net

networks:
  traefik-net:
    external: true

My Network

LfnQAqTK89

my result:
404 page not found

 time="2024-02-09T18:33:19Z" level=debug msg="Filtering disabled container" providerName=docker container=my-service-unqervjxzi143lb7yykfuay5r

It works correctly for me only when both services run on the same node.!
Could you help me correct my error, my logic is to have Trafik only on the master node and the other services on the worker nodes.

There seems to be a backtick missing.

This is corrected, but I still don't get results, it only works for me when both services are on the same node.

      - "traefik.enable=true"
      - "traefik.docker.network=traefik-net"
      - "traefik.http.routers.myapp.rule=Host(`myapp.test.com`)"
      - "traefik.http.routers.myapp.service=myapp"
      - "traefik.http.services.myapp.loadbalancer.server.port=80"
      - "traefik.http.routers.myapp.entrypoints=web"
      - "traefik.http.services.myapp.loadbalancer.passhostheader=true"

So when you don't constrain the placement of the target service and you have 1 manager and 1 worker, every second request will fail (as Traefik uses round-robin)?

Enable full Traefik debug log. Maybe compare to a simple Traefik Swarm example.

Note that Traefik LetsEncrypt with easier httpChallenge and tlsChallenge only works when a single Traefik instance receives all requests.

The example has worked successfully for me.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.