0

具有以下作业配置。curl NOMAD_IP_http:NOMAD_PORT_http无法访问 http-echo 服务。

本地主机上没有用于传入请求的侦听端口。

为什么以及如何访问 http-echo 服务


job "job" {
  datacenters = ["dc1"]
  group "group" {
    count = 2
    network {        
      port "http" {}
    }
    service {
      name = "http-echo"
      port = "http"
      tags = [
        "http-echo",
      ]
      check {
        type      = "http"
        path      = "/health"
        interval  = "30s"
        timeout   = "2s"
      }
    }
    task "task" {
      driver = "docker"
      config {
        image = "hashicorp/http-echo:latest"
        args = [
          "-listen", ":${NOMAD_PORT_http}",
          "-text", "Hello and welcome to ${NOMAD_IP_http} running on port ${NOMAD_PORT_http}",
        ]
      }
      resources {}
    }
  }
}

更新

配置驱动网络模式后,卷曲成功。

network_mode = "host"

4

1 回答 1

0

你忘了portsjob -> group -> task ->ports

现在它适用于最新的 nomad(v1.1.3+)。

job "job" {
  datacenters = ["dc1"]
  group "group" {
    count = 2
    network {        
      port "http" {}
      # or maps to container's default port
      # port "http" {
      #    to = 5678
      # }
      # 
    }
    service {
      name = "http-echo"
      port = "http"
      tags = [
        "http-echo",
      ]
      check {
        type      = "http"
        path      = "/health"
        interval  = "30s"
        timeout   = "2s"
      }
    }
    task "task" {
      driver = "docker"
      config {
        image = "hashicorp/http-echo:latest"
        args = [
          "-listen", ":${NOMAD_PORT_http}",
          "-text", "Hello and welcome to ${NOMAD_IP_http} running on port ${NOMAD_PORT_http}",
        ]
        ports = ["http"]
      }
      resources {}
    }
  }
}

然后运行 ​​docker ps,你将得到映射的端口,并且 curl 工作。

于 2021-08-04T16:32:05.063 回答