iT邦幫忙

2021 iThome 鐵人賽

DAY 6
0
DevOps

Hashicorp Jot Notes系列 第 6

Day 6. Hashicorp Nomad: Submit a Job

Hashicorp Nomad: Submit a Job

今天來寫最基本的提交工作(Submit a Job)

Submit

提交工作的指令: nomad job run hello-world.nomad
但提交後但你怎麼知道

  • 改了一堆,改了甚麼?
  • 幾百行的code有沒有漏改或改錯?
  • 現有worker node的資源夠不夠?
  • 能不能讓我測試一下?

Dry-run

所以有一個指令可以用來測試: 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.

check-index

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

上一篇
Day 5. Hashicorp Nomad: How to configure one service advertise multiple ports
下一篇
Day 7. Hashicorp Nomad: Inspect a job
系列文
Hashicorp Jot Notes30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言