Nomad
- workload orchestrator (containers, java, vm, windows, binaries)
- single binary (linux, arm, osx, windows)
- unified workflow for deployments
- zero downtime (blue-green, canary, rolling-release)
- batch
- service / system
- easily integrates with Consul and Vault
- plugin system: CSI, CNI
- uses HCL to define workloads
installation
asdf plugin-add nomad
asdf install nomad 1.8.0
asdf local nomad 1.8.0
or developer.hashicorp.com/nomad/downloads
CLI
nomad run <job> # run/update a job
nomad stop <job> # stop a job
nomad status [job] # check status
nomad agent -dev # run agent in dev mode
nomad exec <alloc> sh # exec into allocation
nomad -help # global help
architecture
- Job - declared workload; defines desired state
- Task Group - set of tasks that must run together
- Driver - tool to run a workload (docker, exec, java...)
- Task - smallest unit of work
- Client - machine where tasks run
- Allocation - mapping of task group to client
- Evaluation - scheduling decision mechanism
- Server - brain of the cluster
job
\_ group
\_ task
job spec
job "api" {
datacenters = ["dc1"]
type = "service"
update {
max_parallel = 2
stagger = "30s"
}
group "api" {
count = 3
network {
port "http" {}
}
task "server" {
driver = "docker"
config {
image = "my-org/api:1.2.3"
ports = ["http"]
}
resources {
cpu = 500
memory = 256
}
service {
name = "api"
port = "http"
check {
type = "http"
path = "/health"
interval = "10s"
timeout = "2s"
}
}
}
}
}
dev mode
$ nomad agent -dev
# UI at http://localhost:4646
# do NOT use in production
deployments
rolling update
update {
max_parallel = 1
min_healthy_time = "10s"
healthy_deadline = "3m"
}
canary
update {
canary = 1
max_parallel = 2
auto_promote = false
}
Promote manually after verifying:
nomad deployment promote <deployment-id>
blue-green
update {
canary = 3 # equal to group count
max_parallel = 3
auto_promote = false
}
plan and apply
$ nomad job plan api.nomad
Job Modify Index: 7
To submit with version verification:
nomad run -check-index 7 api.nomad
$ nomad run -check-index 7 api.nomad
history and revert
$ nomad job history api
Version = 3 Stable = true Submit Date = ...
Version = 2 Stable = true Submit Date = ...
Version = 1 Stable = false Submit Date = ...
$ nomad job revert api 2
scheduled batch jobs
job "nightly-report" {
type = "batch"
periodic {
crons = ["0 2 * * *"]
}
group "report" {
task "run" {
driver = "docker"
config {
image = "my-org/reporter:latest"
command = "/app/report"
}
}
}
}
For service discovery and load balancing with Consul - see Consul service discovery.
Originally published at https://bard.sh/posts/nomad_and_consul/
Top comments (0)