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