github.com/ferranbt/nomad@v0.9.3-0.20190607002617-85c449b7667c/website/source/docs/job-specification/job.html.md (about) 1 --- 2 layout: "docs" 3 page_title: "job Stanza - Job Specification" 4 sidebar_current: "docs-job-specification-job" 5 description: |- 6 The "job" stanza is the top-most configuration option in the job 7 specification. A job is a declarative specification of tasks that Nomad 8 should run. 9 --- 10 11 # `job` Stanza 12 13 <table class="table table-bordered table-striped"> 14 <tr> 15 <th width="120">Placement</th> 16 <td> 17 <code>**job**</code> 18 </td> 19 </tr> 20 </table> 21 22 The `job` stanza is the top-most configuration option in the job specification. 23 A job is a declarative specification of tasks that Nomad should run. Jobs have a 24 globally unique name, one or many task groups, which are themselves collections 25 of one or many tasks. 26 27 ```hcl 28 job "docs" { 29 constraint { 30 # ... 31 } 32 33 datacenters = ["us-east-1"] 34 35 group "example" { 36 # ... 37 } 38 39 meta { 40 "my-key" = "my-value" 41 } 42 43 parameterized { 44 # ... 45 } 46 47 periodic { 48 # ... 49 } 50 51 priority = 100 52 53 region = "north-america" 54 55 task "docs" { 56 # ... 57 } 58 59 update { 60 # ... 61 } 62 } 63 ``` 64 65 ## `job` Parameters 66 67 - `all_at_once` `(bool: false)` - Controls whether the scheduler can make 68 partial placements if optimistic scheduling resulted in an oversubscribed 69 node. This does not control whether all allocations for the job, where all 70 would be the desired count for each task group, must be placed atomically. 71 This should only be used for special circumstances. 72 73 - `constraint` <code>([Constraint][constraint]: nil)</code> - 74 This can be provided multiple times to define additional constraints. See the 75 [Nomad constraint reference](/docs/job-specification/constraint.html) for more 76 details. 77 78 - `affinity` <code>([Affinity][affinity]: nil)</code> - 79 This can be provided multiple times to define preferred placement criteria. See the 80 [Nomad affinity reference](/docs/job-specification/affinity.html) for more 81 details. 82 83 - `spread` <code>([Spread][spread]: nil)</code> - This can be provided multiple times 84 to define criteria for spreading allocations across a node attribute or metadata. 85 See the [Nomad spread reference](/docs/job-specification/spread.html) for more details. 86 87 - `datacenters` `(array<string>: <required>)` - A list of datacenters in the region which are eligible 88 for task placement. This must be provided, and does not have a default. 89 90 - `group` <code>([Group][group]: \<required\>)</code> - Specifies the start of a 91 group of tasks. This can be provided multiple times to define additional 92 groups. Group names must be unique within the job file. 93 94 - `meta` <code>([Meta][]: nil)</code> - Specifies a key-value map that annotates 95 with user-defined metadata. 96 97 - `migrate` <code>([Migrate][]: nil)</code> - Specifies the groups strategy for 98 migrating off of draining nodes. If omitted, a default migration strategy is 99 applied. Only service jobs with a count greater than 1 support migrate stanzas. 100 101 - `namespace` `(string: "default")` - The namespace in which to execute the job. 102 Values other than default are not allowed in non-Enterprise versions of Nomad. 103 104 - `parameterized` <code>([Parameterized][parameterized]: nil)</code> - Specifies 105 the job as a parameterized job such that it can be dispatched against. 106 107 - `periodic` <code>([Periodic][]: nil)</code> - Allows the job to be scheduled 108 at fixed times, dates or intervals. 109 110 - `priority` `(int: 50)` - Specifies the job priority which is used to 111 prioritize scheduling and access to resources. Must be between 1 and 100 112 inclusively, with a larger value corresponding to a higher priority. 113 114 - `region` `(string: "global")` - The region in which to execute the job. 115 116 - `reschedule` <code>([Reschedule][]: nil)</code> - Allows to specify a 117 rescheduling strategy. Nomad will then attempt to schedule the task on another 118 node if any of its allocation statuses become "failed". 119 120 - `type` `(string: "service")` - Specifies the [Nomad scheduler][scheduler] to 121 use. Nomad provides the `service`, `system` and `batch` schedulers. 122 123 - `update` <code>([Update][update]: nil)</code> - Specifies the task's update 124 strategy. When omitted, rolling updates are disabled. 125 126 - `vault` <code>([Vault][]: nil)</code> - Specifies the set of Vault policies 127 required by all tasks in this job. 128 129 - `vault_token` `(string: "")` - Specifies the Vault token that proves the 130 submitter of the job has access to the specified policies in the 131 [`vault`][vault] stanza. This field is only used to transfer the token and is 132 not stored after job submission. 133 134 !> It is **strongly discouraged** to place the token as a configuration 135 parameter like this, since the token could be checked into source control 136 accidentally. Users should set the `VAULT_TOKEN` environment variable when 137 running the job instead. 138 139 ## `job` Examples 140 141 The following examples only show the `job` stanzas. Remember that the 142 `job` stanza is only valid in the placements listed above. 143 144 ### Docker Container 145 146 This example job starts a Docker container which runs as a service. Even though 147 the type is not specified as "service", that is the default job type. 148 149 ```hcl 150 job "docs" { 151 datacenters = ["default"] 152 153 group "example" { 154 task "server" { 155 driver = "docker" 156 config { 157 image = "hashicorp/http-echo" 158 args = ["-text", "hello"] 159 } 160 161 resources { 162 memory = 128 163 } 164 } 165 } 166 } 167 ``` 168 169 ### Batch Job 170 171 This example job executes the `uptime` command on 10 Nomad clients in the fleet, 172 restricting the eligible nodes to Linux machines. 173 174 ```hcl 175 job "docs" { 176 datacenters = ["default"] 177 178 type = "batch" 179 180 constraint { 181 attribute = "${attr.kernel.name}" 182 value = "linux" 183 } 184 185 group "example" { 186 count = 10 187 task "uptime" { 188 driver = "exec" 189 config { 190 command = "uptime" 191 } 192 } 193 } 194 } 195 ``` 196 197 ### Consuming Secrets 198 199 This example shows a job which retrieves secrets from Vault and writes those 200 secrets to a file on disk, which the application then consumes. Nomad handles 201 all interactions with Vault. 202 203 ```hcl 204 job "docs" { 205 datacenters = ["default"] 206 207 group "example" { 208 task "cat" { 209 driver = "exec" 210 211 config { 212 command = "cat" 213 args = ["local/secrets.txt"] 214 } 215 216 template { 217 data = "{{ secret \"secret/data\" }}" 218 destination = "local/secrets.txt" 219 } 220 221 vault { 222 policies = ["secret-readonly"] 223 } 224 } 225 } 226 } 227 ``` 228 229 When submitting this job, you would run: 230 231 ``` 232 $ VAULT_TOKEN="..." nomad job run example.nomad 233 ``` 234 235 [constraint]: /docs/job-specification/constraint.html "Nomad constraint Job Specification" 236 [affinity]: /docs/job-specification/affinity.html "Nomad affinity Job Specification" 237 [spread]: /docs/job-specification/spread.html "Nomad spread Job Specification" 238 [group]: /docs/job-specification/group.html "Nomad group Job Specification" 239 [meta]: /docs/job-specification/meta.html "Nomad meta Job Specification" 240 [migrate]: /docs/job-specification/migrate.html "Nomad migrate Job Specification" 241 [parameterized]: /docs/job-specification/parameterized.html "Nomad parameterized Job Specification" 242 [periodic]: /docs/job-specification/periodic.html "Nomad periodic Job Specification" 243 [reschedule]: /docs/job-specification/reschedule.html "Nomad reschedule Job Specification" 244 [task]: /docs/job-specification/task.html "Nomad task Job Specification" 245 [update]: /docs/job-specification/update.html "Nomad update Job Specification" 246 [vault]: /docs/job-specification/vault.html "Nomad vault Job Specification" 247 [scheduler]: /docs/schedulers.html "Nomad Scheduler Types"