Https+h2c: Could not define the service name for the router: too many services

Hi,

I have found this error many times in Google, but nothing seems to fit my situation: I want to map two different routers to one service like so:

  interest_v1:
    image: my.registry.com/knipknap/spiff-mm-interest:latest
    networks:
      - traefik-public
      - spiff-backend
    deploy:
      labels:
        - micromodel=true
        - traefik.enable=true
        - traefik.docker.network=traefik-public
        - traefik.constraint-label=traefik-public
        - traefik.http.routers.spiff-backend-grpcui-interest-h2c.rule=Host(`grpc.interest.api.mydomain.com`)
        - traefik.http.routers.spiff-backend-grpcui-interest-h2c.entrypoints=grpc
        - traefik.http.routers.spiff-backend-grpcui-interest-h2c.tls=true
        - traefik.http.routers.spiff-backend-grpcui-interest-h2c.tls.certresolver=le
        - traefik.http.services.spiff-backend-grpcui-interest-h2c.loadbalancer.server.scheme=h2c
        - traefik.http.services.spiff-backend-grpcui-interest-h2c.loadbalancer.server.port=8181
        - traefik.http.routers.spiff-backend-grpcui-interest-https.rule=Host(`interest.api.mydomain.com`)
        - traefik.http.routers.spiff-backend-grpcui-interest-https.entrypoints=https
        - traefik.http.routers.spiff-backend-grpcui-interest-https.tls=true
        - traefik.http.routers.spiff-backend-grpcui-interest-https.tls.certresolver=le
        - traefik.http.services.spiff-backend-grpcui-interest.loadbalancer.server.port=8080

This leads to this:
"Could not define the service name for the router: too many services"

I found hints that I should add

        - traefik.http.routers.spiff-backend-grpcui-interest-h2c.service=interest_v1
        - traefik.http.routers.spiff-backend-grpcui-interest-https.service=interest_v1

But that also doesn't work; the error then is "no such service: interest_v1@docker". How can I make both these services available?

The routers don't know which service to use, there is more than one so implicit selection wont work. Use a service label on the router:

services:
  twoport:    
    image: twoport
    labels:
      traefik.enable: "true"
      traefik.http.routers.1.rule: Host(`one.example.com`)
      traefik.http.routers.1.entrypoints: websecure
      traefik.http.routers.1.service: one
      traefik.http.services.one.loadbalancer.server.port: 80
      traefik.http.routers.2.rule: Host(`two.example.com`)
      traefik.http.routers.2.entrypoints: websecure
      traefik.http.routers.2.service: two
      traefik.http.services.two.loadbalancer.server.port: 81

Thanks - but isn't that exactly what I did in the second part of my post? It doesn't work, it claims to not find the service as shown.

How would this look if both ports run on the same service?

You did not define a http service interest_v1 which is why you get that error. Notice that my example creates two services one and two there is no reference to the docker service.

Both 80 and 81 are running on this service twoport.

You defined two services:
spiff-backend-grpcui-interest-h2c

And:
spiff-backend-grpcui-interest

So those are the name you want to use for the router's service.

Ahhh, that makes sense! Thank you, I got it now :slight_smile: