Search code examples
subdomainlets-encryptconsulnomad

nomad consul traefik https


I have a go app that i need to run multiple instances under separate subdomains, i have a working nomad consul setup and got the go app to run and is accessible via a fixed ip address and dedicated port. But i am stuck on how to make it work with the unique subdomains and working https.

So what i'm looking for is like app1 runs on https://app1.example.com app2 runs on https://app2.example.com I tried to use traefic (got it running as a job), DNSmasq but i havent got the above to work.

Any help would be much appriciated.


Solution

  • Traefik supports integrating with Consul through its Consul Catalog provider. See https://learn.hashicorp.com/tutorials/nomad/load-balancing-traefik for an example of how to configure this when running Traefik on Nomad.

    The example in that tutorial configures the tag traefik.http.routers.http.rule=Path('/myapp') on the service so that requests for /myapp are routed to the backend service instance. In your case, you'll need to modify this to match on the HTTP Host header so that you can route subdomains to different services. For example:

    tags = [
      "traefik.enable=true",
      "traefik.http.routers.http.rule=Host(`app1.example.com`)",
    ]
    

    See https://doc.traefik.io/traefik/routing/routers/#rule for a full list of supported rules.