github.com/ferranbt/nomad@v0.9.3-0.20190607002617-85c449b7667c/website/source/api/json-jobs.html.md (about) 1 --- 2 layout: api 3 page_title: JSON Job Specification - HTTP API 4 sidebar_current: api-json-jobs 5 description: |- 6 Jobs can also be specified via the HTTP API using a JSON format. This guide 7 discusses the job specification in JSON format. 8 --- 9 10 # JSON Job Specification 11 12 This guide covers the JSON syntax for submitting jobs to Nomad. A useful command 13 for generating valid JSON versions of HCL jobs is: 14 15 ```shell 16 $ nomad job run -output my-job.nomad 17 ``` 18 19 ## Syntax 20 21 Below is the JSON representation of the job outputted by `$ nomad init`: 22 23 ```json 24 { 25 "Job": { 26 "ID": "example", 27 "Name": "example", 28 "Type": "service", 29 "Priority": 50, 30 "Datacenters": [ 31 "dc1" 32 ], 33 "TaskGroups": [{ 34 "Name": "cache", 35 "Count": 1, 36 "Migrate": { 37 "HealthCheck": "checks", 38 "HealthyDeadline": 300000000000, 39 "MaxParallel": 1, 40 "MinHealthyTime": 10000000000 41 }, 42 "Tasks": [{ 43 "Name": "redis", 44 "Driver": "docker", 45 "User": "", 46 "Config": { 47 "image": "redis:3.2", 48 "port_map": [{ 49 "db": 6379 50 }] 51 }, 52 "Services": [{ 53 "Id": "", 54 "Name": "redis-cache", 55 "Tags": [ 56 "global", 57 "cache" 58 ], 59 "PortLabel": "db", 60 "AddressMode": "", 61 "Checks": [{ 62 "Id": "", 63 "Name": "alive", 64 "Type": "tcp", 65 "Command": "", 66 "Args": null, 67 "Header": {}, 68 "Method": "", 69 "Path": "", 70 "Protocol": "", 71 "PortLabel": "", 72 "Interval": 10000000000, 73 "Timeout": 2000000000, 74 "InitialStatus": "", 75 "TLSSkipVerify": false, 76 "CheckRestart": { 77 "Limit": 3, 78 "Grace": 30000000000, 79 "IgnoreWarnings": false 80 } 81 }] 82 }], 83 "Resources": { 84 "CPU": 500, 85 "MemoryMB": 256, 86 "Networks": [{ 87 "Device": "", 88 "CIDR": "", 89 "IP": "", 90 "MBits": 10, 91 "DynamicPorts": [{ 92 "Label": "db", 93 "Value": 0 94 }] 95 }] 96 }, 97 "Leader": false 98 }], 99 "RestartPolicy": { 100 "Interval": 1800000000000, 101 "Attempts": 2, 102 "Delay": 15000000000, 103 "Mode": "fail" 104 }, 105 "ReschedulePolicy": { 106 "Attempts": 10, 107 "Delay": 30000000000, 108 "DelayFunction": "exponential", 109 "Interval": 0, 110 "MaxDelay": 3600000000000, 111 "Unlimited": true 112 }, 113 "EphemeralDisk": { 114 "SizeMB": 300 115 } 116 }], 117 "Update": { 118 "MaxParallel": 1, 119 "MinHealthyTime": 10000000000, 120 "HealthyDeadline": 180000000000, 121 "AutoRevert": false, 122 "Canary": 0 123 } 124 } 125 } 126 ``` 127 128 The example JSON could be submitted as a job using the following: 129 130 ```text 131 $ curl -XPUT -d @example.json http://127.0.0.1:4646/v1/job/example 132 { 133 "EvalID": "5d6ded54-0b2a-8858-6583-be5f476dec9d", 134 "EvalCreateIndex": 12, 135 "JobModifyIndex": 11, 136 "Warnings": "", 137 "Index": 12, 138 "LastContact": 0, 139 "KnownLeader": false 140 } 141 ``` 142 143 ## Syntax Reference 144 145 Following is a syntax reference for the possible keys that are supported and 146 their default values if any for each type of object. 147 148 ### Job 149 150 The `Job` object supports the following keys: 151 152 - `AllAtOnce` - Controls whether the scheduler can make partial placements if 153 optimistic scheduling resulted in an oversubscribed node. This does not 154 control whether all allocations for the job, where all would be the desired 155 count for each task group, must be placed atomically. This should only be 156 used for special circumstances. Defaults to `false`. 157 158 - `Constraints` - A list to define additional constraints where a job can be 159 run. See the constraint reference for more details. 160 161 - `Affinities` - A list to define placement preferences on nodes where a job can be 162 run. See the affinity reference for more details. 163 164 - `Spread` - A list to define allocation spread across attributes. See the spread reference 165 for more details. 166 167 - `Datacenters` - A list of datacenters in the region which are eligible 168 for task placement. This must be provided, and does not have a default. 169 170 - `TaskGroups` - A list to define additional task groups. See the task group 171 reference for more details. 172 173 - `Meta` - Annotates the job with opaque metadata. 174 175 - `Namespace` - The namespace to execute the job in, defaults to "default". 176 Values other than default are not allowed in non-Enterprise versions of Nomad. 177 178 - `ParameterizedJob` - Specifies the job as a parameterized job such that it can 179 be dispatched against. The `ParameterizedJob` object supports the following 180 attributes: 181 182 - `MetaOptional` - Specifies the set of metadata keys that may be provided 183 when dispatching against the job as a string array. 184 185 - `MetaRequired` - Specifies the set of metadata keys that must be provided 186 when dispatching against the job as a string array. 187 188 - `Payload` - Specifies the requirement of providing a payload when 189 dispatching against the parameterized job. The options for this field are 190 "optional", "required" and "forbidden". The default value is "optional". 191 192 - `Payload` - The payload may not be set when submitting a job but may appear in 193 a dispatched job. The `Payload` will be a base64 encoded string containing the 194 payload that the job was dispatched with. The `payload` has a **maximum size 195 of 16 KiB**. 196 197 - `Priority` - Specifies the job priority which is used to prioritize 198 scheduling and access to resources. Must be between 1 and 100 inclusively, 199 and defaults to 50. 200 201 - `Region` - The region to run the job in, defaults to "global". 202 203 - `Type` - Specifies the job type and switches which scheduler 204 is used. Nomad provides the `service`, `system` and `batch` schedulers, 205 and defaults to `service`. To learn more about each scheduler type visit 206 [here](/docs/schedulers.html) 207 208 - `Update` - Specifies an update strategy to be applied to all task groups 209 within the job. When specified both at the job level and the task group level, 210 the update blocks are merged with the task group's taking precedence. For more 211 details on the update stanza, please see below. 212 213 - `Periodic` - `Periodic` allows the job to be scheduled at fixed times, dates 214 or intervals. The periodic expression is always evaluated in the UTC 215 timezone to ensure consistent evaluation when Nomad Servers span multiple 216 time zones. The `Periodic` object is optional and supports the following attributes: 217 218 - `Enabled` - `Enabled` determines whether the periodic job will spawn child 219 jobs. 220 221 - `TimeZone` - Specifies the time zone to evaluate the next launch interval 222 against. This is useful when wanting to account for day light savings in 223 various time zones. The time zone must be parsable by Golang's 224 [LoadLocation](https://golang.org/pkg/time/#LoadLocation). The default is 225 UTC. 226 227 - `SpecType` - `SpecType` determines how Nomad is going to interpret the 228 periodic expression. `cron` is the only supported `SpecType` currently. 229 230 - `Spec` - A cron expression configuring the interval the job is launched 231 at. Supports predefined expressions such as "@daily" and "@weekly" See 232 [here](https://github.com/gorhill/cronexpr#implementation) for full 233 documentation of supported cron specs and the predefined expressions. 234 235 - <a id="prohibit_overlap">`ProhibitOverlap`</a> - `ProhibitOverlap` can 236 be set to true to enforce that the periodic job doesn't spawn a new 237 instance of the job if any of the previous jobs are still running. It is 238 defaulted to false. 239 240 An example `periodic` block: 241 242 ```json 243 { 244 "Periodic": { 245 "Spec": "*/15 - *", 246 "TimeZone": "Europe/Berlin", 247 "SpecType": "cron", 248 "Enabled": true, 249 "ProhibitOverlap": true 250 } 251 } 252 ``` 253 254 - `ReschedulePolicy` - Specifies a reschedule policy to be applied to all task groups 255 within the job. When specified both at the job level and the task group level, 256 the reschedule blocks are merged, with the task group's taking precedence. For more 257 details on `ReschedulePolicy`, please see below. 258 259 ### Task Group 260 261 `TaskGroups` is a list of `TaskGroup` objects, each supports the following 262 attributes: 263 264 - `Constraints` - This is a list of `Constraint` objects. See the constraint 265 reference for more details. 266 267 - `Affinities` - This is a list of `Affinity` objects. See the affinity 268 reference for more details. 269 270 - `Spreads` - This is a list of `Spread` objects. See the spread 271 reference for more details. 272 273 - `Count` - Specifies the number of the task groups that should 274 be running. Must be non-negative, defaults to one. 275 276 - `Meta` - A key-value map that annotates the task group with opaque metadata. 277 278 - `Migrate` - Specifies a migration strategy to be applied during [node 279 drains][drain]. 280 281 - `HealthCheck` - One of `checks` or `task_states`. Indicates how task health 282 should be determined: either via Consul health checks or whether the task 283 was able to run successfully. 284 285 - `HealthyDeadline` - Specifies duration a task must become healthy within 286 before it is considered unhealthy. 287 288 - `MaxParallel` - Specifies how many allocations may be migrated at once. 289 290 - `MinHealthyTime` - Specifies duration a task must be considered healthy 291 before the migration is considered healthy. 292 293 - `Name` - The name of the task group. Must be specified. 294 295 - `RestartPolicy` - Specifies the restart policy to be applied to tasks in this group. 296 If omitted, a default policy for batch and non-batch jobs is used based on the 297 job type. See the [restart policy reference](#restart_policy) for more details. 298 299 - `ReschedulePolicy` - Specifies the reschedule policy to be applied to tasks in this group. 300 If omitted, a default policy is used for batch and service jobs. System jobs are not eligible 301 for rescheduling. See the [reschedule policy reference](#reschedule_policy) for more details. 302 303 - `EphemeralDisk` - Specifies the group's ephemeral disk requirements. See the 304 [ephemeral disk reference](#ephemeral_disk) for more details. 305 306 - `Update` - Specifies an update strategy to be applied to all task groups 307 within the job. When specified both at the job level and the task group level, 308 the update blocks are merged with the task group's taking precedence. For more 309 details on the update stanza, please see below. 310 311 - `Tasks` - A list of `Task` object that are part of the task group. 312 313 ### Task 314 315 The `Task` object supports the following keys: 316 317 - `Artifacts` - `Artifacts` is a list of `Artifact` objects which define 318 artifacts to be downloaded before the task is run. See the artifacts 319 reference for more details. 320 321 - `Config` - A map of key-value configuration passed into the driver 322 to start the task. The details of configurations are specific to 323 each driver. 324 325 - `Constraints` - This is a list of `Constraint` objects. See the constraint 326 reference for more details. 327 328 - `Affinities` - This is a list of `Affinity` objects. See the affinity 329 reference for more details. 330 331 - `Spreads` - This is a list of `Spread` objects. See the spread 332 reference for more details. 333 334 - `DispatchPayload` - Configures the task to have access to dispatch payloads. 335 The `DispatchPayload` object supports the following attributes: 336 337 - `File` - Specifies the file name to write the content of dispatch payload 338 to. The file is written relative to the task's local directory. 339 340 - `Driver` - Specifies the task driver that should be used to run the 341 task. See the [driver documentation](/docs/drivers/index.html) for what 342 is available. Examples include `docker`, `qemu`, `java`, and `exec`. 343 344 - `Env` - A map of key-value representing environment variables that 345 will be passed along to the running process. Nomad variables are 346 interpreted when set in the environment variable values. See the table of 347 interpreted variables [here](/docs/runtime/interpolation.html). 348 349 For example the below environment map will be reinterpreted: 350 351 ```json 352 { 353 "Env": { 354 "NODE_CLASS" : "${nomad.class}" 355 } 356 } 357 ``` 358 359 - `KillSignal` - Specifies a configurable kill signal for a task, where the 360 default is SIGINT. Note that this is only supported for drivers which accept 361 sending signals (currently `docker`, `exec`, `raw_exec`, and `java` drivers). 362 363 - `KillTimeout` - `KillTimeout` is a time duration in nanoseconds. It can be 364 used to configure the time between signaling a task it will be killed and 365 actually killing it. Drivers first sends a task the `SIGINT` signal and then 366 sends `SIGTERM` if the task doesn't die after the `KillTimeout` duration has 367 elapsed. The default `KillTimeout` is 5 seconds. 368 369 - `Leader` - Specifies whether the task is the leader task of the task group. If 370 set to true, when the leader task completes, all other tasks within the task 371 group will be gracefully shutdown. 372 373 - `LogConfig` - This allows configuring log rotation for the `stdout` and `stderr` 374 buffers of a Task. See the log rotation reference below for more details. 375 376 - `Meta` - Annotates the task group with opaque metadata. 377 378 - `Name` - The name of the task. This field is required. 379 380 - `Resources` - Provides the resource requirements of the task. 381 See the resources reference for more details. 382 383 - `Services` - `Services` is a list of `Service` objects. Nomad integrates with 384 Consul for service discovery. A `Service` object represents a routable and 385 discoverable service on the network. Nomad automatically registers when a task 386 is started and de-registers it when the task transitions to the dead state. 387 [Click here](/guides/integrations/consul-integration/index.html#service-discovery) to learn more about 388 services. Below is the fields in the `Service` object: 389 390 - `Name`: An explicit name for the Service. Nomad will replace `${JOB}`, 391 `${TASKGROUP}` and `${TASK}` by the name of the job, task group or task, 392 respectively. `${BASE}` expands to the equivalent of 393 `${JOB}-${TASKGROUP}-${TASK}`, and is the default name for a Service. 394 Each service defined for a given task must have a distinct name, so if 395 a task has multiple services only one of them can use the default name 396 and the others must be explicitly named. Names must adhere to 397 [RFC-1123 ยง2.1](https://tools.ietf.org/html/rfc1123#section-2) and are 398 limited to alphanumeric and hyphen characters (i.e. `[a-z0-9\-]`), and be 399 less than 64 characters in length. 400 401 - `Tags`: A list of string tags associated with this Service. String 402 interpolation is supported in tags. 403 404 - `CanaryTags`: A list of string tags associated with this Service while it 405 is a canary. Once the canary is promoted, the registered tags will be 406 updated to the set defined in the `Tags` field. String interpolation is 407 supported in tags. 408 409 - `PortLabel`: `PortLabel` is an optional string and is used to associate 410 a port with the service. If specified, the port label must match one 411 defined in the resources block. This could be a label of either a 412 dynamic or a static port. 413 414 - `AddressMode`: Specifies what address (host or driver-specific) this 415 service should advertise. This setting is supported in Docker since 416 Nomad 0.6 and rkt since Nomad 0.7. Valid options are: 417 418 - `auto` - Allows the driver to determine whether the host or driver 419 address should be used. Defaults to `host` and only implemented by 420 Docker. If you use a Docker network plugin such as weave, Docker will 421 automatically use its address. 422 423 - `driver` - Use the IP specified by the driver, and the port specified 424 in a port map. A numeric port may be specified since port maps aren't 425 required by all network plugins. Useful for advertising SDN and 426 overlay network addresses. Task will fail if driver network cannot be 427 determined. Only implemented for Docker and rkt. 428 429 - `host` - Use the host IP and port. 430 431 - `Checks`: `Checks` is an array of check objects. A check object defines a 432 health check associated with the service. Nomad supports the `script`, 433 `http` and `tcp` Consul Checks. Script checks are not supported for the 434 qemu driver since the Nomad client doesn't have access to the file system 435 of a task using the Qemu driver. 436 437 - `Type`: This indicates the check types supported by Nomad. Valid 438 options are currently `script`, `http` and `tcp`. 439 440 - `Name`: The name of the health check. 441 442 - `AddressMode`: Same as `AddressMode` on `Service`. Unlike services, 443 checks do not have an `auto` address mode as there's no way for 444 Nomad to know which is the best address to use for checks. Consul 445 needs access to the address for any HTTP or TCP checks. Added in 446 Nomad 0.7.1. Unlike `PortLabel`, this setting is *not* inherited 447 from the `Service`. 448 449 - `PortLabel`: Specifies the label of the port on which the check will 450 be performed. Note this is the _label_ of the port and not the port 451 number unless `AddressMode: "driver"`. The port label must match one 452 defined in the Network stanza. If a port value was declared on the 453 `Service`, this will inherit from that value if not supplied. If 454 supplied, this value takes precedence over the `Service.PortLabel` 455 value. This is useful for services which operate on multiple ports. 456 `http` and `tcp` checks require a port while `script` checks do not. 457 Checks will use the host IP and ports by default. In Nomad 0.7.1 or 458 later numeric ports may be used if `AddressMode: "driver"` is set on 459 the check. 460 461 - `Header`: Headers for HTTP checks. Should be an object where the 462 values are an array of values. Headers will be written once for each 463 value. 464 465 - `Interval`: This indicates the frequency of the health checks that 466 Consul will perform. 467 468 - `Timeout`: This indicates how long Consul will wait for a health 469 check query to succeed. 470 471 - `Method`: The HTTP method to use for HTTP checks. Defaults to GET. 472 473 - `Path`: The path of the HTTP endpoint which Consul will query to query 474 the health of a service if the type of the check is `http`. Nomad 475 will add the IP of the service and the port, users are only required 476 to add the relative URL of the health check endpoint. Absolute paths 477 are not allowed. 478 479 - `Protocol`: This indicates the protocol for the HTTP checks. Valid 480 options are `http` and `https`. We default it to `http`. 481 482 - `Command`: This is the command that the Nomad client runs for doing 483 script based health check. 484 485 - `Args`: Additional arguments to the `command` for script based health 486 checks. 487 488 - `TLSSkipVerify`: If true, Consul will not attempt to verify the 489 certificate when performing HTTPS checks. Requires Consul >= 0.7.2. 490 491 - `CheckRestart`: `CheckRestart` is an object which enables 492 restarting of tasks based upon Consul health checks. 493 494 - `Limit`: The number of unhealthy checks allowed before the 495 service is restarted. Defaults to `0` which disables 496 health-based restarts. 497 498 - `Grace`: The duration to wait after a task starts or restarts 499 before counting unhealthy checks count against the limit. 500 Defaults to "1s". 501 502 - `IgnoreWarnings`: Treat checks that are warning as passing. 503 Defaults to false which means warnings are considered unhealthy. 504 505 - `ShutdownDelay` - Specifies the duration to wait when killing a task between 506 removing it from Consul and sending it a shutdown signal. Ideally services 507 would fail healthchecks once they receive a shutdown signal. Alternatively 508 `ShutdownDelay` may be set to give in flight requests time to complete before 509 shutting down. 510 511 - `Templates` - Specifies the set of [`Template`](#template) objects to render for the task. 512 Templates can be used to inject both static and dynamic configuration with 513 data populated from environment variables, Consul and Vault. 514 515 - `User` - Set the user that will run the task. It defaults to the same user 516 the Nomad client is being run as. This can only be set on Linux platforms. 517 518 ### Resources 519 520 The `Resources` object supports the following keys: 521 522 - `CPU` - The CPU required in MHz. 523 524 - `MemoryMB` - The memory required in MB. 525 526 - `Networks` - A list of network objects. 527 528 - `Devices` - A list of device objects. 529 530 The Network object supports the following keys: 531 532 - `MBits` - The number of MBits in bandwidth required. 533 534 Nomad can allocate two types of ports to a task - Dynamic and Static/Reserved 535 ports. A network object allows the user to specify a list of `DynamicPorts` and 536 `ReservedPorts`. Each object supports the following attributes: 537 538 - `Value` - The port number for static ports. If the port is dynamic, then this 539 attribute is ignored. 540 - `Label` - The label to annotate a port so that it can be referred in the 541 service discovery block or environment variables. 542 543 The Device object supports the following keys: 544 545 - `Name` - Specifies the device required. The following inputs are valid: 546 547 * `<device_type>`: If a single value is given, it is assumed to be the device 548 type, such as "gpu", or "fpga". 549 550 * `<vendor>/<device_type>`: If two values are given separated by a `/`, the 551 given device type will be selected, constraining on the provided vendor. 552 Examples include "nvidia/gpu" or "amd/gpu". 553 554 * `<vendor>/<device_type>/<model>`: If three values are given separated by a `/`, the 555 given device type will be selected, constraining on the provided vendor, and 556 model name. Examples include "nvidia/gpu/1080ti" or "nvidia/gpu/2080ti". 557 558 559 - `Count` - The count of devices being requested per task. Defaults to 1. 560 561 - `Constraints` - A list to define constraints on which device can satisfy the 562 request. See the constraint reference for more details. 563 564 - `Affinities` - A list to define preferences for which device should be 565 chosen. See the affinity reference for more details. 566 567 <a id="ephemeral_disk"></a> 568 569 ### Ephemeral Disk 570 571 The `EphemeralDisk` object supports the following keys: 572 573 - `Migrate` - Specifies that the Nomad client should make a best-effort attempt 574 to migrate the data from a remote machine if placement cannot be made on the 575 original node. During data migration, the task will block starting until the 576 data migration has completed. Value is a boolean and the default is false. 577 578 - `SizeMB` - Specifies the size of the ephemeral disk in MB. Default is 300. 579 580 - `Sticky` - Specifies that Nomad should make a best-effort attempt to place the 581 updated allocation on the same machine. This will move the `local/` and 582 `alloc/data` directories to the new allocation. Value is a boolean and the 583 default is false. 584 585 <a id="reschedule_policy"></a> 586 587 ### Reschedule Policy 588 589 The `ReschedulePolicy` object supports the following keys: 590 591 - `Attempts` - `Attempts` is the number of reschedule attempts allowed 592 in an `Interval`. 593 594 - `Interval` - `Interval` is a time duration that is specified in nanoseconds. 595 The `Interval` is a sliding window within which at most `Attempts` number 596 of reschedule attempts are permitted. 597 598 - `Delay` - A duration to wait before attempting rescheduling. It is specified in 599 nanoseconds. 600 601 - `DelayFunction` - Specifies the function that is used to calculate subsequent reschedule delays. 602 The initial delay is specified by the `Delay` parameter. Allowed values for `DelayFunction` are listed below: 603 - `constant` - The delay between reschedule attempts stays at the `Delay` value. 604 - `exponential` - The delay between reschedule attempts doubles. 605 - `fibonacci` - The delay between reschedule attempts is calculated by adding the two most recent 606 delays applied. For example if `Delay` is set to 5 seconds, the next five reschedule attempts will be 607 delayed by 5 seconds, 5 seconds, 10 seconds, 15 seconds, and 25 seconds respectively. 608 609 - `MaxDelay` - `MaxDelay` is an upper bound on the delay beyond which it will not increase. This parameter is used when 610 `DelayFunction` is `exponential` or `fibonacci`, and is ignored when `constant` delay is used. 611 612 - `Unlimited` - `Unlimited` enables unlimited reschedule attempts. If this is set to true 613 the `Attempts` and `Interval` fields are not used. 614 615 616 <a id="restart_policy"></a> 617 618 ### Restart Policy 619 620 The `RestartPolicy` object supports the following keys: 621 622 - `Attempts` - `Attempts` is the number of restarts allowed in an `Interval`. 623 624 - `Interval` - `Interval` is a time duration that is specified in nanoseconds. 625 The `Interval` begins when the first task starts and ensures that only 626 `Attempts` number of restarts happens within it. If more than `Attempts` 627 number of failures happen, behavior is controlled by `Mode`. 628 629 - `Delay` - A duration to wait before restarting a task. It is specified in 630 nanoseconds. A random jitter of up to 25% is added to the delay. 631 632 - `Mode` - `Mode` is given as a string and controls the behavior when the task 633 fails more than `Attempts` times in an `Interval`. Possible values are listed 634 below: 635 636 - `delay` - `delay` will delay the next restart until the next `Interval` is 637 reached. 638 639 - `fail` - `fail` will not restart the task again. 640 641 ### Update 642 643 Specifies the task group update strategy. When omitted, rolling updates are 644 disabled. The update stanza can be specified at the job or task group level. 645 When specified at the job, the update stanza is inherited by all task groups. 646 When specified in both the job and in a task group, the stanzas are merged with 647 the task group's taking precedence. The `Update` object supports the following 648 attributes: 649 650 - `MaxParallel` - `MaxParallel` is given as an integer value and specifies 651 the number of tasks that can be updated at the same time. 652 653 - `HealthCheck` - Specifies the mechanism in which allocations health is 654 determined. The potential values are: 655 656 - "checks" - Specifies that the allocation should be considered healthy when 657 all of its tasks are running and their associated [checks][] are healthy, 658 and unhealthy if any of the tasks fail or not all checks become healthy. 659 This is a superset of "task_states" mode. 660 661 - "task_states" - Specifies that the allocation should be considered healthy 662 when all its tasks are running and unhealthy if tasks fail. 663 664 - "manual" - Specifies that Nomad should not automatically determine health 665 and that the operator will specify allocation health using the [HTTP 666 API](/api/deployments.html#set-allocation-health-in-deployment). 667 668 - `MinHealthyTime` - Specifies the minimum time the allocation must be in the 669 healthy state before it is marked as healthy and unblocks further allocations 670 from being updated. 671 672 - `HealthyDeadline` - Specifies the deadline in which the allocation must be 673 marked as healthy after which the allocation is automatically transitioned to 674 unhealthy. 675 676 - `ProgressDeadline` - Specifies the deadline in which an allocation must be 677 marked as healthy. The deadline begins when the first allocation for the 678 deployment is created and is reset whenever an allocation as part of the 679 deployment transitions to a healthy state. If no allocation transitions to the 680 healthy state before the progress deadline, the deployment is marked as 681 failed. If the `progress_deadline` is set to `0`, the first allocation to be 682 marked as unhealthy causes the deployment to fail. 683 684 - `AutoRevert` - Specifies if the job should auto-revert to the last stable job 685 on deployment failure. A job is marked as stable if all the allocations as 686 part of its deployment were marked healthy. 687 688 - `Canary` - Specifies that changes to the job that would result in destructive 689 updates should create the specified number of canaries without stopping any 690 previous allocations. Once the operator determines the canaries are healthy, 691 they can be promoted which unblocks a rolling update of the remaining 692 allocations at a rate of `max_parallel`. 693 694 - `AutoPromote` - Specifies if the job should automatically promote to 695 the new deployment if all canaries become healthy. 696 697 - `Stagger` - Specifies the delay between migrating allocations off nodes marked 698 for draining. 699 700 An example `Update` block: 701 702 ```json 703 { 704 "Update": { 705 "MaxParallel": 3, 706 "HealthCheck": "checks", 707 "MinHealthyTime": 15000000000, 708 "HealthyDeadline": 180000000000, 709 "AutoRevert": false, 710 "AutoPromote": false, 711 "Canary": 1 712 } 713 } 714 ``` 715 716 ### Constraint 717 718 The `Constraint` object supports the following keys: 719 720 - `LTarget` - Specifies the attribute to examine for the 721 constraint. See the table of attributes [here](/docs/runtime/interpolation.html#interpreted_node_vars). 722 723 - `RTarget` - Specifies the value to compare the attribute against. 724 This can be a literal value, another attribute or a regular expression if 725 the `Operator` is in "regexp" mode. 726 727 - `Operand` - Specifies the test to be performed on the two targets. It takes on the 728 following values: 729 730 - `regexp` - Allows the `RTarget` to be a regular expression to be matched. 731 732 - `set_contains` - Allows the `RTarget` to be a comma separated list of values 733 that should be contained in the LTarget's value. 734 735 - `distinct_hosts` - If set, the scheduler will not co-locate any task groups on the same 736 machine. This can be specified as a job constraint which applies the 737 constraint to all task groups in the job, or as a task group constraint which 738 scopes the effect to just that group. The constraint may not be 739 specified at the task level. 740 741 Placing the constraint at both the job level and at the task group level is 742 redundant since when placed at the job level, the constraint will be applied 743 to all task groups. When specified, `LTarget` and `RTarget` should be 744 omitted. 745 746 - `distinct_property` - If set, the scheduler selects nodes that have a 747 distinct value of the specified property. The `RTarget` specifies how 748 many allocations are allowed to share the value of a property. The 749 `RTarget` must be 1 or greater and if omitted, defaults to 1. This can 750 be specified as a job constraint which applies the constraint to all 751 task groups in the job, or as a task group constraint which scopes the 752 effect to just that group. The constraint may not be specified at the 753 task level. 754 755 Placing the constraint at both the job level and at the task group level is 756 redundant since when placed at the job level, the constraint will be applied 757 to all task groups. When specified, `LTarget` should be the property 758 that should be distinct and `RTarget` should be omitted. 759 760 - Comparison Operators - `=`, `==`, `is`, `!=`, `not`, `>`, `>=`, `<`, `<=`. The 761 ordering is compared lexically. 762 763 ### Affinity 764 765 Affinities allow operators to express placement preferences. More details on how they work 766 are described in [affinities](/docs/job-specification/affinity.html) 767 768 The `Affinity` object supports the following keys: 769 770 - `LTarget` - Specifies the attribute to examine for the 771 affinity. See the table of attributes [here](/docs/runtime/interpolation.html#interpreted_node_vars). 772 773 - `RTarget` - Specifies the value to compare the attribute against. 774 This can be a literal value, another attribute or a regular expression if 775 the `Operator` is in "regexp" mode. 776 777 - `Operand` - Specifies the test to be performed on the two targets. It takes on the 778 following values: 779 780 - `regexp` - Allows the `RTarget` to be a regular expression to be matched. 781 782 - `set_contains_all` - Allows the `RTarget` to be a comma separated list of values 783 that should be contained in the LTarget's value. 784 785 - `set_contains_any` - Allows the `RTarget` to be a comma separated list of values 786 any of which should be contained in the LTarget's value. 787 788 - Comparison Operators - `=`, `==`, `is`, `!=`, `not`, `>`, `>=`, `<`, `<=`. The 789 ordering is compared lexically. 790 791 - `Weight` - A non zero weight, valid values are from -100 to 100. Used to express 792 relative preference when there is more than one affinity. 793 794 ### Log Rotation 795 796 The `LogConfig` object configures the log rotation policy for a task's `stdout` and 797 `stderr`. The `LogConfig` object supports the following attributes: 798 799 - `MaxFiles` - The maximum number of rotated files Nomad will retain for 800 `stdout` and `stderr`, each tracked individually. 801 802 - `MaxFileSizeMB` - The size of each rotated file. The size is specified in 803 `MB`. 804 805 If the amount of disk resource requested for the task is less than the total 806 amount of disk space needed to retain the rotated set of files, Nomad will return 807 a validation error when a job is submitted. 808 809 ```json 810 { 811 "LogConfig": { 812 "MaxFiles": 3, 813 "MaxFileSizeMB": 10 814 } 815 } 816 ``` 817 818 In the above example we have asked Nomad to retain 3 rotated files for both 819 `stderr` and `stdout` and size of each file is 10 MB. The minimum disk space that 820 would be required for the task would be 60 MB. 821 822 ### Artifact 823 824 Nomad downloads artifacts using 825 [`go-getter`](https://github.com/hashicorp/go-getter). The `go-getter` library 826 allows downloading of artifacts from various sources using a URL as the input 827 source. The key-value pairs given in the `options` block map directly to 828 parameters appended to the supplied `source` URL. These are then used by 829 `go-getter` to appropriately download the artifact. `go-getter` also has a CLI 830 tool to validate its URL and can be used to check if the Nomad `artifact` is 831 valid. 832 833 Nomad allows downloading `http`, `https`, and `S3` artifacts. If these artifacts 834 are archives (zip, tar.gz, bz2, etc.), these will be unarchived before the task 835 is started. 836 837 The `Artifact` object supports the following keys: 838 839 - `GetterSource` - The path to the artifact to download. 840 841 - `RelativeDest` - An optional path to download the artifact into relative to the 842 root of the task's directory. If omitted, it will default to `local/`. 843 844 - `GetterOptions` - A `map[string]string` block of options for `go-getter`. 845 Full documentation of supported options are available 846 [here](https://github.com/hashicorp/go-getter/tree/ef5edd3d8f6f482b775199be2f3734fd20e04d4a#protocol-specific-options-1). 847 An example is given below: 848 849 ```json 850 { 851 "GetterOptions": { 852 "checksum": "md5:c4aa853ad2215426eb7d70a21922e794", 853 854 "aws_access_key_id": "<id>", 855 "aws_access_key_secret": "<secret>", 856 "aws_access_token": "<token>" 857 } 858 } 859 ``` 860 861 An example of downloading and unzipping an archive is as simple as: 862 863 ```json 864 { 865 "Artifacts": [ 866 { 867 "GetterSource": "https://example.com/my.zip", 868 "GetterOptions": { 869 "checksum": "md5:7f4b3e3b4dd5150d4e5aaaa5efada4c3" 870 } 871 } 872 ] 873 } 874 ``` 875 876 #### S3 examples 877 878 S3 has several different types of addressing and more detail can be found 879 [here](http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html#access-bucket-intro) 880 881 S3 region specific endpoints can be found 882 [here](http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region) 883 884 Path based style: 885 886 ```json 887 { 888 "Artifacts": [ 889 { 890 "GetterSource": "https://my-bucket-example.s3-us-west-2.amazonaws.com/my_app.tar.gz", 891 } 892 ] 893 } 894 ``` 895 896 or to override automatic detection in the URL, use the S3-specific syntax 897 898 ```json 899 { 900 "Artifacts": [ 901 { 902 "GetterSource": "s3::https://my-bucket-example.s3-eu-west-1.amazonaws.com/my_app.tar.gz", 903 } 904 ] 905 } 906 ``` 907 908 Virtual hosted based style 909 910 ```json 911 { 912 "Artifacts": [ 913 { 914 "GetterSource": "my-bucket-example.s3-eu-west-1.amazonaws.com/my_app.tar.gz", 915 } 916 ] 917 } 918 ``` 919 920 ### Template 921 922 The `Template` block instantiates an instance of a template renderer. This 923 creates a convenient way to ship configuration files that are populated from 924 environment variables, Consul data, Vault secrets, or just general 925 configurations within a Nomad task. 926 927 Nomad utilizes a tool called [Consul Template][ct]. Since Nomad v0.5.3, the 928 template can reference [Nomad's runtime environment variables][env]. For a full 929 list of the API template functions, please refer to the [Consul Template 930 README][ct]. 931 932 933 `Template` object supports following attributes: 934 935 - `ChangeMode` - Specifies the behavior Nomad should take if the rendered 936 template changes. The default value is `"restart"`. The possible values are: 937 938 - `"noop"` - take no action (continue running the task) 939 - `"restart"` - restart the task 940 - `"signal"` - send a configurable signal to the task 941 942 - `ChangeSignal` - Specifies the signal to send to the task as a string like 943 "SIGUSR1" or "SIGINT". This option is required if the `ChangeMode` is 944 `signal`. 945 946 - `DestPath` - Specifies the location where the resulting template should be 947 rendered, relative to the task directory. 948 949 - `EmbeddedTmpl` - Specifies the raw template to execute. One of `SourcePath` 950 or `EmbeddedTmpl` must be specified, but not both. This is useful for smaller 951 templates, but we recommend using `SourcePath` for larger templates. 952 953 - `Envvars` - Specifies the template should be read back as environment 954 variables for the task. 955 956 - `LeftDelim` - Specifies the left delimiter to use in the template. The default 957 is "{{" for some templates, it may be easier to use a different delimiter that 958 does not conflict with the output file itself. 959 960 - `Perms` - Specifies the rendered template's permissions. File permissions are 961 given as octal of the Unix file permissions `rwxrwxrwx`. 962 963 - `RightDelim` - Specifies the right delimiter to use in the template. The default 964 is "}}" for some templates, it may be easier to use a different delimiter that 965 does not conflict with the output file itself. 966 967 - `SourcePath` - Specifies the path to the template to be rendered. `SourcePath` 968 is mutually exclusive with `EmbeddedTmpl` attribute. The source can be fetched 969 using an [`Artifact`](#artifact) resource. The template must exist on the 970 machine prior to starting the task; it is not possible to reference a template 971 inside of a Docker container, for example. 972 973 - `Splay` - Specifies a random amount of time to wait between 0 ms and the given 974 splay value before invoking the change mode. Should be specified in 975 nanoseconds. 976 977 - `VaultGrace` - Specifies the grace period between lease renewal and secret 978 re-acquisition. When renewing a secret, if the remaining lease is less than or 979 equal to the configured grace, the template will request a new credential. 980 This prevents Vault from revoking the secret at its expiration and the task 981 having a stale secret. If the grace is set to a value that is higher than your 982 default TTL or max TTL, the template will always read a new secret. If the 983 task defines several templates, the `vault_grace` will be set to the lowest 984 value across all the templates. 985 986 ```json 987 { 988 "Templates": [ 989 { 990 "SourcePath": "local/config.conf.tpl", 991 "DestPath": "local/config.conf", 992 "EmbeddedTmpl": "", 993 "ChangeMode": "signal", 994 "ChangeSignal": "SIGUSR1", 995 "Splay": 5000000000 996 } 997 ] 998 } 999 ``` 1000 1001 ### Spread 1002 1003 Spread allow operators to target specific percentages of allocations based on 1004 any node attribute or metadata. More details on how they work are described 1005 in [spread](/docs/job-specification/spread.html). 1006 1007 The `Spread` object supports the following keys: 1008 1009 - `Attribute` - Specifies the attribute to examine for the 1010 spread. See the [table of attributes](/docs/runtime/interpolation.html#interpreted_node_vars) for examples. 1011 1012 - `SpreadTarget` - Specifies a list of attribute values and percentages. This is an optional field, when 1013 left empty Nomad will evenly spread allocations across values of the attribute. 1014 - `Value` - The value of a specific target attribute, like "dc1" for `${node.datacenter}`. 1015 - `Percent` - Desired percentage of allocations for this attribute value. The sum of 1016 all spread target percentages must add up to 100. 1017 1018 - `Weight` - A non zero weight, valid values are from -100 to 100. Used to express 1019 relative preference when there is more than one spread or affinity. 1020 1021 1022 [ct]: https://github.com/hashicorp/consul-template "Consul Template by HashiCorp" 1023 [drain]: /docs/commands/node/drain.html 1024 [env]: /docs/runtime/environment.html "Nomad Runtime Environment"