The integration Nomad with Consul error

Hi team,
I tried to test the integration Nomad with Consul but it doesn’t work well.

As the environment, there is the state that consul agent and nomad agent are running.

The nomad config file hello-consul.nomad is the below.

job "hello-consul" {
  datacenters = ["dc1"]

  type = "service"

  group "web-server" {
    network {
      port "nginx" {
        static = "80"
      }
    }
    count = 1
    task "nginx" {

      service {
        name = "nginx"
        tags = ["nginx", "nomad"]
        meta {
          meta = "for your service"
        }
        check {
          type     = "http"
          protocol = "http"
          port     = "nginx"
          interval = "10s"
          timeout  = "2s"
          path = "/index.html"
        }
      }

      driver = "docker"

      config {
        image = "nginx"
      }

      resources {
        cpu    = 500
        memory = 256
      }
    }
  }
}

I ran the job file by nomad command, but it failed due to progress deadline.

nomad job run hello-consul.nomad
==> 2024-09-07T22:49:46+09:00: Monitoring evaluation "5c7bcd0f"
    2024-09-07T22:49:46+09:00: Evaluation triggered by job "hello-consul"
    2024-09-07T22:49:47+09:00: Evaluation within deployment: "16b35e7b"
    2024-09-07T22:49:47+09:00: Allocation "ae6e786a" created: node "46d686f2", group "web-server"
    2024-09-07T22:49:47+09:00: Evaluation status changed: "pending" -> "complete"
==> 2024-09-07T22:49:47+09:00: Evaluation "5c7bcd0f" finished with status "complete"
==> 2024-09-07T22:49:47+09:00: Monitoring deployment "16b35e7b"
  ⠧ Deployment "16b35e7b" in progress...
  ! Deployment "16b35e7b" failed

    2024-09-07T22:59:46+09:00
    ID          = 16b35e7b
    Job ID      = hello-consul
    Job Version = 1
    Status      = failed
    Description = Failed due to progress deadline

    Deployed
    Task Group  Desired  Placed  Healthy  Unhealthy  Progress Deadline
    web-server  1        1       0        1          2024-09-07T22:59:46+09:00

I checked by the alloc status command, but I didn’t find the cause.

% nomad alloc status 5f8b68b8
ID                  = 5f8b68b8-ffda-ff03-719d-cd36480f89b8
Eval ID             = ce461178
Name                = hello-consul.web-server[0]
Node ID             = 46d686f2
Node Name           = tomoki.maeda-KM06N7TJRX
Job ID              = hello-consul
Job Version         = 2
Client Status       = running
Client Description  = Tasks are running
Desired Status      = run
Desired Description = <none>
Created             = 29s ago
Modified            = 24s ago
Deployment ID       = 0ad70904
Deployment Health   = unset

Allocation Addresses:
Label   Dynamic  Address
*nginx  yes      2001:268:c20d:1df8:1cd9:aa5d:da9c:ac5f:80

Task "nginx" is "running"
Task Resources:
CPU        Memory          Disk     Addresses
0/100 MHz  10 MiB/128 MiB  300 MiB

Task Events:
Started At     = 2024-09-07T14:02:30Z
Finished At    = N/A
Total Restarts = 0
Last Restart   = N/A

Recent Events:
Time                       Type        Description
2024-09-07T23:02:30+09:00  Started     Task started by client
2024-09-07T23:02:26+09:00  Driver      Downloading image
2024-09-07T23:02:26+09:00  Task Setup  Building Task Directory
2024-09-07T23:02:26+09:00  Received    Task received by client

Hi. Check consul website,click on tge nginx service and see the healthcheck.

Probably it is green now, but could have been red on startup.

Hi @Kamilcuk ,

Now I fixed the nomad config, and it worked well.

job "hello-consul" {
  datacenters = ["dc1"]

  type = "service"

  group "web-server" {
    count = 1
    network {
      port "nginx" {
        static = "80"
      }
    }

    service {
        name = "nginx"
        tags = ["nginx", "nomad"]
        meta {
          meta = "for your service"
        }
        check {
          type     = "http"
          port = "nginx"
          interval = "10s"
          timeout  = "2s"
          path = "/index.html"
        }
    }

    task "nginx" {
      driver = "docker"

      config {
        image = "nginx"
        ports = ["nginx"]
      }

      resources {
        cpu    = 500
        memory = 256
      }
    }
  }
}

Thank you so much.