I ran a Spring job using Nomad.
I want to load these Spring jobs with Nginx job.
Here is my environment:
- The namespace of Spring job is dev.
- The namespace of Nginx job is ops.
- I want to discover using nomadService in template stanza.
- However, Spring Service (namespace=dev) is not called from Nginx job (namespace=ops).
- Here are the methods I tried:
- spring-boot.dev
- dev.spring-boot
But neither method worked.
We need your help!
##########################################
My Spring job
job "spring-boot-hello" {
datacenters = ["dc1"]
namespace = "dev"
type = "service"
constraint {
attribute = "${attr.driver.java.version}"
operator = ">"
value = "17.0"
}
group "run-spring-boot" {
count = 3
network {
port "boot" {
#static = 8080
}
}
task "java" {
driver = "java"
config {
jar_path = "local/hashitalks-0.0.1-SNAPSHOT.jar"
jvm_options = ["-Xmx2048m", "-Xms256m"]
}
env {
PORT = "${NOMAD_PORT_boot}"
COLOR = "skyblue"
}
artifact {
source = "https://github.com/Great-Stone/images/raw/master/build/hashitalks-0.0.1-SNAPSHOT.jar"
destination = "local/"
}
resources {
cpu = 500
memory = 256
memory_max = 2048
}
service {
provider = "nomad"
name = "spring-boot"
port = "boot"
check {
type = "http"
path = "/hello"
interval = "2s"
timeout = "2s"
}
}
}
}
}
My nginx job
job "nginx" {
datacenters = ["dc1"]
namespace = "ops"
node_pool="default"
group "nginx" {
count = 1
network {
port "http" {
static = 8080
}
}
service {
name = "nginx"
port = "http"
provider="nomad"
}
task "nginx" {
driver = "docker"
config {
image = "nginx"
ports = ["http"]
volumes = [
"local:/etc/nginx/conf.d",
]
}
template {
data = <<EOF
upstream backend {
{{ range nomadService "spring-boot" }} #
server {{ .Address }}:{{ .Port }}; # Tomcat
{{ else }}server 127.0.0.1:65535; # force a 502
{{ end }}
}
server {
#listen {{ env "NOMAD_PORT_http" }};
listen 80;
location /sample {
proxy_pass http://backend;
}
location /status {
stub_status on;
}
}
EOF
destination = "local/load-balancer.conf"
change_mode = "signal"
change_signal = "SIGHUP"
}
}
}
}
}