Group->network vs. group->task->resources->network

I’m new to nomad, and playing around with it. I’m getting a simple http-echo service up and going.

I have two configs that are mostly identical. If I define a network stanza directly under “group” like so:

group "webs" {
    network {
        port "http" {}

And then use “http” as the port for the service stanza’s ‘check’ stanza, all will work, but the health checks will fail.

However, if I put the network stanza down in the resources stanza in the task stanza, the health check works.

The two files are here: this_one_doesnt.hcl · GitHub

Soooo…why? :slight_smile:

I’ve been reading a lot of the docs, getting started guides, etc. If I missed something in the docs, please feel free to point it out.

Hi @joshua,

Declaring network inside resources has been deprecated (I think it happened on v0.12.0), so you should always define it at the group level. If you are using a more recent version Nomad task level network might not work.

Since this is a fairly recent change, you might still find job files that use the old syntax, which can be quite confusing…please let us know if you come across any outdated examples in our documentation.

Thank you :grinning_face_with_smiling_eyes:

Thank you for the quick reply. The problem I’m hitting is that if I define the network at the group level, the job seems to run, but the health checks fail. If it put it resources, the health checks work. Please take a look at the Github Gist linked in the original post.

Ahh sorry, I thought the task one was failing.

The only thing you seem to be missing is allocating the group port to the task, so add this line to your job file:

job "echo" {
  group "webs" {
    task "frontend" {
      # Specify the driver to be "docker". Nomad supports
      # multiple drivers.
      driver = "docker"

      # Configuration is specific to each driver.
      config {
        image = "hashicorp/http-echo"
        args  = ["-text", "Hello Dominent Hedge", "-listen", ":${NOMAD_PORT_http}"]
+       ports = ["http"]

After that the Consul healthcheck will be able to reach your app:

Thank you for the solution! That does indeed work. I would suggest updating this page: Job Specification | Nomad by HashiCorp as that was what I was working from, and it does not have the “ports” parameter in the “config” section.

Thanks again!

1 Like

Great! Glad it’s working now :slightly_smiling_face:

And thank you for the pointer to where we can our docs. I’ve opened a PR to add ports to the example.

1 Like