Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Routers and Services on the same container with traefik 2

I'm currently trying to get traefik to use multiple routers and services on a single container, which isn't working and i don't know if this is intended at all.

Why?

Specificly i'm using an gitlab omnibus container and wanted to use / access multiple services inside the omnibus container since gitlab is providing not only "the gitlab website" with it.

What did i try?

I simply tried adding another router to my docker compose file via labels

This is what i have:

labels:
  - "traefik.http.routers.gitlab.rule=Host(`gitlab.example.com`)"
  - "traefik.http.services.gitlab.loadbalancer.server.port=80"

This is what i want:

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"

This doesn't work since traefik probably getting confused with what to route to which service and i couldn't find a mechanism that tells traefik exactly which router goes to which service in a case like this.

Is this even possible or am i just missing a little bit of traefik magic?

like image 596
nevotheless Avatar asked Jan 22 '20 09:01

nevotheless


1 Answers

I found the solution to my Question.

There's indeed a little bit i missed:

  • traefik.http.routers.myRouter.service=myService

With this Label i can point a Router to a specific Service and should be able to add multiple services to one container:

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"

Here each router is pointed to a specific service explicitly which normally happens implicitly.

like image 194
nevotheless Avatar answered Oct 13 '22 04:10

nevotheless