jittering / traefik-kop

A dynamic docker->redis->traefik discovery agent
MIT License
179 stars 13 forks source link

multiple servers behind one service #30

Open koehnik opened 7 months ago

koehnik commented 7 months ago

Hello there,

got a question which is based on a service which has multiple servers in background. With the docker deamon it works like charme. But i ran into this issue with traefik-kop.

I want to publish multiple instances behind one router and one service (load balancing in fact).

Here are my labels for the container1 and the same on container2:

 - "traefik.enable=true"
  - "traefik.http.services.test.loadbalancer.server.port=8080"
  - "traefik.docker.network=q-srv"
  - "traefik.http.routers.test.entrypoints=web"
  - "traefik.http.services.test.loadbalancer.server.scheme=http"
  - "traefik.http.routers.test.rule=Host(`test.local`)"

But everytime i start the other container, the IP will bei overwritten on both servers with the latest discovered ip from traefik-kop. So is it possible to do that?

image image

Can you give me a hint how to publish both IPs to this service as servers? Would be great :)

koehnik commented 7 months ago

...after browsing a bit at the redis database there is something suspicious:

"traefik/http/services/test/loadBalancer/servers/0/url": image

"traefik/http/services/test/loadBalancer/servers/1/url":

Both will be rewritten with the same IP Address... image

chetan commented 7 months ago

@koehnik I'm not sure how a load balanced scenario would work. It looks like it's correctly publishing two services for the same service, which is what you expect. If that's the case, you just need to make one of the services run on a different port. Since both containrs are on the same host and the external traefik instance needs to be able to talk to them both, they must be exposed on different ports. Try binding one of the services on 8081 instead.

koehnik commented 7 months ago

@chetan not totally correct. These 2 services run on different hosts. So they got an ipvlan ip-address and these are defined in my compose.yml. And the label "traefik.docker.network=q-srv" points to the right network. So it collects the IP and set the rules. But unfortunately the traefik/http/services/test/loadBalacer/servers/0/url should be: 10.42.2.100:8080 and traefik/http/services/test/loadBalacer/servers/1/url should be: 10.42.2.101:8080

So i think that there is a bug, which overrides both of them and doesn't seperate them because of 2 containers referencing the same servicename but other IPs. Is there a option that the "array" got seperate ips?

Addition: If i restart one of the containers, the latest restarted containers IP is set for both. Thanks in advance! ;)

chetan commented 7 months ago

Ah, I see. In that case, I think it's likely a "last update wins" scenario. traefik-kop is designed to publish distinct services for each container so the fact that it's even sort-of handling this case is a mystery to me. I don't think this will work without some changes but you can try a workaround like adding the kop.bind.ip label explicitly on each host