Coder Social home page Coder Social logo

Comments (4)

elfenlaid avatar elfenlaid commented on May 3, 2024 1

@baskinsy thanks for config

It seems I've tracked my problem. It boils down to service's labels. You can define multiple segments for different routes. I need to forward requests from path to port for logstash and described it like this:

labels:
  - traefik.web.frontend.entryPoints=https
  - traefik.web.port=9600
  - traefik.web.frontend.rule=Host:hello.${DOMAIN}

  - traefik.metrics.frontend.rule=Host:hello.${DOMAIN};PathPrefixStrip:/metrics
  - traefik.metrics.frontend.entryPoints=https
  - traefik.metrics.port=5001

But traefik doesn't work if top traefik.frontend.rule and traefik.port not specified. At least not in expected way:

$> while sleep 1; do curl -s -o /dev/null -w "%{http_code}\n" https://hello.${DOMAIN} ; done
200
200
200
200
200
404
404
404
404
404
200
200
200
...

So a working set of labels for me:

labels:
   - traefik.tags=traefik-public
   - traefik.docker.network=traefik-public
   - traefik.enable=true

   - traefik.frontend.rule=Host:hello.${DOMAIN?Variable DOMAIN not set}
   - traefik.port=9600

   - traefik.web.frontend.entryPoints=https
   - traefik.web.metrics.port=9600

   - traefik.metrics.frontend.rule=Host:hello.${DOMAIN?Variable DOMAIN not set};PathPrefixStrip:/metrics
   - traefik.metrics.frontend.entryPoints=https
   - traefik.metrics.port=5000

   - traefik.redirect.frontend.entryPoints=http
   - traefik.redirect.frontend.redirect.entryPoint=https
   - traefik.redirect.frontend.redirect.permanent=true

from dockerswarm.rocks.

baskinsy avatar baskinsy commented on May 3, 2024

I didn't had such behavior even with the stack proposed here by @tiangolo , although I faced several consul clustering issues and I ended with this deployment file which works fine for me.

I don't use at all those two settings, don't know if the play any role on your issue but in general I haven't seen recreation of fronteds and backends with node discovery, even when consul was down, everything was working fine. Only adding new frontends and backends was failing due to the lost connection with consul

--docker.domain=traefik
--docker.network=proxy

This is what I use:

version: '3.4'

services:
  traefik_init:
    image: traefik:1.7
    command: 
      - "storeconfig"
      - "--docker"
      - "--docker.swarmMode"
      - "--docker.watch"
      - "--docker.exposedbydefault=false"
      - "--constraints=tag==traefik-public"
      - "--entrypoints=Name:http Address::80 Redirect.EntryPoint:https"
      - "--entrypoints=Name:https Address::443 TLS"
      - "--consul"
      - "--consul.endpoint=consul:8500"
      - "--consul.prefix=traefik"
      - "--acme"
      - "[email protected]"
      - "--acme.storage=traefik/acme/account"
      - "--acme.entryPoint=https"
      - "--acme.httpChallenge.entryPoint=http"
      - "--acme.onHostRule=true"
      - "--acme.onDemand=false"
      - "--acme.acmelogging=true"
      - "--logLevel=INFO"
      - "--accessLog"
      - "--api"
    networks:
      - consul
    deploy:
      restart_policy:
        condition: on-failure
    depends_on:
      - consul

  consul:
    image: consul:latest
    command: agent -server -client=0.0.0.0 -bootstrap-expect=3 -ui -data-dir /consul/data -retry-join consul.cluster
    volumes:
      - consul-data:/consul/data
    environment:
      - 'CONSUL_LOCAL_CONFIG={ "skip_leave_on_interrupt": true, "leave_on_terminate": false, "datacenter":"staging", "data_dir":"/consul/data", "server":true }'
      - CONSUL_BIND_INTERFACE=eth0
    networks:
      consul:
        aliases:
          - consul.cluster
      traefik-public:
    deploy:
      endpoint_mode: dnsrr
      mode: global
      placement:
        constraints:
          - node.role == manager
      resources:
        reservations:
          cpus: '0.5'
          memory: 128M 
      update_config:
        parallelism: 1
        delay: 30s
      restart_policy:
        condition: on-failure
      labels:
        - traefik.frontend.rule=Host:consul.domain.tld
        - traefik.enable=true
        - traefik.port=8500
        - traefik.tags=traefik-public
        - traefik.docker.network=traefik-public
        # Traefik service that listens to HTTP
        - traefik.redirectorservice.frontend.entryPoints=http
        - traefik.redirectorservice.frontend.redirect.entryPoint=https
        # Traefik service that listens to HTTPS
        - traefik.webservice.frontend.entryPoints=https
        - traefik.frontend.auth.basic.users=admin:xxxxxxxxxxxxxx

  traefik:
    image: traefik:1.7
    ports:
      - 80:80
      - 443:443
    deploy:
      mode: global
      placement:
        constraints:
          - node.role == manager
      update_config:
        parallelism: 1
        delay: 10s
      restart_policy:
        condition: on-failure  
      labels:
        - traefik.frontend.rule=Host:traefik.domain.tld
        - traefik.enable=true
        - traefik.port=8080
        - traefik.tags=traefik-public
        - traefik.docker.network=traefik-public
        - traefik.backend.loadbalancer.stickiness=true
        # Traefik service that listens to HTTP
        - traefik.redirectorservice.frontend.entryPoints=http
        - traefik.redirectorservice.frontend.redirect.entryPoint=https
        # Traefik service that listens to HTTPS
        - traefik.webservice.frontend.entryPoints=https
        - traefik.frontend.auth.basic.users=admin:xxxxxxxxxxxx
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    command:
      - "--consul"
      - "--consul.endpoint=consul:8500"
      - "--consul.prefix=traefik"
      - "--sendAnonymousUsage=true"
    networks:
      - consul
      - traefik-public
    depends_on:
      - consul
      - traefik_init      
        
networks:
  traefik-public:
    driver: overlay
    external: true
  consul:
    driver: overlay
    external: true

volumes:
  consul-data:

from dockerswarm.rocks.

elfenlaid avatar elfenlaid commented on May 3, 2024

Additional recommendations here traefik/traefik#4941

from dockerswarm.rocks.

tiangolo avatar tiangolo commented on May 3, 2024

Thanks for reporting back and closing the issue @elfenlaid ! 🍰

from dockerswarm.rocks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.