如何修复 Traefik Could not define the service name for the router: too many services
问题:
Traefik 不加载你的一些服务,你看到类似以下的错误消息:
traefik_error.txt
traefik_1 | time="2022-03-27T15:22:05Z" level=error msg="Could not define the service name for the router: too many services" routerName=myapp providerName=docker使用带有多个路由器的 docker 标签配置,如下所示:
traefik_labels.yml
labels:
- "traefik.enable=true"
- "traefik.http.routers.myapp-console.rule=Host(`console.myapp.mydomain.com`)"
- "traefik.http.routers.myapp-console.entrypoints=websecure"
- "traefik.http.routers.myapp-console.tls.certresolver=alpn"
- "traefik.http.services.myapp-console.loadbalancer.server.port=9001"
#
- "traefik.http.routers.myapp.rule=Host(`myapp.mydomain.com`)"
- "traefik.http.routers.myapp.entrypoints=websecure"
- "traefik.http.routers.myapp.tls.certresolver=cloudflare-techoverflow"
- "traefik.http.routers.myapp.tls.domains[0].main=mydomain.com"
- "traefik.http.routers.myapp.tls.domains[0].sans=*.mydomain.com"
- "traefik.http.services.myapp.loadbalancer.server.port=9000"解决方案
这里的基本问题是你为单个 docker 容器定义了多个路由器,而 Traefik 不知道哪个 http.services 属于哪个 http.routers!
为了修复此问题,明确告诉 traefik 每个路由器应该使用什么服务,如下所示:
traefik_labels_example.yml
- "traefik.http.routers.myapp-console.service=myapp-console"完整示例:
traefik_labels_full_example.yml
labels:
- "traefik.enable=true"
- "traefik.http.routers.myapp-console.rule=Host(`console.myapp.mydomain.com`)"
- "traefik.http.routers.myapp-console.entrypoints=websecure"
- "traefik.http.routers.myapp-console.tls.certresolver=alpn"
- "traefik.http.routers.myapp-console.service=myapp-console"
- "traefik.http.services.myapp-console.loadbalancer.server.port=9001"
#
- "traefik.http.routers.myapp.rule=Host(`myapp.mydomain.com`)"
- "traefik.http.routers.myapp.entrypoints=websecure"
- "traefik.http.routers.myapp.tls.certresolver=cloudflare-techoverflow"
- "traefik.http.routers.myapp.tls.domains[0].main=mydomain.com"
- "traefik.http.routers.myapp.tls.domains[0].sans=*.mydomain.com"
- "traefik.http.routers.myapp.service=myapp"
- "traefik.http.services.myapp.loadbalancer.server.port=9000"Check out similar posts by category:
Container, Docker, Networking, Traefik
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow