traefik - Go Edge Router

choko's avatar
Jun 29, 2024
traefik - Go Edge Router
💧
Watermill
 
 
notion image

traefik

  • traefik은 서비스로 들어오는 요청들을 가로채서, 적절한 인스턴스에 분배시켜주는 오픈소스 플랫폼이다.
    • → Edge Router
  • 시스템을 대신하여 요청을 받고, 어떤 구성요소가 해당 요청을 처리하는지 알아낸다. 서비스가 배포되면 이를 즉시 감지하고, 라우팅 규칙을 실시간으로 업데이트한다.
    • Auto Service Discovery
 
 
 

Tutorial

notion image
docker-compose.yaml (traefik:v3.0)
version: '3' services: reverse-proxy: # The official v3 Traefik docker image image: traefik:v3.0 # Enables the web UI and tells Traefik to listen to docker command: --api.insecure=true --providers.docker ports: # The HTTP port - "80:80" # The Web UI (enabled by --api.insecure=true) - "8080:8080" volumes: # So that Traefik can listen to the Docker events - /var/run/docker.sock:/var/run/docker.sock
  • 바이너리
    • trafik.toml (config)
      • # defaultEntryPoints = ["http", "https"] [entryPoints] [entryPoints.http] address = ":7777" [api] dashboard = true insecure = true [providers] [providers.file] filename = "traefik.toml" watch = true [http] [http.routers] [http.routers.usermanagement] entryPoints = ["http"] rule = "PathPrefix(`/seedotech.usermanagement`)" service = "usermanagement" [http.routers.moviemanagement] entryPoints = ["http"] rule = "PathPrefix(`/seedotech.moviemanagement`)" service = "moviemanagement" # Adding a router for the Traefik dashboard [http.routers.api] rule = "PathPrefix(`/dashboard`)" service = "api@internal" entryPoints = ["http"] [http.services] [http.services.usermanagement.loadBalancer] [[http.services.usermanagement.loadBalancer.servers]] url = "http://127.0.0.1:8808" [http.services.moviemanagement.loadBalancer] [[http.services.moviemanagement.loadBalancer.servers]] url = "http://127.0.0.1:8809"
      • http://localhost:7777/seedotech.usermanagement 으로 요청을 보내면, usermanagement 서비스(127.0.0.1:8808의 서비스)로 request를 전달한다.
      • http://localhost:7777/seedotech.moviemanagement 으로 요청을 보내면, moviemanagement 서비스(127.0.0.1:8809의 서비스)로 request를 전달한다.
       
       
    • 실행
      • ./traefik --configFile=traefik.toml
        • notion image
       
    • 결과
    •  
       
       

      Middleware

      notion image
    • Router에서 각 서비스로 요청이 가기 전에, Middleware들을 설정할 수 있다.
      • 대표적으로 다음과 같은 미들웨어 기능들이 가능한 것 같다.
        • HTTP
          • Adds a Path Prefix
            Path Modifier
            Adds Basic Authentication
            Security, Authentication
            Buffering
            Buffers the request/response
            Request Lifecycle
            Chain
            Combines multiple pieces of middleware
            Misc
            CircuitBreaker
            Prevents calling unhealthy services
            Request Lifecycle
        • TCP
          • Limits the number of simultaneous connections.
            Security, Request lifecycle
            Limit the allowed client IPs.
            Security, Request lifecycle
         
         
Share article

Tom의 TIL 정리방