Blog
June 15, 2022

Traefik Proxy Now Fully Integrates with Hashicorp Nomad

traefik integrates with nomad

We are thrilled to announce the full integration of the new Nomad built-in Service Discovery with Traefik Proxy. This is a first-of-its-kind ingress integration that simplifies ingress in HashiCorp Nomad. Utilizing Nomad directly with Traefik Proxy has never been so easy!

In early May, Hashicorp announced Nomad Version 1.3. Among other updates, it also includes a nice list of improvements on usability and developer experience. Before this release, when using service discovery with Nomad, Traefik Proxy users had to use Hashicorp Consul and Nomad side-by-side in order to benefit from Traefik Proxy’s famous automatic configuration. Now, Nomad has a simple and straightforward way to use service discovery built-in. This improves direct usability a lot! Not only in simple test environments but also on the edge.

nomad webinar traefik nomad logo
Webinar: Simplify Networking in Nomad with the New Traefik IntegrationSee how the new Nomad Provider streamlines load balancing, ingress routing, dynamic configuration, and more with Traefik.Register Now

With this great new addition, the major question remained: How can you utilize the new Nomad Service Discovery directly with an ingress? To provide you with an answer, we worked closely together with Hashicorp to get a first implementation of those new APIs in Traefik Proxy.

This is a big step, and we are very excited to be the first ingress and reverse proxy that integrates natively with the new Nomad Service Discovery. Traefik Proxy (and soon Enterprise) users can now utilize the new Nomad provider in Traefik Proxy, to unlock its full potential directly with Nomad, as it was possible previously only with Consul.

The main driving force behind our Nomad integration in Traefik was always you, our community. We know that our Nomad community is really large and active, and uses Traefik in a lot of different ways. Therefore, it was only logical to provide our community with this additional new integration.

Let’s dig in and see how this integration works.

Set up Traefik Proxy with the new Nomad Service Discovery

Utilizing a new provider with Traefik Proxy is simple and straightforward. First, make sure that you have Nomad set up with the required version. Remember, the minimum required version is 1.3.0.

nomad -v
Nomad v1.3.1 (2b054e38e91af964d1235faa98c286ca3f527e56)

Once that is verified, we can deploy Traefik Proxy. This new integration requires at least version 2.8-rc1. With that version, you can enable the new provider as seen below:

job "traefik" {
  datacenters = ["dc1"]
  type        = "service"

  group "traefik" {
    count = 1

    network {
      port  "http"{
         static = 80
      }
      port  "admin"{
         static = 8080
      }
    }

    service {
      name = "traefik-http"
      provider = "nomad"
      port = "http"
    }

    task "server" {
      driver = "docker"
      config {
        image = "traefik:2.8-rc1"
        ports = ["admin", "http"]
        args = [
          "--api.dashboard=true",
          "--api.insecure=true", ### For Test only, please do not use that in production
          "--entrypoints.web.address=:${NOMAD_PORT_http}",
          "--entrypoints.traefik.address=:${NOMAD_PORT_admin}",
          "--providers.nomad=true",
          "--providers.nomad.endpoint.address=http://192.168.178.39:4646" ### IP to your nomad server 
        ]
      }
    }
  }
}

Once Traefik Proxy is up and running with the dashboard enabled (for test purposes), you can verify that the provider is correctly enabled:

With that verified, you can now deploy your first service. In order to enable the new Service Discovery for a service, you need to enable it in the service stanza. In the service stanza there is now a provider option which needs to be set to nomad. Below you see a full example using the sample Traefik Proxy application whoami.

job "whoami" {
  datacenters = ["dc1"]

  type = "service"

  group "demo" {
    count = 1

    network {
       port "http" {
         to = 80
       }
    }

    service {
      name = "whoami-demo"
      port = "http"
      provider = "nomad"

      tags = [
        "traefik.enable=true",
        "traefik.http.routers.http.rule=Host(`whoami.nomad.localhost`)",
      ]
    }

    task "server" {
      env {
        WHOAMI_PORT_NUMBER = "${NOMAD_PORT_http}"
      }

      driver = "docker"

      config {
        image = "traefik/whoami"
        ports = ["http"]
      }
    }
  }
}

With the service deployed, you should be able to see that Traefik Proxy picked it up quickly in the dashboard as well.

Testing it with a simple curl (make sure to set a host entry!) should work like a charm from here:

curl -v http://whoami.nomad.localhost
*   Trying 10.27.71.49:80...
* Connected to whoami.nomad.localhost (10.27.71.49) port 80 (#0)
> GET / HTTP/1.1
> Host: whoami.nomad.localhost
> User-Agent: curl/7.79.1
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Length: 365
< Content-Type: text/plain; charset=utf-8
< Date: Mon, 06 Jun 2022 11:56:11 GMT
<
Hostname: a65ebc9c1731
IP: 127.0.0.1
IP: 172.17.0.3
RemoteAddr: 172.17.0.1:60030
GET / HTTP/1.1
Host: whoami.nomad.localhost
User-Agent: curl/7.79.1
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 172.17.0.1
X-Forwarded-Host: whoami.nomad.localhost
X-Forwarded-Port: 80
X-Forwarded-Proto: http
X-Forwarded-Server: 08f885acac7d
X-Real-Ip: 172.17.0.1

Conclusion

The new native Service Discovery in Nomad really does work seamlessly. With this integration, delivering load balancing, dynamic routing configuration, and ingress traffic routing become easier than ever. Check out the Traefik Proxy 2.8 Release Candidate and the Nomad 1.3 release notes. You’re also welcome to head over to our Community Forum to share your feedback and ask any questions.

If you want to learn more, register for our upcoming webinar “Simplify Networking in Nomad with New Traefik Integration” on June 30, 2022. You can also join the HashiConf Europe session “Nomad: Past, Present, and Future,” on Tuesday, June 21, and visit the Hashicorp Nomad booth for a demo.

nomad webinar traefik nomad logo
Webinar: Simplify Networking in Nomad with the New Traefik IntegrationSee how the new Nomad Provider streamlines load balancing, ingress routing, dynamic configuration, and more with Traefik.Register Now


About the Author

Latest from Traefik Labs

How to Keep Your Services Secure With Traefik’s Rate Limiting
Blog

How to Keep Your Services Secure With Traefik’s Rate Limiting

Read more
Taming The Wild West of LLMs with Traefik AI Gateway
Blog

Taming The Wild West of LLMs with Traefik AI Gateway

Read more
GitOps-Driven Runtime API Governance: The Secret Sauce for Scale
Webinar

GitOps-Driven Runtime API Governance: The Secret Sauce for Scale

Watch now

Traefik Labs uses cookies to improve your experience. By continuing to browse the site you are agreeing to our use of cookies. Find out more in the Cookie Policy.