github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/docs/commands/job/run.mdx (about)

     1  ---
     2  layout: docs
     3  page_title: 'Commands: job run'
     4  description: |
     5    The job run command is used to run a new job.
     6  ---
     7  
     8  # Command: job run
     9  
    10  **Alias: `nomad run`**
    11  
    12  The `job run` command is used to submit new jobs to Nomad or to update existing
    13  jobs. Job files must conform to the [job specification] format.
    14  
    15  ## Usage
    16  
    17  ```plaintext
    18  nomad job run [options] <job file>
    19  ```
    20  
    21  The `job run` command requires a single argument, specifying the path to a file
    22  containing a valid [job specification]. This file will be read and the job will
    23  be submitted to Nomad for scheduling. If the supplied path is "-", the job file
    24  is read from STDIN. Otherwise it is read from the file at the supplied path or
    25  downloaded and read from URL specified. Nomad downloads the job file using
    26  [`go-getter`] and supports `go-getter` syntax.
    27  
    28  By default, on successful job submission the run command will enter an
    29  interactive monitor and display log information detailing the scheduling
    30  decisions, placement information, and [deployment status] for the provided job
    31  if applicable ([`batch`] and [`system`] jobs don't create deployments). The monitor will
    32  exit after scheduling and deployment have finished or failed.
    33  
    34  On successful job submission and scheduling, exit code 0 will be returned. If
    35  there are job placement issues encountered (unsatisfiable constraints, resource
    36  exhaustion, etc), then the exit code will be 2. Any other errors, including
    37  deployment failures, client connection issues, or internal errors, are indicated
    38  by exit code 1.
    39  
    40  If the job has specified the region, the `-region` flag and `$NOMAD_REGION`
    41  environment variable are overridden and the job's region is used.
    42  
    43  The run command will set the `consul_token` of the job based on the following
    44  precedence, going from highest to lowest: the `-consul-token` flag, the
    45  `$CONSUL_HTTP_TOKEN` environment variable and finally the value in the job file.
    46  
    47  The run command will set the `vault_token` of the job based on the following
    48  precedence, going from highest to lowest: the `-vault-token` flag, the
    49  `$VAULT_TOKEN` environment variable and finally the value in the job file.
    50  
    51  When ACLs are enabled, this command requires a token with the `submit-job`
    52  capability for the job's namespace. Jobs that mount CSI volumes require a
    53  token with the `csi-mount-volume` capability for the volume's namespace. Jobs
    54  that mount host volumes require a token with the `host_volume` capability for
    55  that volume.
    56  
    57  ## General Options
    58  
    59  @include 'general_options.mdx'
    60  
    61  ## Run Options
    62  
    63  - `-check-index`: If set, the job is only registered or
    64    updated if the passed job modify index matches the server side version.
    65    If a check-index value of zero is passed, the job is only registered if it does
    66    not yet exist. If a non-zero value is passed, it ensures that the job is being
    67    updated from a known state. The use of this flag is most common in conjunction
    68    with [`job plan` command].
    69  
    70  - `-detach`: Return immediately instead of monitoring. A new evaluation ID
    71    will be output, which can be used to examine the evaluation using the
    72    [eval status] command.
    73  
    74  - `-eval-priority`: Override the priority of the evaluations produced as a result
    75    of this job submission. By default, this is set to the priority of the job.
    76  
    77  - `-json`: Parses the job file as JSON. If the outer object has a Job field,
    78    such as from "nomad job inspect" or "nomad run -output", the value of the
    79    field is used as the job. See [JSON Jobs] for details.
    80  
    81  - `-hcl1`: If set, HCL1 parser is used for parsing the job spec. Takes
    82    precedence over `-hcl2-strict`.
    83  
    84  - `-hcl2-strict`: Whether an error should be produced from the HCL2 parser where
    85    a variable has been supplied which is not defined within the root variables.
    86    Defaults to true, but ignored if `-hcl1` is defined.
    87  
    88  - `-output`: Output the JSON that would be submitted to the HTTP API without
    89    submitting the job.
    90  
    91  - `-policy-override`: Sets the flag to force override any soft mandatory
    92    Sentinel policies.
    93  
    94  - `-preserve-counts`: If set, the existing task group counts will be preserved
    95    when updating a job.
    96  
    97  - `-consul-token`: If set, the passed Consul token is stored in the job before
    98    sending to the Nomad servers. This allows passing the Consul token without
    99    storing it in the job file. This overrides the token found in the
   100    `$CONSUL_HTTP_TOKEN` environment variable and that found in the job.
   101  
   102  - `-consul-namespace`: <EnterpriseAlert inline/> If set, any services in the job will be registered into the
   103    specified Consul namespace. Any `template` stanza reading from Consul KV will
   104    scoped to the specified Consul namespace. If Consul ACLs are enabled and the
   105    [`consul` stanza `allow_unauthenticated`] is disabled in the Nomad server configuration, then
   106    a Consul token must be supplied with appropriate service and kv Consul ACL policy
   107    permissions.
   108  
   109  - `-vault-token`: Used to validate if the user submitting the job has
   110    permission to run the job according to its Vault policies. A Vault token must
   111    be supplied if the [`vault` stanza `allow_unauthenticated`] is disabled in
   112    the Nomad server configuration. If the `-vault-token` flag is set, the passed
   113    Vault token is added to the jobspec before sending to the Nomad servers. This
   114    allows passing the Vault token without storing it in the job file. This
   115    overrides the token found in the `$VAULT_TOKEN` environment variable and the
   116    [`vault_token`] field in the job file. This token is cleared from the job
   117    after validating and cannot be used within the job executing environment. Use
   118    the `vault` stanza when templating in a job with a Vault token.
   119  
   120  - `-vault-namespace`: If set, the passed Vault namespace is stored in the job
   121    before sending to the Nomad servers.
   122  
   123  - `-var=<key=value>`: Variable for template, can be used multiple times.
   124  
   125  - `-var-file=<path>`: Path to HCL2 file containing user variables.
   126  
   127  - `-verbose`: Show full information.
   128  
   129  ## Examples
   130  
   131  Schedule the job contained in the file `job1.nomad`, monitoring placement and deployment:
   132  
   133  ```shell-session
   134  $ nomad job run job1.nomad
   135  ==> 2021-06-09T15:22:58-07:00: Monitoring evaluation "52dee78a"
   136      2021-06-09T15:22:58-07:00: Evaluation triggered by job "example"
   137      2021-06-09T15:22:58-07:00: Allocation "5e0b39f0" created: node "3e84d3d2", group "group1"
   138  ==> 2021-06-09T15:22:59-07:00: Monitoring evaluation "52dee78a"
   139      2021-06-09T15:22:59-07:00: Evaluation within deployment: "62eb607c"
   140      2021-06-09T15:22:59-07:00: Allocation "5e0b39f0" status changed: "pending" -> "running"
   141      2021-06-09T15:22:59-07:00: Evaluation status changed: "pending" -> "complete"
   142  ==> 2021-06-09T15:22:59-07:00: Evaluation "52dee78a" finished with status "complete"
   143  ==> 2021-06-09T15:22:59-07:00: Monitoring deployment "62eb607c"
   144    ⠦ Deployment "62eb607c" in progress...
   145  
   146      2021-06-09T15:22:59-07:00
   147      ID          = 62eb607c
   148      Job ID      = example
   149      Job Version = 0
   150      Status      = running
   151      Description = Deployment is running
   152  
   153      Deployed
   154      Task Group  Desired  Placed  Healthy  Unhealthy  Progress Deadline
   155      cache       2        2       1        0          2021-06-09T15:32:58-07:00
   156      web         1        1       1        0          2021-06-09T15:32:58-07:00
   157  ```
   158  
   159  <a id="check-index"></a> Update the job using `check-index`:
   160  
   161  ```shell-session
   162  $ nomad job run -check-index 5 example.nomad
   163  Enforcing job modify index 5: job exists with conflicting job modify index: 6
   164  Job not updated
   165  
   166  $ nomad job run -check-index 6 example.nomad
   167  ==> 2021-06-09T16:57:29-07:00: Monitoring evaluation "5ef16dff"
   168      2021-06-09T16:57:29-07:00: Evaluation triggered by job "example"
   169      2021-06-09T16:57:29-07:00: Allocation "6ec7d16f" modified: node "6e1f9bf6", group "cache"
   170  ==> 2021-06-09T16:57:30-07:00: Monitoring evaluation "5ef16dff"
   171      2021-06-09T16:57:30-07:00: Evaluation within deployment: "62eb607c"
   172      2021-06-09T16:57:30-07:00: Evaluation status changed: "pending" -> "complete"
   173  ==> 2021-06-09T16:57:30-07:00: Evaluation "5ef16dff" finished with status "complete"
   174  ==> 2021-06-09T16:57:30-07:00: Monitoring deployment "62eb607c"
   175    ✓ Deployment "62eb607c" successful
   176  
   177      2021-06-09T16:57:30-07:00
   178      ID          = 62eb607c
   179      Job ID      = example
   180      Job Version = 2
   181      Status      = successful
   182      Description = Deployment completed successfully
   183  
   184      Deployed
   185      Task Group  Desired  Placed  Healthy  Unhealthy  Progress Deadline
   186      cache       1        1       1        0          2021-06-09T17:07:00-07:00
   187  ```
   188  
   189  Schedule the job contained in `job1.nomad` and return immediately:
   190  
   191  ```shell-session
   192  $ nomad job run -detach job1.nomad
   193  Job registration successful
   194  Evaluation ID: e18819c1-b83d-dc17-5e7b-b6f264990283
   195  ```
   196  
   197  Schedule a job which cannot be successfully placed. This results in a scheduling
   198  failure and the specifics of the placement are printed:
   199  
   200  ```shell-session
   201  $ nomad job run failing.nomad
   202  ==> 2021-06-09T16:49:00-07:00: Monitoring evaluation "2ae0e6a5"
   203      2021-06-09T16:49:00-07:00: Evaluation triggered by job "example"
   204  ==> 2021-06-09T16:49:01-07:00: Monitoring evaluation "2ae0e6a5"
   205      2021-06-09T16:49:01-07:00: Evaluation within deployment: "db0c5e57"
   206      2021-06-09T16:49:01-07:00: Evaluation status changed: "pending" -> "complete"
   207  ==> 2021-06-09T16:49:01-07:00: Evaluation "2ae0e6a5" finished with status "complete" but failed to place all allocations:
   208      2021-06-09T16:49:01-07:00: Task Group "cache" (failed to place 1 allocation):
   209        * Class "foo" filtered 1 nodes
   210        * Constraint "${attr.kernel.name} = linux" filtered 1 nodes
   211      2021-06-09T16:49:01-07:00: Evaluation "67493a64" waiting for additional capacity to place remainder
   212  ==> 2021-06-09T16:49:01-07:00: Monitoring deployment "db0c5e57"
   213    ⠧ Deployment "db0c5e57" in progress...
   214  
   215      2021-06-09T16:49:03-07:00
   216      ID          = db0c5e57
   217      Job ID      = example
   218      Job Version = 8
   219      Status      = running
   220      Description = Deployment is running
   221  
   222      Deployed
   223      Task Group  Desired  Placed  Healthy  Unhealthy  Progress Deadline
   224      cache       1        0       0        0          N/A
   225  ```
   226  
   227  Sample output when scheduling a system job, which doesn't create a deployment:
   228  
   229  ```shell-session
   230  $ nomad job run example.nomad
   231  ==> 2021-06-14T09:25:08-07:00: Monitoring evaluation "88a91284"
   232      2021-06-14T09:25:08-07:00: Evaluation triggered by job "example"
   233      2021-06-14T09:25:08-07:00: Allocation "03501797" created: node "7849439f", group "cache"
   234  ==> 2021-06-14T09:25:09-07:00: Monitoring evaluation "88a91284"
   235      2021-06-14T09:25:09-07:00: Evaluation status changed: "pending" -> "complete"
   236  ==> 2021-06-14T09:25:09-07:00: Evaluation "88a91284" finished with status "complete"
   237  ```
   238  
   239  [`batch`]: /docs/schedulers#batch
   240  [`consul` stanza `allow_unauthenticated`]: /docs/configuration/consul#allow_unauthenticated
   241  [deployment status]: /docs/commands/deployment#status
   242  [eval status]: /docs/commands/eval/status
   243  [`go-getter`]: https://github.com/hashicorp/go-getter
   244  [`job plan` command]: /docs/commands/job/plan
   245  [job specification]: /docs/job-specification
   246  [JSON jobs]: /api-docs/json-jobs
   247  [`system`]: /docs/schedulers#system
   248  [`vault` stanza `allow_unauthenticated`]: /docs/configuration/vault#allow_unauthenticated
   249  [`vault_token`]: /docs/job-specification/job#vault_token