/
nats_group.nomad
82 lines (60 loc) · 1.62 KB
/
nats_group.nomad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0
//
// This job runs a pair of nats-server and prometheus-nats-exporter tasks
//
// A isolated network stack is defined at group level and both
// tasks will join it.
//
// The exporter tasks can thus access the servers http monitoring port without
// exposing it.
//
//
// A curl http://<your-ip>:7777/metrics hits the exporter which in turn grabs
// values from the nats-server
//
job "nats" {
datacenters = ["dc1"]
type = "service"
group "nats" {
// Expose the default port for nats clients and
// also the exporters http endpoint
network {
// define a shared network namespace for all tasks in this group
mode = "bridge"
port "server" { static = 4222 }
port "exporter" { static = 7777 }
}
task "server" {
driver = "podman"
// no "lifecycle" task: this is the main workload
// server configuration file
template {
change_mode = "noop"
destination = "local/nats-server.conf"
data = file("./templates/nats-server.conf.tpl")
}
config {
image = "docker://nats:2.2.6"
ports = [
"server"
]
}
}
task "exporter" {
driver = "podman"
config {
image = "docker://natsio/prometheus-nats-exporter:0.7.0"
// NOTE: this example does not bind the servers monitoring port to localhost due
// nomad issue #10014
args = [
"-varz",
"http://${NOMAD_IP_server}:8222"
]
ports = [
"exporter"
]
}
}
}
}