I've written a .NET API application that listens on two ports:
- 5000 for regular HTTP requests (HTTP1)
- 5001 for gRPC (HTTP2)
I'm deploying my images via docker-compose
using labels:
labels:
- "traefik.enable=true"
- "traefik.http.routers.myApi.rule=Host(`api.example.com`)"
- "traefik.http.routers.myApientrypoints=websecure"
- "traefik.http.routers.myApitls.certresolver=myresolver"
Now, my question is - if my container EXPOSEs 5000 as well as 5001, how do I setup a new subdomain so that I can allow regular web traffic as well as gRPC
?
So that:
HTTP1 https://api.example.com -> container:5000
HTTP2 https://api-grpc.example.com -> container:5001
If there is a better way of achieving the same, please let me know. I cannot have gRPC
listen on the same port as web traffic due to the strict HTTP2
requirement, and I'd rather not use gRPC-web
.
CodePudding user response:
labels:
- traefik.http.routers.http-router.rule=Host(`api.example.com`)
- traefik.http.routers.http-router.service=http-service
- traefik.http.services.http-service.loadbalancer.server.port=5000
- traefik.http.routers.grpc-router.rule=Host(`api-grpc.example.com`)
- traefik.http.routers.grpc-router.service=grpc-service
- traefik.http.services.grpc-service.loadbalancer.server.port=5001
- traefik.http.services.grpc-service.loadbalancer.server.scheme=h2c
Reference: Specifying more than one router and service per container