使用 traefik 2 在同一个容器上的多个路由器和服务
Multiple Routers and Services on the same container with traefik 2
我目前正在尝试让 traefik 在单个容器上使用多个路由器和服务,但这是行不通的,我不知道这是否有意。
为什么?
具体来说,我正在使用 gitlab omnibus 容器,并且想在 omnibus 容器内使用/访问多个服务,因为 gitlab 不仅 "the gitlab website" 提供它。
我尝试了什么?
我只是尝试通过标签向我的 docker 撰写文件添加另一个路由器
这是我的:
labels:
- "traefik.http.routers.gitlab.rule=Host(`gitlab.example.com`)"
- "traefik.http.services.gitlab.loadbalancer.server.port=80"
这就是我想要的:
labels:
- "traefik.http.routers.gitlab.rule=Host(`gitlab.example.com`)"
- "traefik.http.services.gitlab.loadbalancer.server.port=80"
- "traefik.http.routers.registry.rule=Host(`registry.gitlab.example.com`)"
- "traefik.http.services.registry.loadbalancer.server.port=5000"
这是行不通的,因为 traefik 可能对将什么路由到哪个服务感到困惑,而且我找不到一种机制来准确地告诉 traefik 在这种情况下哪个路由器转到哪个服务。
这有可能吗,还是我只是缺少一点 traefik 魔法?
我找到了问题的答案。
我确实漏掉了一点:
- traefik.http.routers.myRouter.service=我的服务
有了这个标签,我可以将一个路由器指向一个特定的服务,并且应该能够向一个容器添加多个服务:
labels:
- "traefik.http.routers.gitlab.rule=Host(`gitlab.example.com`)"
- "traefik.http.routers.gitlab.service=gitlab"
- "traefik.http.services.gitlab.loadbalancer.server.port=80"
- "traefik.http.routers.registry.rule=Host(`registry.gitlab.example.com`)"
- "traefik.http.routers.registry.service=registry"
- "traefik.http.services.registry.loadbalancer.server.port=5000"
这里每个路由器都明确指向一个特定的服务,这通常是隐式发生的。
我目前正在尝试让 traefik 在单个容器上使用多个路由器和服务,但这是行不通的,我不知道这是否有意。
为什么?
具体来说,我正在使用 gitlab omnibus 容器,并且想在 omnibus 容器内使用/访问多个服务,因为 gitlab 不仅 "the gitlab website" 提供它。
我尝试了什么?
我只是尝试通过标签向我的 docker 撰写文件添加另一个路由器
这是我的:
labels:
- "traefik.http.routers.gitlab.rule=Host(`gitlab.example.com`)"
- "traefik.http.services.gitlab.loadbalancer.server.port=80"
这就是我想要的:
labels:
- "traefik.http.routers.gitlab.rule=Host(`gitlab.example.com`)"
- "traefik.http.services.gitlab.loadbalancer.server.port=80"
- "traefik.http.routers.registry.rule=Host(`registry.gitlab.example.com`)"
- "traefik.http.services.registry.loadbalancer.server.port=5000"
这是行不通的,因为 traefik 可能对将什么路由到哪个服务感到困惑,而且我找不到一种机制来准确地告诉 traefik 在这种情况下哪个路由器转到哪个服务。
这有可能吗,还是我只是缺少一点 traefik 魔法?
我找到了问题的答案。
我确实漏掉了一点:
- traefik.http.routers.myRouter.service=我的服务
有了这个标签,我可以将一个路由器指向一个特定的服务,并且应该能够向一个容器添加多个服务:
labels:
- "traefik.http.routers.gitlab.rule=Host(`gitlab.example.com`)"
- "traefik.http.routers.gitlab.service=gitlab"
- "traefik.http.services.gitlab.loadbalancer.server.port=80"
- "traefik.http.routers.registry.rule=Host(`registry.gitlab.example.com`)"
- "traefik.http.routers.registry.service=registry"
- "traefik.http.services.registry.loadbalancer.server.port=5000"
这里每个路由器都明确指向一个特定的服务,这通常是隐式发生的。