Skip List
Placing job task on certain node
Specific node wildcard
Do not place jobs on same host
Distinct property
constraint {
attribute = "${node.unique.name}"
operator = "regexp"
value = "agent.*" # Regex selector
}
constraint {
operator = "distinct_hosts"
value = "true"
}
constraint {
operator = "distinct_property"
attribute = "${meta.rack}"
value = "3"
}
Instructs the scheduler to select nodes that have a distinct value of the specified property. The value parameter specifies how many allocations are allowed to share the value of a property. The value must be 1 or greater and if omitted, defaults to 1.
Think to note here is that after applying the job the tasks may not be shut-down on previous selector because target node may not exists and to prevent the outage it will stay the same. It depends on configuration.
Running JAR from URL
// TODO
Running Docker Image
job "running-nexus-in-docker" {
type = "service"
datacenters = ["dc1"]
task "jar" {
driver = "docker"
config {
image = "sonatype/nexus3"
labels {
group = "nexus"
}
}
}
}
Limiting Task Resource Usage
Memory/cores usage
job "running-nexus-in-docker" {
type = "service"
datacenters = ["dc1"]
task "jar" {
driver = "docker"
config {
image = "sonatype/nexus3"
labels {
group = "nexus"
}
}
resources {
memory = 1024
cores = 2
}
}
}
Using Consul keys/values and reacting to changes
job "fetch-consul-key" {
datacenters = ["dc1"]
group "cache" {
task "consul-echo-key" {
driver = "docker"
template {
destination = "/local/config"
data = <<EOF
CONSUL_KEY={{ key "consul-key" }}
EOF
env = true
}
config {
image = "redis:3.2"
network_mode = "host"
command = "sh"
args = ["-c", "echo $CONSUL_KEY; sleep 10000"]
}
resources {
cpu = 500 # 500 MHz
memory = 256 # 256MB
}
}
}
}
Usually all files are placed in /local/* directory.