Dear all,
I have a Nomad server node and a client node.
Nomad server node config:
data_dir = "/opt/nomad/data"
bind_addr = "0.0.0.0"
server {
enabled = true
bootstrap_expect = 1
}
advertise {
http = "192.168.40.10:4646"
rpc = "192.168.40.10:4647"
serf = "192.168.40.10:4648"
}
client {
enabled = false # Disable the client on the server
}
#consul {
#address = "192.168.60.10:8500"
#checks_use_advertise = true
#}
Nomad client node config:
client {
enabled = true
servers = ["192.168.40.10:4647"]
# host_volume "nomad-vol1" {
# path = "/home/ubuntu/nomad/nomad-vol1/"
# read_only = false
# }
options {
"docker.privileged.enabled" = "true"
"docker.caps.whitelist" = "NET_RAW,NET_ADMIN"
}
}
plugin "docker" {
config {
allow_privileged = true
volumes {
enabled = true
}
}
}
data_dir = "/opt/nomad/data"
bind_addr = "0.0.0.0"
advertise {
http = "192.168.40.11:4646"
}
server {
enabled = false # Disable server functionality on the client node
}
consul {
address = "127.0.0.1:8500"
checks_use_advertise = true
}
Also, I have installed Consul on Nomad Client Node and configured it as a Consul Client.
Consul Config:
data_dir = "/opt/consul"
client_addr = "0.0.0.0"
bind_addr = "192.168.40.11"
server = false
advertise_addr = "192.168.40.11"
retry_join = ["192.168.60.10"]
log_level = "DEBUG"
I have a VM running the Consul server externally on IP 192.168.60.10. That config is as below; /etc/consul.d/consul.hcl
data_dir = "/opt/consul"
bind_addr = "192.168.60.10"
client_addr = "0.0.0.0" #Allow connections from any client
ui_config{
enabled = true
}
server = true
advertise_addr = "192.168.60.10"
bootstrap_expect=1
retry_join = ["192.168.60.10"]
ports {
grpc = 8502
}
connect {
enabled = true
}
#log_level = "DEBUG"
config_entries {
bootstrap = [
{
Kind = "proxy-defaults"
Name = "global"
AccessLogs {
Enabled = true
#Type = "stderr"
}
Config {
protocol = "http"
}
}
]
}
I was able to deploy a job in Nomad and successfully register it in the Consul UI. The job spec is as below;
job "nginx" {
datacenters = ["dc1"] # Specify your datacenter
type = "service"
group "nginx" {
count = 1 # Number of instances
network {
mode = "bridge"
port "http" {
to = 80
}
}
task "nginx" {
driver = "docker"
config {
image = "nginx:alpine"
# Entry point to write message into index.html and start nginx
entrypoint = [
"/bin/sh", "-c",
"echo 'Hello, I am running on Nomad!' > /usr/share/nginx/html/index.html && nginx -g 'daemon off;'"
]
}
resources {
cpu = 500 # CPU units
memory = 256 # Memory in MB
}
service {
name = "nginx-service"
port = "http" # Reference the network port defined above
tags = ["nginx", "nomad"]
connect {
sidecar_service {
proxy {
transparent_proxy {}
}
}
}
check {
type = "http"
path = "/"
interval = "10s"
timeout = "2s"
}
}
}
}
}
When tis job is run it succeed and shows in both Nomad and Consul UI under service Nginx-service.
However, when I try to run the below job spec it gives error " * Constraint "${attr.consul.grpc} > 0": 1 nodes excluded by filter
"
nomad job run test-pod.nomad.hcl
==> 2024-09-29T18:58:17Z: Monitoring evaluation "b199d95f"
2024-09-29T18:58:17Z: Evaluation triggered by job "nomad-test-pod"
2024-09-29T18:58:18Z: Evaluation within deployment: "89d7cd6b"
2024-09-29T18:58:18Z: Evaluation status changed: "pending" -> "complete"
==> 2024-09-29T18:58:18Z: Evaluation "b199d95f" finished with status "complete" but failed to place all allocations:
2024-09-29T18:58:18Z: Task Group "test-pod" (failed to place 1 allocation):
* Constraint "${attr.consul.grpc} > 0": 1 nodes excluded by filter
2024-09-29T18:58:18Z: Evaluation "038c63a4" waiting for additional capacity to place remainder
==> 2024-09-29T18:58:18Z: Monitoring deployment "89d7cd6b"
⠙ Deployment "89d7cd6b" in progress...
What I don’t understand is why it gives this error? This job spec is similar to the successfully running job spec. I didn’t got this Consul error while running the Nginx job spec. Is there anything I am missing here.
Consul UI
Nomad UI
I am grateful for your kind advices and help.
Thank you!