Dear all,
I have Nomad running on a single VM. I have 2 job specs named as rebel-base (2 tasks) and x-wing (1 task). In Kubernetes, I could access the rebel-base pods through a service. For example, I could run the command “curl ” from x-wing pod which then returns a response from rebel-base pod.
Unfortunately I am not able to achieve the same in Nomad. I have created a service using native nomad service discovery. The services are correctly listed down. However, I cannot curl to the service name as in K8S.
I followed the following but I think I am missing something.
Services are registered using the [service] block, with the [provider] parameter with nomad.
task "rebel-base" {
driver = "docker"
service {
name = "rebel-base"
port = "http"
provider = "nomad"
tags = ["rebel-base"]
}
To access services, other allocations can query the catalog using [template] blocks with the [service] function to query the Consul catalog or the [nomadService] function when using Nomad native service discovery.
I have this in the x-wing job specification. I want to access the rebel-base tasks through this x-wing task.
template {
data = <<EOH
{{ range nomadService "rebel-base" }}
"http://{{ .Address }}:{{ .Port }}"
{{ end }}
EOH
destination = "local/env.txt"
}
Inside the x-wing task the I can see the correct service IPs listed as below in local/env.txt
But when I log into the x-wing pod and try to curl to rebel-base or http://127.0.0.1:24956 it says “Failed to connect to [127.0.0.1] port 24956: connection refused.”
Then I tried to access the http://127.0.0.1:24956 from the VM where I installed Nomad. It gave me the result correctly. However, when I try to access service (curl rebel-base) it says cannot resolve host: rebel-base.
nomad service list
Service Name Tags
rebel-base [rebel-base]
nomad service info rebel-base
Job ID Address Tags Node ID Alloc ID
rebel-base [rebel-base] 0abf806b 7945615d
rebel-base [rebel-base] 0abf806b a14a3e76127.0.0.1:24956127.0.0.1:23016
Am I missing something here? Your kind help would be much appreciated.
Thank you!