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