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