github.com/adityamillind98/nomad@v0.11.8/website/pages/api-docs/json-jobs.mdx (about)

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