今天來寫最基本的提交工作(Submit a Job)
提交工作的指令: nomad job run hello-world.nomad
但提交後但你怎麼知道
所以有一個指令可以用來測試: nomad job plan hello-world.nomad
它會告訴你修改了那些地方,如下的例子:
我修改了image的版本,由"nginx:1.19.2" => "nginx:1.21",
dry-run的結果告訴我 All tasks successfully allocated.
並顯示修改了哪些地方
$ nomad job plan hello-world.nomad
+/- Job: "hello-world"
+/- Task Group: "webfront" (1 create/destroy update)
+/- Task: "nginx" (forces create/destroy update)
+/- Config {
+/- image: "nginx:1.19.2" => "nginx:1.21"
port_map[0][web]: "80"
}
Scheduler dry-run:
- All tasks successfully allocated.
Job Modify Index: 748164
To submit the job with version verification run:
nomad job run -check-index 748164 nginx.nomad
When running the job with the check-index flag, the job will only be run if the
job modify index given matches the server-side version. If the index has
changed, another user has modified the job and the plan's results are
potentially invalid.
Dry-run 成功後就可以提交工作了?
在團體開發的環境下,直接執行nomad job plan hello-world.nomad
, 要怎麼確保執行的是當下的job呢?
可能下一秒別人就修改了job, 所以Nomad在每次dry-run後都會提供一個Job Modify Index
,透過index來保證執行的是當下plan job後的的內容。
但如果在submit job之前,有人又做了plan job得到新的index,則會造成舊的index, submit無效。
Job Modify Index: 748164
To submit the job with version verification run:
nomad job run -check-index 748164 nginx.nomad