Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
204 views
in Technique[技术] by (71.8m points)

Traefik not updating when services are deployed to docker swarm

I have a traefik environment running in docker. Originally I was running services in standard containers. I am not deploying containers to docker swarm and I have done this for traefik too, where the container is only deployed to my swarm manager.

For some reason, traefik successfully registers the host name I have given it, and can access that fine. However, when I deploy any other service to the swarm, traefik doesn't pick it up. There is one other service that has partially worked. I have deployed heimdall to docker swarm which can be access from gateway.docker.swarm:8091 but I don't want the port either.

My traefik compose file is as follows:

version: '3.3'
networks:
  swarm-network:
    driver: overlay
services:
  traefik:
    # The official v2 Traefik docker image
    image: traefik
    deploy:
      placement: 
        constraints: 
          - node.role == manager
      labels:
        - "traefik.enable=true"
        - "traefik.docker.network=pi_swarm-network"
        - "traefik.http.routers.traefik.entrypoints=http"
        - "traefik.http.services.traefik.loadbalancer.server.port=8080"
        - "traefik.http.routers.traefik.rule=Host(`traefik.docker.swarm`)"
        
    # Enables the web UI and tells Traefik to listen to docker
    command: 
    - '--api.insecure=true'
    - '--providers.docker=true'
    - '--providers.docker.swarmmode=true'
    - '--providers.docker.defaultRule=Host("docker.swarm")'
    - '--providers.docker.watch=true' 
    - '--providers.docker.swarmModeRefreshSeconds=15s'
    # Metrics configuration for influx db.
    - '--metrics=true'
    - '--metrics.influxdb=true'
    - '--metrics.influxdb.address=192.168.8.122:8086'
    - '--metrics.influxdb.protocol=http'
    - '--metrics.influxdb.database=traefik'
    - '--metrics.influxdb.addEntryPointsLabels=true'
    - '--metrics.influxdb.addServicesLabels=true'
    - '--metrics.influxdb.pushInterval=10s'
    # Tracing
    - '--tracing=true'
    - '--tracing.zipkin=true'
    - '--tracing.zipkin.httpEndpoint=http://192.168.8.117:9411/api/v2/spans'
    - '--log' 
    - '--accesslog'
    ports:
      # The HTTP port
      - "80:80"
      # The Web UI (enabled by --api.insecure=true)
      - "8080:8080"
    networks:
      - swarm-network
    volumes:
      # So that Traefik can listen to the Docker events
      - /var/run/docker.sock:/var/run/docker.sock
   

An example of another service I am running is heimdall which has the compose file of the following:

version: "3"
networks:
  swarm-network:
    external:
      name: pi_swarm-network
services:
 heimdall:
    image: ghcr.io/linuxserver/heimdall
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Europe/London
    deploy:
      placement: 
        constraints: 
          - node.labels.tier == web
      labels:
        - "traefik.enable=true"
        - "traefik.docker.network=pi_swarm-network"
        - "traefik.http.routers.heimdall.entrypoints=http"
        - "traefik.http.services.heimdall.loadbalancer.server.port=8091"
        - "traefik.http.routers.heimdall.rule=Host(`gateway.docker.swarm`)"
    ports:
      - 8091:80
    restart: unless-stopped
    networks:
      - swarm-network

Can anyone see what I'm doing wrong?

question from:https://stackoverflow.com/questions/65672070/traefik-not-updating-when-services-are-deployed-to-docker-swarm

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I have figured out the problem.

In my compose file, I was using "traefik.http.services.heimdall.loadbalancer.entrypoints=http" as well as "traefik.http.routers.heimdall.entrypoints=http"

this was incorrect and needed to just be "traefik.http.routers.heimdall.entrypoints=http"

For heimdall, I was also targetting the external port of 8091, whereas I actually needed to target the internal port of 80


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...