Nomad without consul ? - service/task fqdn?

Hello,

After spending some time on the documentation I was wondering if there was a way to use nomad without consul ?

Does nomad provide it’s own dns ? Whether it’s possible or not what is the fqdn of a service/task ? I wasn’t able to find an answer in the documentation.

Also, is there a way, with dynamic ports to know the port of another service ? Is there a way to query this type of information with the rest api ?

Thank you very much in advance for any help.

Hi! I don’t think there is a native way to get fqdn of a task in Nomad, but you can use the service discovery from Nomad to get IP and port of a task as a service. Although if you are injecting the service through a template stanza, by default containers will reboot on dependency service change, which is quite annoying. You need to configure change_signal and change_mode in template (although I haven’t tried this myself)

Some people use Traefik as an internal DNS service, so you can use fqdn in this case to connect your tasks, although I haven’t tried myself.

Nomad service discovery.

A job in which you declare a service:

job "grafana-agent" {
    datacenters = ["dc1"]
    group "grafana-agent" {
        network {
            port "grafana-agent-port" {
                to = 9411
            }
        }
     [...]
        task "grafana-agent" {
            service {
            name = "grafana-agent"
            port = "grafana-agent-port"
            provider = "nomad"
            }
     [...]

You can check this service is correct by using the nomad CLI nomad service list

Then you have to use this service in another job.

job "sample" {
    datacenters = ["dc1"]
    group "sample" {
     [...]
        task "sample" {
     [...]
           template {
               destination = "local/env"
               data = <<EOH 
               GRAFANA_AGENT={{ with nomadService "grafana-agent" }}{{ with index . 0 }}{{.Address}}:{{.Port}}{{ end }}{{ end }}
               EOH
               env = true
         }
     […]

This will create an ENV variable called GRAFANA_AGENT in the sample task with the IP and address of the grafana-agent service we declared before. It will be dynamically update.

You have to be careful with the circle dependencies, tho. And I would suggest to check change_signal and change_mode in template, so the sample container will not reboot if the grafana-agent service change its IP or port, or if the grafana-agent reboots.

For more advanced features I would suggest you to try the traefik solution. It seems a more fancy way, so you could balance your traffic with more than one instance dynamically.

I hope this helps! Have a nice day.

Thank you for your quick reply.

Form what you said I suppose that using Nomad with Consul seems a better solution (provider = consul I suppose).

Than I suppose I can get the fqdn the same way as consul ?

The aim here is to not having to be preoccupied by hardcoding the port in my code.

Thank you very ,much for your help

Hi @bigfoot_arch indeed, Nomad’s native service discovery does not yet support DNS. It’s something we do intend to implement in the future but we’re not quite there yet.

If you already have Consul setup in your cluster, then yes just using the Consul service provider (and setting up Consul DNS itself) will get you DNS names for your tasks running in Nomad.

1 Like

Thank you very much for your help and exciting news and for the issue link.

Thank your for your time.