繁体   English   中英

使用 traefik 2 在同一个容器上的多个路由器和服务

[英]Multiple Routers and Services on the same container with traefik 2

我目前正在尝试让 traefik 在单个容器上使用多个路由器和服务,但这是行不通的,我不知道这是否有意为之。

为什么?

具体来说,我正在使用一个 gitlab omnibus 容器,并且想在 omnibus 容器内使用/访问多个服务,因为 gitlab 不仅提供“gitlab 网站”。

我尝试了什么?

我只是尝试通过标签将另一个路由器添加到我的 docker compose 文件中

这就是我所拥有的:

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=myService

使用此标签,我可以将路由器指向特定服务,并且应该能够向一个容器添加多个服务:

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"

这里每个路由器都明确指向一个特定的服务,这通常是隐式发生的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM