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