상현에 하루하루
개발자의 하루

Traefik 커맨드 config 파일로 구성하기

( 업데이트: )

왜?

Traefik을 구성하면서 docker-compose.yaml 내부에서 커맨드라인이 너무나 늘어나는 것이다 그러다 보니까 고민이 되었다.

이렇게 작성하면 내가 나중에 잘 알아볼 수 있을까?

그래서 Traefik의 커맨드 설정을 .toml .yaml로 설정하는 방법이 있어서 이 방법으로 커맨드를 옮기려 한다.

Let’s go

Configuration Introduction – Traefik 공식 홈페이지에서 이 부분을 살펴보면 configuration File은 설정파일의 이름이 traefik.toml(.yml, .yaml)으로 설정 되어있고 해당 경로에 있으면 Traefik이 실행되면서 해당 설정을 가져온다.

  • /etc/traeifk
  • $XDG_CONFIG_HOME/
  • $HOME/.config/
  • .(the working directory)

처음에는 설정파일로 분리해서 작성할때 매우 만족스러웠다.

하지만 Dynamic conf 에 작성해야하는 것과 static config에 지정해야하는 것을 세세하게 살펴보지 못해서 왜 안되는거지? 하면서 커맨드로 계속 테스트를 해봤다.

traefik의 설정은 모두 끝났고

커맨드로 설정한 것을 /etc/traefik/traefik.yaml로 옮긴다.

################################################################
#
# Configuration sample for Traefik v2.
#
# master
# For Traefik v2: https://github.com/traefik/traefik/blob/master/traefik.sample.yml
# sample
# For Traefik v1: https://github.com/traefik/traefik/blob/v1.7/traefik.sample.toml
#
################################################################

################################################################
# Global configuration
################################################################

global:
  checkNewVersion: true
  sendAnonymousUsage: true

################################################################
# Traefik logs configuration
################################################################

log:
  level: DEBUG

################################################################
# Access logs configuration
################################################################

accessLog:
  filePath: /traefik.log
  bufferingSize: 100
  filters:
    statusCodes: ["400-499"]

################################################################
# API and dashboard configuration
################################################################

api:
  insecure: true

################################################################
# EntryPoints configuration
################################################################

entryPoints:
  http:
    address: :80
  https:
    address: :443
  traefik:
    address: :8080

################################################################
# Docker configuration backend
################################################################

providers:
  docker:
    exposedbydefault: false
  file:
    directory: /rules
    watch: trueCode language: PHP (php)

그리고 acme 설정을 위해서 /rules/ssl.yaml

certificateResolvers를 tlsChallenge, dnsChallenge 둘다 해봤지만 설정이 안되고 log=DEBUG에서 error와 debug 메세지에서 제대로 설정이 안되는 것을 알게 되었다.

그래서 커맨드로 실행해본 httpChallenge를 토대로 진행해보기로했다.

################################################################
# 인증서
# example: https://doc.traefik.io/traefik/https/acme/
################################################################

certificatesResolvers:
  myresolver:
    acme:
      email: dandan9509@gmail.com
      storage: /acme/acme.json
      httpchallenge:
        entrypoint: httpCode language: PHP (php)