2016-10-28 00:36:26 +00:00
|
|
|
---
|
2020-02-06 23:45:31 +00:00
|
|
|
layout: docs
|
|
|
|
page_title: job Stanza - Job Specification
|
|
|
|
sidebar_title: job
|
2016-10-28 00:36:26 +00:00
|
|
|
description: |-
|
|
|
|
The "job" stanza is the top-most configuration option in the job
|
|
|
|
specification. A job is a declarative specification of tasks that Nomad
|
|
|
|
should run.
|
|
|
|
---
|
|
|
|
|
|
|
|
# `job` Stanza
|
|
|
|
|
2020-02-06 23:45:31 +00:00
|
|
|
<Placement group={['job']} />
|
2016-11-01 12:53:13 +00:00
|
|
|
|
2016-10-28 00:36:26 +00:00
|
|
|
The `job` stanza is the top-most configuration option in the job specification.
|
2019-07-29 15:00:28 +00:00
|
|
|
A job is a declarative specification of tasks that Nomad should run. Jobs have
|
|
|
|
one or more task groups, which are themselves collections of one or more tasks.
|
|
|
|
Job names are unique per [region][region] or [namespace][namespace] (if Nomad
|
|
|
|
Enterprise is used).
|
2016-10-28 00:36:26 +00:00
|
|
|
|
|
|
|
```hcl
|
|
|
|
job "docs" {
|
|
|
|
constraint {
|
|
|
|
# ...
|
|
|
|
}
|
|
|
|
|
|
|
|
datacenters = ["us-east-1"]
|
|
|
|
|
|
|
|
group "example" {
|
|
|
|
# ...
|
|
|
|
}
|
|
|
|
|
|
|
|
meta {
|
|
|
|
"my-key" = "my-value"
|
|
|
|
}
|
|
|
|
|
2017-01-26 06:15:00 +00:00
|
|
|
parameterized {
|
|
|
|
# ...
|
|
|
|
}
|
|
|
|
|
2016-10-31 00:36:27 +00:00
|
|
|
periodic {
|
|
|
|
# ...
|
|
|
|
}
|
|
|
|
|
2016-10-28 00:36:26 +00:00
|
|
|
priority = 100
|
|
|
|
|
|
|
|
region = "north-america"
|
|
|
|
|
|
|
|
task "docs" {
|
|
|
|
# ...
|
|
|
|
}
|
|
|
|
|
|
|
|
update {
|
|
|
|
# ...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## `job` Parameters
|
|
|
|
|
2017-08-29 23:20:28 +00:00
|
|
|
- `all_at_once` `(bool: false)` - Controls whether the scheduler can make
|
|
|
|
partial placements if optimistic scheduling resulted in an oversubscribed
|
|
|
|
node. This does not control whether all allocations for the job, where all
|
|
|
|
would be the desired count for each task group, must be placed atomically.
|
|
|
|
This should only be used for special circumstances.
|
|
|
|
|
2016-10-28 00:36:26 +00:00
|
|
|
- `constraint` <code>([Constraint][constraint]: nil)</code> -
|
|
|
|
This can be provided multiple times to define additional constraints. See the
|
2019-12-19 20:32:23 +00:00
|
|
|
[Nomad constraint reference][constraint] for more
|
2016-10-28 00:36:26 +00:00
|
|
|
details.
|
|
|
|
|
2019-01-24 18:12:40 +00:00
|
|
|
- `affinity` <code>([Affinity][affinity]: nil)</code> -
|
2020-02-06 23:45:31 +00:00
|
|
|
This can be provided multiple times to define preferred placement criteria. See the
|
|
|
|
[Nomad affinity reference][affinity] for more
|
|
|
|
details.
|
2019-01-24 18:12:40 +00:00
|
|
|
|
2019-01-24 20:58:26 +00:00
|
|
|
- `spread` <code>([Spread][spread]: nil)</code> - This can be provided multiple times
|
|
|
|
to define criteria for spreading allocations across a node attribute or metadata.
|
2019-12-19 20:32:23 +00:00
|
|
|
See the [Nomad spread reference][spread] for more details.
|
2019-01-24 20:58:26 +00:00
|
|
|
|
2016-11-01 12:53:13 +00:00
|
|
|
- `datacenters` `(array<string>: <required>)` - A list of datacenters in the region which are eligible
|
2016-10-28 00:36:26 +00:00
|
|
|
for task placement. This must be provided, and does not have a default.
|
|
|
|
|
2017-01-26 06:15:00 +00:00
|
|
|
- `group` <code>([Group][group]: \<required\>)</code> - Specifies the start of a
|
2016-10-28 00:36:26 +00:00
|
|
|
group of tasks. This can be provided multiple times to define additional
|
|
|
|
groups. Group names must be unique within the job file.
|
|
|
|
|
|
|
|
- `meta` <code>([Meta][]: nil)</code> - Specifies a key-value map that annotates
|
|
|
|
with user-defined metadata.
|
|
|
|
|
2018-10-11 00:55:50 +00:00
|
|
|
- `migrate` <code>([Migrate][]: nil)</code> - Specifies the groups strategy for
|
|
|
|
migrating off of draining nodes. If omitted, a default migration strategy is
|
|
|
|
applied. Only service jobs with a count greater than 1 support migrate stanzas.
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
- `namespace` `(string: "default")` - The namespace in which to execute the job.
|
|
|
|
Values other than default are not allowed in non-Enterprise versions of Nomad.
|
|
|
|
|
2017-01-26 06:15:00 +00:00
|
|
|
- `parameterized` <code>([Parameterized][parameterized]: nil)</code> - Specifies
|
2017-07-17 18:41:50 +00:00
|
|
|
the job as a parameterized job such that it can be dispatched against.
|
2017-01-26 06:15:00 +00:00
|
|
|
|
2016-10-28 03:01:11 +00:00
|
|
|
- `periodic` <code>([Periodic][]: nil)</code> - Allows the job to be scheduled
|
|
|
|
at fixed times, dates or intervals.
|
|
|
|
|
2016-10-28 00:36:26 +00:00
|
|
|
- `priority` `(int: 50)` - Specifies the job priority which is used to
|
|
|
|
prioritize scheduling and access to resources. Must be between 1 and 100
|
|
|
|
inclusively, with a larger value corresponding to a higher priority.
|
|
|
|
|
|
|
|
- `region` `(string: "global")` - The region in which to execute the job.
|
|
|
|
|
2018-10-11 00:55:50 +00:00
|
|
|
- `reschedule` <code>([Reschedule][]: nil)</code> - Allows to specify a
|
|
|
|
rescheduling strategy. Nomad will then attempt to schedule the task on another
|
|
|
|
node if any of its allocation statuses become "failed".
|
|
|
|
|
2020-02-06 23:45:31 +00:00
|
|
|
- `type` `(string: "service")` - Specifies the [Nomad scheduler][scheduler] to
|
2016-10-28 00:36:26 +00:00
|
|
|
use. Nomad provides the `service`, `system` and `batch` schedulers.
|
|
|
|
|
|
|
|
- `update` <code>([Update][update]: nil)</code> - Specifies the task's update
|
|
|
|
strategy. When omitted, rolling updates are disabled.
|
|
|
|
|
2016-11-02 22:29:17 +00:00
|
|
|
- `vault` <code>([Vault][]: nil)</code> - Specifies the set of Vault policies
|
|
|
|
required by all tasks in this job.
|
2016-11-02 22:14:49 +00:00
|
|
|
|
2016-10-31 00:36:27 +00:00
|
|
|
- `vault_token` `(string: "")` - Specifies the Vault token that proves the
|
|
|
|
submitter of the job has access to the specified policies in the
|
|
|
|
[`vault`][vault] stanza. This field is only used to transfer the token and is
|
2016-10-31 20:43:25 +00:00
|
|
|
not stored after job submission.
|
|
|
|
|
2020-02-06 23:45:31 +00:00
|
|
|
!> It is **strongly discouraged** to place the token as a configuration
|
|
|
|
parameter like this, since the token could be checked into source control
|
|
|
|
accidentally. Users should set the `VAULT_TOKEN` environment variable when
|
|
|
|
running the job instead.
|
2016-10-31 00:36:27 +00:00
|
|
|
|
2019-11-18 21:05:06 +00:00
|
|
|
- `consul_token` `(string: "")` - Specifies the Consul token that proves the
|
|
|
|
submitter of the job has access to the Service Identity policies associated
|
|
|
|
with the job's Consul Connect enabled services. This field is only used to
|
|
|
|
transfer the token and is not stored after job submission.
|
|
|
|
|
2020-02-06 23:45:31 +00:00
|
|
|
!> It is **strongly discouraged** to place the token as a configuration
|
|
|
|
parameter like this, since the token could be checked into source control
|
|
|
|
accidentally. Users should set the `CONSUL_TOKEN` environment variable when
|
|
|
|
running the job instead.
|
2019-11-18 21:05:06 +00:00
|
|
|
|
2016-10-28 00:36:26 +00:00
|
|
|
## `job` Examples
|
|
|
|
|
2016-10-31 00:41:03 +00:00
|
|
|
The following examples only show the `job` stanzas. Remember that the
|
|
|
|
`job` stanza is only valid in the placements listed above.
|
|
|
|
|
2016-10-28 00:36:26 +00:00
|
|
|
### Docker Container
|
|
|
|
|
|
|
|
This example job starts a Docker container which runs as a service. Even though
|
|
|
|
the type is not specified as "service", that is the default job type.
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
job "docs" {
|
|
|
|
datacenters = ["default"]
|
|
|
|
|
|
|
|
group "example" {
|
|
|
|
task "server" {
|
|
|
|
driver = "docker"
|
|
|
|
config {
|
|
|
|
image = "hashicorp/http-echo"
|
|
|
|
args = ["-text", "hello"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resources {
|
|
|
|
memory = 128
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Batch Job
|
|
|
|
|
2017-08-25 00:12:43 +00:00
|
|
|
This example job executes the `uptime` command on 10 Nomad clients in the fleet,
|
2018-03-11 17:58:26 +00:00
|
|
|
restricting the eligible nodes to Linux machines.
|
2016-10-28 00:36:26 +00:00
|
|
|
|
|
|
|
```hcl
|
|
|
|
job "docs" {
|
|
|
|
datacenters = ["default"]
|
|
|
|
|
|
|
|
type = "batch"
|
|
|
|
|
|
|
|
constraint {
|
|
|
|
attribute = "${attr.kernel.name}"
|
|
|
|
value = "linux"
|
|
|
|
}
|
|
|
|
|
|
|
|
group "example" {
|
2017-08-25 00:12:43 +00:00
|
|
|
count = 10
|
2016-10-28 00:36:26 +00:00
|
|
|
task "uptime" {
|
|
|
|
driver = "exec"
|
|
|
|
config {
|
|
|
|
command = "uptime"
|
|
|
|
}
|
2016-10-31 00:36:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2016-10-31 20:43:53 +00:00
|
|
|
### Consuming Secrets
|
2016-10-31 00:36:27 +00:00
|
|
|
|
|
|
|
This example shows a job which retrieves secrets from Vault and writes those
|
|
|
|
secrets to a file on disk, which the application then consumes. Nomad handles
|
|
|
|
all interactions with Vault.
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
job "docs" {
|
|
|
|
datacenters = ["default"]
|
|
|
|
|
|
|
|
group "example" {
|
2016-10-31 20:44:54 +00:00
|
|
|
task "cat" {
|
2016-10-31 00:36:27 +00:00
|
|
|
driver = "exec"
|
|
|
|
|
|
|
|
config {
|
2016-10-31 14:43:29 +00:00
|
|
|
command = "cat"
|
|
|
|
args = ["local/secrets.txt"]
|
2016-10-31 00:36:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template {
|
|
|
|
data = "{{ secret \"secret/data\" }}"
|
|
|
|
destination = "local/secrets.txt"
|
|
|
|
}
|
|
|
|
|
|
|
|
vault {
|
|
|
|
policies = ["secret-readonly"]
|
|
|
|
}
|
2016-10-28 00:36:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2016-10-31 20:44:54 +00:00
|
|
|
When submitting this job, you would run:
|
|
|
|
|
2020-02-06 23:45:31 +00:00
|
|
|
```shell
|
2018-03-22 20:39:18 +00:00
|
|
|
$ VAULT_TOKEN="..." nomad job run example.nomad
|
2016-10-31 20:44:54 +00:00
|
|
|
```
|
|
|
|
|
2020-02-06 23:45:31 +00:00
|
|
|
[affinity]: /docs/job-specification/affinity 'Nomad affinity Job Specification'
|
|
|
|
[constraint]: /docs/job-specification/constraint 'Nomad constraint Job Specification'
|
|
|
|
[group]: /docs/job-specification/group 'Nomad group Job Specification'
|
|
|
|
[meta]: /docs/job-specification/meta 'Nomad meta Job Specification'
|
|
|
|
[migrate]: /docs/job-specification/migrate 'Nomad migrate Job Specification'
|
2019-12-19 20:32:23 +00:00
|
|
|
[namespace]: https://learn.hashicorp.com/nomad/governance-and-policy/namespaces
|
2020-02-06 23:45:31 +00:00
|
|
|
[parameterized]: /docs/job-specification/parameterized 'Nomad parameterized Job Specification'
|
|
|
|
[periodic]: /docs/job-specification/periodic 'Nomad periodic Job Specification'
|
|
|
|
[region]: /guides/operations/federation
|
|
|
|
[reschedule]: /docs/job-specification/reschedule 'Nomad reschedule Job Specification'
|
|
|
|
[scheduler]: /docs/schedulers 'Nomad Scheduler Types'
|
|
|
|
[spread]: /docs/job-specification/spread 'Nomad spread Job Specification'
|
|
|
|
[task]: /docs/job-specification/task 'Nomad task Job Specification'
|
|
|
|
[update]: /docs/job-specification/update 'Nomad update Job Specification'
|
|
|
|
[vault]: /docs/job-specification/vault 'Nomad vault Job Specification'
|