github.com/maier/nomad@v0.4.1-0.20161110003312-a9e3d0b8549d/website/source/docs/job-specification/job.html.md (about)

     1  ---
     2  layout: "docs"
     3  page_title: "job Stanza - Job Specification"
     4  sidebar_current: "docs-job-specification-job"
     5  description: |-
     6    The "job" stanza is the top-most configuration option in the job
     7    specification. A job is a declarative specification of tasks that Nomad
     8    should run.
     9  ---
    10  
    11  # `job` Stanza
    12  
    13  <table class="table table-bordered table-striped">
    14    <tr>
    15      <th width="120">Placement</th>
    16      <td>
    17        <code>**job**</code>
    18      </td>
    19    </tr>
    20  </table>
    21  
    22  The `job` stanza is the top-most configuration option in the job specification.
    23  A job is a declarative specification of tasks that Nomad should run. Jobs have a
    24  globally unique name, one or many task groups, which are themselves collections
    25  of one or many tasks.
    26  
    27  ```hcl
    28  job "docs" {
    29    all_at_once = true
    30  
    31    constraint {
    32      # ...
    33    }
    34  
    35    datacenters = ["us-east-1"]
    36  
    37    group "example" {
    38      # ...
    39    }
    40  
    41    meta {
    42      "my-key" = "my-value"
    43    }
    44  
    45    periodic {
    46      # ...
    47    }
    48  
    49    priority = 100
    50  
    51    region = "north-america"
    52  
    53    task "docs" {
    54      # ...
    55    }
    56  
    57    update {
    58      # ...
    59    }
    60  }
    61  ```
    62  
    63  ## `job` Parameters
    64  
    65  - `all_at_once` `(bool: false)` - Controls if the entire set of tasks in the job
    66    must be placed atomically or if they can be scheduled incrementally. This
    67    should only be used for special circumstances.
    68  
    69  - `constraint` <code>([Constraint][constraint]: nil)</code> -
    70    This can be provided multiple times to define additional constraints. See the
    71    [Nomad constraint reference](/docs/job-specification/constraint.html) for more
    72    details.
    73  
    74  - `datacenters` `(array<string>: <required>)` - A list of datacenters in the region which are eligible
    75    for task placement. This must be provided, and does not have a default.
    76  
    77  - `group` <code>([Group][group]: <required>)</code> - Specifies the start of a
    78    group of tasks. This can be provided multiple times to define additional
    79    groups. Group names must be unique within the job file.
    80  
    81  - `meta` <code>([Meta][]: nil)</code> - Specifies a key-value map that annotates
    82    with user-defined metadata.
    83  
    84  - `periodic` <code>([Periodic][]: nil)</code> - Allows the job to be scheduled
    85    at fixed times, dates or intervals.
    86  
    87  - `priority` `(int: 50)` - Specifies the job priority which is used to
    88    prioritize scheduling and access to resources. Must be between 1 and 100
    89    inclusively, with a larger value corresponding to a higher priority.
    90  
    91  - `region` `(string: "global")` - The region in which to execute the job.
    92  
    93  - `type` `(string: "service")` - Specifies the  [Nomad scheduler][scheduler] to
    94    use. Nomad provides the `service`, `system` and `batch` schedulers.
    95  
    96  - `update` <code>([Update][update]: nil)</code> - Specifies the task's update
    97    strategy. When omitted, rolling updates are disabled.
    98  
    99  - `vault` <code>([Vault][]: nil)</code> - Specifies the set of Vault policies
   100    required by all tasks in this job.
   101  
   102  - `vault_token` `(string: "")` - Specifies the Vault token that proves the
   103    submitter of the job has access to the specified policies in the
   104    [`vault`][vault] stanza. This field is only used to transfer the token and is
   105    not stored after job submission.
   106  
   107      !> It is **strongly discouraged** to place the token as a configuration
   108      parameter like this, since the token could be checked into source control
   109      accidentally. Users should set the `VAULT_TOKEN` environment variable when
   110      running the job instead.
   111  
   112  ## `job` Examples
   113  
   114  The following examples only show the `job` stanzas. Remember that the
   115  `job` stanza is only valid in the placements listed above.
   116  
   117  ### Docker Container
   118  
   119  This example job starts a Docker container which runs as a service. Even though
   120  the type is not specified as "service", that is the default job type.
   121  
   122  ```hcl
   123  job "docs" {
   124    datacenters = ["default"]
   125  
   126    group "example" {
   127      task "server" {
   128        driver = "docker"
   129        config {
   130          image = "hashicorp/http-echo"
   131          args  = ["-text", "hello"]
   132        }
   133  
   134        resources {
   135          memory = 128
   136        }
   137      }
   138    }
   139  }
   140  ```
   141  
   142  ### Batch Job
   143  
   144  This example job executes the `uptime` command across all Nomad clients in the
   145  fleet, as long as those machines are running Linux.
   146  
   147  ```hcl
   148  job "docs" {
   149    datacenters = ["default"]
   150  
   151    type = "batch"
   152  
   153    constraint {
   154      attribute = "${attr.kernel.name}"
   155      value     = "linux"
   156    }
   157  
   158    group "example" {
   159      task "uptime" {
   160        driver = "exec"
   161        config {
   162          command = "uptime"
   163        }
   164  
   165        resources {
   166          cpu = 20
   167        }
   168      }
   169    }
   170  }
   171  ```
   172  
   173  ### Consuming Secrets
   174  
   175  This example shows a job which retrieves secrets from Vault and writes those
   176  secrets to a file on disk, which the application then consumes. Nomad handles
   177  all interactions with Vault.
   178  
   179  ```hcl
   180  job "docs" {
   181    datacenters = ["default"]
   182  
   183    group "example" {
   184      task "cat" {
   185        driver = "exec"
   186  
   187        config {
   188          command = "cat"
   189          args    = ["local/secrets.txt"]
   190        }
   191  
   192        template {
   193          data        = "{{ secret \"secret/data\" }}"
   194          destination = "local/secrets.txt"
   195        }
   196  
   197        vault {
   198          policies = ["secret-readonly"]
   199        }
   200  
   201        resources {
   202          cpu = 20
   203        }
   204      }
   205    }
   206  }
   207  ```
   208  
   209  When submitting this job, you would run:
   210  
   211  ```
   212  $ VAULT_TOKEN="..." nomad run example.nomad
   213  ```
   214  
   215  [constraint]: /docs/job-specification/constraint.html "Nomad constraint Job Specification"
   216  [group]: /docs/job-specification/group.html "Nomad group Job Specification"
   217  [meta]: /docs/job-specification/meta.html "Nomad meta Job Specification"
   218  [periodic]: /docs/job-specification/periodic.html "Nomad periodic Job Specification"
   219  [task]: /docs/job-specification/task.html "Nomad task Job Specification"
   220  [update]: /docs/job-specification/update.html "Nomad update Job Specification"
   221  [vault]: /docs/job-specification/vault.html "Nomad vault Job Specification"
   222  [meta]: /docs/job-specification/meta.html "Nomad meta Job Specification"
   223  [scheduler]: /docs/runtime/schedulers.html "Nomad Scheduler Types"