2015-09-23 21:58:25 +00:00
|
|
|
---
|
|
|
|
layout: "docs"
|
2016-10-28 00:36:26 +00:00
|
|
|
page_title: "Environment - Runtime"
|
|
|
|
sidebar_current: "docs-runtime-environment"
|
2015-09-23 21:58:25 +00:00
|
|
|
description: |-
|
|
|
|
Learn how to configure the Nomad runtime environment.
|
|
|
|
---
|
|
|
|
|
|
|
|
# Runtime Environment
|
|
|
|
|
2016-10-28 00:36:26 +00:00
|
|
|
Some settings you specify in your [job specification][jobspec] are passed
|
2016-10-09 07:01:59 +00:00
|
|
|
to tasks when they start. Other settings are dynamically allocated when your job
|
|
|
|
is scheduled. Both types of values are made available to your job through
|
2015-09-23 21:58:25 +00:00
|
|
|
environment variables.
|
|
|
|
|
2016-03-02 00:08:21 +00:00
|
|
|
## Summary
|
|
|
|
|
|
|
|
<table class="table table-bordered table-striped">
|
|
|
|
<tr>
|
|
|
|
<th>Variable</th>
|
|
|
|
<th>Description</th>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
2016-10-09 07:01:59 +00:00
|
|
|
<td>`NOMAD_ALLOC_DIR`</td>
|
2016-03-02 00:08:21 +00:00
|
|
|
<td>Path to the shared alloc directory</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
2016-10-09 07:01:59 +00:00
|
|
|
<td>`NOMAD_TASK_DIR`</td>
|
2016-03-02 00:08:21 +00:00
|
|
|
<td>Path to the local task directory</td>
|
|
|
|
</tr>
|
2016-11-01 17:36:59 +00:00
|
|
|
<tr>
|
|
|
|
<td>`NOMAD_SECRETS_DIR`</td>
|
|
|
|
<td>Path to the task's secrets directory</td>
|
|
|
|
</tr>
|
2016-03-02 00:08:21 +00:00
|
|
|
<tr>
|
2016-10-09 07:01:59 +00:00
|
|
|
<td>`NOMAD_MEMORY_LIMIT`</td>
|
2016-03-02 00:08:21 +00:00
|
|
|
<td>The task's memory limit in MB</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
2016-10-09 07:01:59 +00:00
|
|
|
<td>`NOMAD_CPU_LIMIT`</td>
|
2016-03-02 00:08:21 +00:00
|
|
|
<td>The task's CPU limit in MHz</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
2016-10-09 07:01:59 +00:00
|
|
|
<td>`NOMAD_ALLOC_ID`</td>
|
2016-03-02 00:08:21 +00:00
|
|
|
<td>The allocation ID of the task</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
2016-10-09 07:01:59 +00:00
|
|
|
<td>`NOMAD_ALLOC_NAME`</td>
|
2016-03-02 00:08:21 +00:00
|
|
|
<td>The allocation name of the task</td>
|
|
|
|
</tr>
|
2016-03-10 02:09:51 +00:00
|
|
|
<tr>
|
2016-10-09 07:01:59 +00:00
|
|
|
<td>`NOMAD_ALLOC_INDEX`</td>
|
2016-03-10 02:09:51 +00:00
|
|
|
<td>The allocation index; useful to distinguish instances of task groups</td>
|
|
|
|
</tr>
|
2016-03-02 00:08:21 +00:00
|
|
|
<tr>
|
2016-10-09 07:01:59 +00:00
|
|
|
<td>`NOMAD_TASK_NAME`</td>
|
2016-03-02 00:08:21 +00:00
|
|
|
<td>The task's name</td>
|
|
|
|
</tr>
|
2016-10-11 18:22:09 +00:00
|
|
|
<tr>
|
|
|
|
<td>`NOMAD_JOB_NAME`</td>
|
|
|
|
<td>The job's name</td>
|
|
|
|
</tr>
|
2016-03-02 00:08:21 +00:00
|
|
|
<tr>
|
2016-10-09 07:01:59 +00:00
|
|
|
<td>`NOMAD_IP_<label>`</td>
|
2016-10-11 19:31:40 +00:00
|
|
|
<td>The IP of the port with the given label</td>
|
2016-04-15 17:27:51 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2016-10-09 07:01:59 +00:00
|
|
|
<td>`NOMAD_PORT_<label>`</td>
|
2016-04-15 17:27:51 +00:00
|
|
|
<td>The port value with the given label</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
2016-10-09 07:01:59 +00:00
|
|
|
<td>`NOMAD_ADDR_<label>`</td>
|
2016-10-11 19:31:40 +00:00
|
|
|
<td>The IP:Port pair of the port with the given label</td>
|
2016-03-02 00:08:21 +00:00
|
|
|
</tr>
|
2017-03-07 04:04:41 +00:00
|
|
|
<tr>
|
2017-03-10 20:17:43 +00:00
|
|
|
<td>`NOMAD_ADDR_<task>_<label>`</td>
|
2017-03-07 04:04:41 +00:00
|
|
|
<td>The allocated address, given as IP:Port for the given label of other tasks in the same group</td>
|
|
|
|
</tr>
|
2017-03-10 20:17:43 +00:00
|
|
|
<tr>
|
|
|
|
<td>`NOMAD_PORT_<task>_<label>`</td>
|
|
|
|
<td>The allocated port for the given label of other tasks in the same group</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>`NOMAD_IP_<task>_<label>`</td>
|
|
|
|
<td>The allocated IP address for the given label of other tasks in the same group</td>
|
|
|
|
</tr>
|
2016-03-02 00:08:21 +00:00
|
|
|
<tr>
|
2016-10-09 07:01:59 +00:00
|
|
|
<td>`NOMAD_HOST_PORT_<label>`</td>
|
2016-03-02 00:08:21 +00:00
|
|
|
<td>The host port for the given label if the port is port mapped</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
2016-10-09 07:01:59 +00:00
|
|
|
<td>`NOMAD_META_<key>`</td>
|
2016-03-02 00:08:21 +00:00
|
|
|
<td>The metadata of the task</td>
|
|
|
|
</tr>
|
2016-11-01 17:36:59 +00:00
|
|
|
<tr>
|
|
|
|
<td>`VAULT_TOKEN`</td>
|
|
|
|
<td>The task's Vault token. See [Vault Integration](/docs/vault-integration/index.html) for more details</td>
|
|
|
|
</tr>
|
2016-03-02 00:08:21 +00:00
|
|
|
</table>
|
|
|
|
|
2017-03-10 01:12:10 +00:00
|
|
|
~> Port labels and task names will have any non-alphanumeric or underscore
|
|
|
|
characters in their names replaced by underscores `_` when they're used in
|
|
|
|
environment variable names such as `NOMAD_ADDR_<task>_<label>`.
|
2017-03-07 04:04:41 +00:00
|
|
|
|
2016-03-02 00:08:21 +00:00
|
|
|
## Task Identifiers
|
|
|
|
|
2016-10-11 18:22:09 +00:00
|
|
|
Nomad will pass both the allocation ID and name as well as the task and job's
|
|
|
|
names. These are given as `NOMAD_ALLOC_ID`, `NOMAD_ALLOC_NAME`,
|
|
|
|
`NOMAD_ALLOC_INDEX`, `NOMAD_JOB_NAME`, and `NOMAD_TASK_NAME`. The allocation ID
|
|
|
|
and index can be useful when the task being run needs a unique identifier or to
|
|
|
|
know its instance count.
|
2016-03-02 00:08:21 +00:00
|
|
|
|
2015-09-23 21:58:25 +00:00
|
|
|
## Resources
|
|
|
|
|
|
|
|
When you request resources for a job, Nomad creates a resource offer. The final
|
|
|
|
resources for your job are not determined until it is scheduled. Nomad will
|
2015-10-12 02:33:02 +00:00
|
|
|
tell you which resources have been allocated after evaluation and placement.
|
2015-09-23 21:58:25 +00:00
|
|
|
|
|
|
|
### CPU and Memory
|
|
|
|
|
2015-09-24 21:37:32 +00:00
|
|
|
Nomad will pass CPU and memory limits to your job as `NOMAD_CPU_LIMIT` and
|
2015-09-23 21:58:25 +00:00
|
|
|
`NOMAD_MEMORY_LIMIT`. Your task should use these values to adapt its behavior to
|
|
|
|
fit inside the resource allocation that nomad provides. For example, you can use
|
|
|
|
the memory limit to inform how large your in-process cache should be, or to
|
|
|
|
decide when to flush buffers to disk.
|
2015-09-23 22:19:31 +00:00
|
|
|
|
|
|
|
Both CPU and memory are presented as integers. The unit for CPU limit is
|
2016-10-11 19:52:50 +00:00
|
|
|
`1024 = 1GHz`. The unit for memory is `1 = 1 megabyte`.
|
2015-09-23 21:58:25 +00:00
|
|
|
|
|
|
|
Writing your applications to adjust to these values at runtime provides greater
|
|
|
|
scheduling flexibility since you can adjust the resource allocations in your
|
2015-09-26 00:09:35 +00:00
|
|
|
job specification without needing to change your code. You can also schedule workloads
|
2015-09-23 22:19:31 +00:00
|
|
|
that accept dynamic resource allocations so they can scale down/up as your
|
|
|
|
cluster gets more or less busy.
|
2015-09-23 21:58:25 +00:00
|
|
|
|
2015-11-18 23:51:39 +00:00
|
|
|
### Networking
|
2015-09-23 21:58:25 +00:00
|
|
|
|
2015-11-20 01:21:57 +00:00
|
|
|
Nomad assigns IPs and ports to your jobs and exposes them via environment
|
2016-10-28 00:36:26 +00:00
|
|
|
variables. See the [Networking](/docs/job-specification/network.html) page for more
|
2015-11-20 01:21:57 +00:00
|
|
|
details.
|
2015-09-23 21:58:25 +00:00
|
|
|
|
2016-10-28 00:36:26 +00:00
|
|
|
### Task Directories
|
2015-10-16 00:28:25 +00:00
|
|
|
|
2016-11-01 17:36:59 +00:00
|
|
|
Nomad makes the following directories available to tasks:
|
2015-10-16 00:28:25 +00:00
|
|
|
|
|
|
|
* `alloc/`: This directory is shared across all tasks in a task group and can be
|
|
|
|
used to store data that needs to be used by multiple tasks, such as a log
|
|
|
|
shipper.
|
|
|
|
* `local/`: This directory is private to each task. It can be used to store
|
2016-11-01 19:23:10 +00:00
|
|
|
arbitrary data that should not be shared by tasks in the task group.
|
2016-11-01 17:36:59 +00:00
|
|
|
* `secrets/`: This directory is private to each task, not accessible via the
|
|
|
|
`nomad fs` command or filesystem APIs and where possible backed by an
|
2016-11-01 19:23:10 +00:00
|
|
|
in-memory filesystem. It can be used to store secret data that should not be
|
2016-11-01 17:36:59 +00:00
|
|
|
visible outside the task.
|
2015-10-16 00:28:25 +00:00
|
|
|
|
2016-11-01 17:36:59 +00:00
|
|
|
These directories are persisted until the allocation is removed, which occurs
|
|
|
|
hours after all the tasks in the task group enter terminal states. This gives
|
|
|
|
time to view the data produced by tasks.
|
2015-10-16 00:28:25 +00:00
|
|
|
|
|
|
|
Depending on the driver and operating system being targeted, the directories are
|
|
|
|
made available in various ways. For example, on `docker` the directories are
|
2016-07-18 14:24:30 +00:00
|
|
|
bound to the container, while on `exec` on Linux the directories are mounted into the
|
2015-10-16 00:28:25 +00:00
|
|
|
chroot. Regardless of how the directories are made available, the path to the
|
2016-11-01 19:23:10 +00:00
|
|
|
directories can be read through the `NOMAD_ALLOC_DIR`, `NOMAD_TASK_DIR`, and
|
2016-11-01 17:36:59 +00:00
|
|
|
`NOMAD_SECRETS_DIR` environment variables.
|
2015-10-16 00:28:25 +00:00
|
|
|
|
2015-09-23 21:58:25 +00:00
|
|
|
## Meta
|
|
|
|
|
2015-09-26 00:09:35 +00:00
|
|
|
The job specification also allows you to specify a `meta` block to supply arbitrary
|
2015-09-23 21:58:25 +00:00
|
|
|
configuration to a task. This allows you to easily provide job-specific
|
|
|
|
configuration even if you use the same executable unit in multiple jobs. These
|
2016-10-11 19:52:50 +00:00
|
|
|
key-value pairs are passed through to the job as `NOMAD_META_<key>=<value>`
|
2017-02-21 03:51:24 +00:00
|
|
|
environment variables. Prior to Nomad 0.5.5 the key was uppercased and since
|
|
|
|
then both the original case and an uppercased version are injected. The
|
|
|
|
uppercased version will be deprecated in a future release.
|
2015-09-23 21:58:25 +00:00
|
|
|
|
2016-10-11 19:52:50 +00:00
|
|
|
Currently there is no enforcement that the meta keys be lowercase, but using
|
2015-09-23 21:58:25 +00:00
|
|
|
multiple keys with the same uppercased representation will lead to undefined
|
|
|
|
behavior.
|
2016-10-28 00:36:26 +00:00
|
|
|
|
2016-11-02 01:47:40 +00:00
|
|
|
[jobspec]: /docs/job-specification/index.html "Nomad Job Specification"
|
2016-11-01 17:36:59 +00:00
|
|
|
[vault]: /docs/vault-integration/index.html "Nomad Vault Integration"
|