Coder Social home page Coder Social logo

traefik-swarm's Introduction

traefik-swarm

Use traefik reverse proxy with docker swarm, based on this blog post: https://dockerswarm.rocks/traefik/

  • docker service name is traefik
  • overlay network name is traefik-public
  • uses docker "host mode" to get real ip addresses and enable ipv6 ingress
  • configured to run on single node in swarm based on constraints
  • predefined middlewares for http, https and redirects from non-www to www

Setup instructions

Add the following environment variables or use a shell script for that.

Create docker overlay network

docker network create --driver=overlay --attachable traefik-public

Export current Node Id to ensure that traefik runs always on same node

export NODE_ID=$(docker info -f '{{.Swarm.NodeID}}')

Create tag on node to add constraint for deployment

docker node update --label-add traefik-public.traefik-public-certificates=true $NODE_ID

Create Email for letsencrypt notifications

Domain for traefik UI

export DOMAIN=my.domain.com

Basic Auth User for Traefik

export USERNAME=MY_USER \
export PASSWORD=MY_SECURE_PASSWORD

Hash Password

export HASHED_PASSWORD=$(openssl passwd -apr1 $PASSWORD)

Deploy Stack:

docker stack deploy -c docker-compose.yml traefik

Access Logs & Rotation

The example has access log enabled and will log all traefik to a mounted host directory, log rotation on the host system rotates the logs periodically.

  • Create directory, e.g. /var/log/traefik and mount it in traefik docker-compose file
    volumes:
      ...
      # Mount log folder
      - /var/log/traefik:/var/log/traefik
  • Add log rotation on Host System - example for Ubuntu
nano /etc/logrotate.d/traefik

# assuming traefik container contains "traefik" in its name
/var/log/traefik/*.log {
        daily
        missingok
        rotate 30
        compress
        delaycompress
        notifempty
        create 0644 root root
        sharedscripts
        postrotate
           # kill & resstart container which contains "traefik" in name
           docker kill --signal="USR1" $(docker ps | grep traefik | awk '{print $1}')
        endscript
}

# debug logrotate & run it
logrotate /etc/logrotate.conf --debug 
logrotate /etc/logrotate.conf

traefik-swarm's People

Contributors

elmarputz avatar

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.