Nomad 작업 명세
Nomad 작업 명세 (Nomad job specification)
Nomad 작업 명세(jobspec)는 Nomad 작업의 스키마를 정의해요. Nomad 작업은 HCL로 지정하며, HCL은 사람이 읽고 편집하기 쉬우면서도 기계 친화적인 균형을 추구해요.
출처: 문서
본문
작업 명세는 더 작은 여러 조각으로 나뉘며, 내비게이션 메뉴에서 그 내용을 확인할 수 있어요. 작업(job) 블록부터 시작하는 것을 권장해요. 또는 계속 읽으면서 몇 가지 예제를 볼 수도 있어요.
Nomad HCL은 명령줄에서 파싱되어 HTTP API를 통해 JSON 형식으로 Nomad에 전송돼요.
작업의 일반적인 계층 구조는 다음과 같아요:
job
\_ group
| \_ task
| \_ task
|
\_ group
\_ task
\_ task
각 작업 파일에는 단 하나의 작업만 존재해요. 하지만 작업은 여러 그룹을 가질 수 있고, 각 그룹은 여러 태스크를 가질 수 있어요. 그룹은 동일한 Nomad 클라이언트에 함께 배치되는 태스크 집합이에요.
예제 (Example)
이 예제는 샘플 작업 파일을 보여줘요. 가능한 한 단순하게 유지하면서도 Nomad의 힘을 보여주려고 했어요. 이 필드들에 대한 더 자세한 설명은 내비게이션을 사용해 더 깊이 들어가 보세요.
# This declares a job named "docs". There can be exactly one
# job declaration per job file.
job "docs" {
# Specify this job should run in the region named "us". Regions
# are defined by the Nomad servers' configuration.
region = "us"
# Spread the tasks in this job between us-west-1 and us-east-1.
datacenters = ["us-west-1", "us-east-1"]
# Run this job as a "service" type. Each job type has different
# properties. See the documentation below for more examples.
type = "service"
# Specify this job to have rolling updates, two-at-a-time, with
# 30 second intervals.
update {
stagger = "30s"
max_parallel = 2
}
# A group defines a series of tasks that should be co-located
# on the same client (host). All tasks within a group will be
# placed on the same host.
group "webs" {
# Specify the number of these tasks we want.
count = 5
network {
# This requests a dynamic port named "http". This will
# be something like "46283", but we refer to it via the
# label "http".
port "http" {}
# This requests a static port on 443 on the host. This
# will restrict this task to running once per host, since
# there is only one port 443 on each host.
port "https" {
static = 443
}
}
# The service block tells Nomad how to register this service
# with Consul for service discovery and monitoring.
service {
# This tells Consul to monitor the service on the port
# labelled "http". Since Nomad allocates high dynamic port
# numbers, we use labels to refer to them.
port = "http"
check {
type = "http"
path = "/health"
interval = "10s"
timeout = "2s"
}
}
# Create an individual task (unit of work). This particular
# task utilizes a Docker container to front a web application.
task "frontend" {
# Specify the driver to be "docker". Nomad supports
# multiple drivers.
driver = "docker"
# Configuration is specific to each driver.
config {
image = "hashicorp/web-frontend"
ports = ["http", "https"]
}
# It is possible to set environment variables which will be
# available to the task when it runs.
env {
DB_HOST = "db01.example.com"
DB_USER = "web"
DB_PASS = "loremipsum"
}
# Specify the maximum resources required to run the task,
# include CPU and memory.
resources {
cpu = 500 # MHz
memory = 128 # MB
}
}
}
}
service 블록은 그룹 수준에서도 지정할 수 있어요. 이를 통해 작업 명세 작성자가 서비스를 만들고 Consul Service Mesh에 등록할 수 있어요. 그룹 수준에서 지정한 service 블록은 다음 스니펫처럼 connect 블록을 포함해야 해요.
service {
name = "count-api"
port = "9001"
connect {
sidecar_service {}
}
}