본문 바로가기
WIKI 기술 지식 베이스

Traefik TCP 라우터 문서

원문 보기 위키 갱신

출처: Traefik TCP Routers Documentation

본문

Router

TCP 라우터

TCP 라우터는 들어오는 TCP 연결을 처리할 수 있는 서비스에 연결하는 역할을 해요. TCP 라우터는 규칙에 따라 들어오는 연결을 분석하고, 일치하는 항목이 발견되면 구성된 미들웨어를 거쳐 적절한 서비스로 연결을 전달해요.

TCP 라우팅과 HTTP 라우팅

HTTP 라우터와 TCP 라우터가 동일한 엔트리 포인트를 수신하면 TCP 라우터가 HTTP 라우터보다 먼저 적용돼요. TCP 라우터에 일치하는 경로가 없으면 HTTP 라우터가 처리하게 돼요.

설정 예시

구조화 (YAML)

tcp:
  routers:
    my-tcp-router:
      entryPoints:
        - "tcp-ep"
        - "websecure"
      rule: "HostSNI(`example.com`)"
      priority: 10
      middlewares:
        - "tcp-ipallowlist"
      tls:
        passthrough: false
        certResolver: "letsencrypt"
        options: "modern-tls"
        domains:
          - main: "example.com"
            sans:
              - "www.example.com"
      service: my-tcp-service

구조화 (TOML)

[tcp.routers]
  [tcp.routers.my-tcp-router]
    entryPoints = ["tcp-ep", "websecure"]
    rule = "HostSNI(`example.com`)"
    priority = 10
    middlewares = ["tcp-ipallowlist"]
    service = "my-tcp-service"

    [tcp.routers.my-tcp-router.tls]
      passthrough = false
      certResolver = "letsencrypt"
      options = "modern-tls"

      [[tcp.routers.my-tcp-router.tls.domains]]
        main = "example.com"
        sans = ["www.example.com"]

Labels

labels:
  - "traefik.tcp.routers.my-tcp-router.entrypoints=tcp-ep,websecure"
  - "traefik.tcp.routers.my-tcp-router.rule=HostSNI(`example.com`)"
  - "traefik.tcp.routers.my-tcp-router.priority=10"
  - "traefik.tcp.routers.my-tcp-router.middlewares=tcp-ipallowlist"
  - "traefik.tcp.routers.my-tcp-router.tls.certresolver=letsencrypt"
  - "traefik.tcp.routers.my-tcp-router.tls.passthrough=false"
  - "traefik.tcp.routers.my-tcp-router.tls.options=modern-tls"
  - "traefik.tcp.routers.my-tcp-router.tls.domains[0].main=example.com"
  - "traefik.tcp.routers.my-tcp-router.tls.domains[0].sans=www.example.com"
  - "traefik.tcp.routers.my-tcp-router.service=my-tcp-service"

Tags

{
  "Tags": [
    "traefik.tcp.routers.my-tcp-router.entrypoints=tcp-ep,websecure",
    "traefik.tcp.routers.my-tcp-router.rule=HostSNI(`example.com`)",
    "traefik.tcp.routers.my-tcp-router.priority=10",
    "traefik.tcp.routers.my-tcp-router.middlewares=tcp-ipallowlist",
    "traefik.tcp.routers.my-tcp-router.tls.certresolver=letsencrypt",
    "traefik.tcp.routers.my-tcp-router.tls.passthrough=false",
    "traefik.tcp.routers.my-tcp-router.tls.options=modern-tls",
    "traefik.tcp.routers.my-tcp-router.tls.domains[0].main=example.com",
    "traefik.tcp.routers.my-tcp-router.tls.domains[0].sans=www.example.com",
    "traefik.tcp.routers.my-tcp-router.service=my-tcp-service"
  ]
}

설정 옵션

| 필드 | 설명 | 기본값 | 필수 | | entryPoints | 라우터가 연결되는 엔트리 포인트 목록이에요. 지정하지 않으면 TCP 라우터는 모든 TCP 엔트리 포인트에 연결돼요. | 모든 TCP 엔트리 포인트 | 아니요 | | rule | 규칙은 값으로 구성된 매처 집합으로, 특정 연결이 특정 기준에 맞는지 판단해요. 규칙이 검증되면 라우터가 활성화되고 미들웨어를 호출한 뒤 연결을 서비스로 전달해요. 자세한 내용은 규칙 및 우선순위를 참고하세요. | | 예 | | ruleSyntax | 더 이상 사용되지 않아요. v2→v3 마이그레이션을 지원하기 위해 rule 필드에 사용되는 문법을 지정해요. 새 구성에서는 이 필드를 사용하지 말고 라우터 규칙을 v3 문법으로 다시 작성하세요. | | 아니요 | | priority | 규칙 겹침을 피하기 위해 경로는 기본적으로 규칙 길이를 기준으로 내림차순 정렬돼요. 우선순위는 규칙의 길이와 정확히 같으므로, 가장 긴 규칙이 가장 높은 우선순위를 가져요. 우선순위 값 0 은 무시돼요. 음수 값도 지원돼요. 자세한 내용은 규칙 및 우선순위를 참고하세요. | 규칙 길이 | 아니요 | | middlewares | 라우터에 적용되는 미들웨어 목록이에요. 미들웨어는 선언된 순서대로 적용돼요. 사용 가능한 TCP 미들웨어는 TCP 미들웨어 개요를 참고하세요. | | 아니요 | | tls | 라우터의 TLS 구성이에요. 지정하면 라우터는 TLS 연결만 처리해요. 자세한 TLS 옵션은 TLS 구성 섹션을 참고하세요. | | 아니요 | | service | 일치하는 연결을 처리할 서비스 이름이에요. 서비스는 로드 밸런서 서비스나 가중 라운드 로빈(weighted round robin) 서비스가 될 수 있어요. 자세한 내용은 TCP 서비스를 참고하세요. | | 예 |

라우터 이름 지정

  • 라우터 이름에는 @ 문자가 허용되지 않아요

  • 라우터 이름은 설명적이어야 하고 여러분의 명명 규칙을 따라야 해요

  • 프로바이더별 구성(Docker, Kubernetes)에서는 라우터 이름이 서비스 이름과 규칙을 기반으로 자동 생성되는 경우가 많아요

프로덕션에서 Traefik OSS를 사용 중인가요?

업무에서 Traefik을 사용하고 있다면 엔터프라이즈급 API 게이트웨이 기능이나 Traefik OSS에 대한 상용 지원을 추가하는 것을 고려해 보세요.

  • API 게이트웨이 데모 영상 보기

  • 24/7/365 OSS 지원 요청하기

Traefik OSS에 API 게이트웨이 기능을 추가하는 것은 빠르고 매끄러워요. 교체(rip and replace)가 필요 없고 모든 구성이 그대로 유지돼요. 짧은 영상으로 직접 확인해 보세요.

더 알아보기 (Learn more)