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

     1  ---
     2  layout: "docs"
     3  page_title: "Environment - Runtime"
     4  sidebar_current: "docs-runtime-environment"
     5  description: |-
     6    Learn how to configure the Nomad runtime environment.
     7  ---
     8  
     9  # Runtime Environment
    10  
    11  Some settings you specify in your [job specification][jobspec] are passed
    12  to tasks when they start. Other settings are dynamically allocated when your job
    13  is scheduled. Both types of values are made available to your job through
    14  environment variables.
    15  
    16  ## Summary
    17  
    18  <table class="table table-bordered table-striped">
    19    <tr>
    20      <th>Variable</th>
    21      <th>Description</th>
    22    </tr>
    23    <tr>
    24      <td>`NOMAD_ALLOC_DIR`</td>
    25      <td>Path to the shared alloc directory</td>
    26    </tr>
    27    <tr>
    28      <td>`NOMAD_TASK_DIR`</td>
    29      <td>Path to the local task directory</td>
    30    </tr>
    31    <tr>
    32      <td>`NOMAD_SECRETS_DIR`</td>
    33      <td>Path to the task's secrets directory</td>
    34    </tr>
    35    <tr>
    36      <td>`NOMAD_MEMORY_LIMIT`</td>
    37      <td>The task's memory limit in MB</td>
    38    </tr>
    39    <tr>
    40      <td>`NOMAD_CPU_LIMIT`</td>
    41      <td>The task's CPU limit in MHz</td>
    42    </tr>
    43    <tr>
    44      <td>`NOMAD_ALLOC_ID`</td>
    45      <td>The allocation ID of the task</td>
    46    </tr>
    47    <tr>
    48      <td>`NOMAD_ALLOC_NAME`</td>
    49      <td>The allocation name of the task</td>
    50    </tr>
    51    <tr>
    52      <td>`NOMAD_ALLOC_INDEX`</td>
    53      <td>The allocation index; useful to distinguish instances of task groups</td>
    54    </tr>
    55    <tr>
    56      <td>`NOMAD_TASK_NAME`</td>
    57      <td>The task's name</td>
    58    </tr>
    59    <tr>
    60      <td>`NOMAD_JOB_NAME`</td>
    61      <td>The job's name</td>
    62    </tr>
    63    <tr>
    64      <td>`NOMAD_IP_<label>`</td>
    65      <td>The IP of the port with the given label</td>
    66    </tr>
    67    <tr>
    68      <td>`NOMAD_PORT_<label>`</td>
    69      <td>The port value with the given label</td>
    70    </tr>
    71    <tr>
    72      <td>`NOMAD_ADDR_<label>`</td>
    73      <td>The IP:Port pair of the port with the given label</td>
    74    </tr>
    75    <tr>
    76      <td>`NOMAD_HOST_PORT_<label>`</td>
    77      <td>The host port for the given label if the port is port mapped</td>
    78    </tr>
    79    <tr>
    80      <td>`NOMAD_META_<key>`</td>
    81      <td>The metadata of the task</td>
    82    </tr>
    83    <tr>
    84      <td>`VAULT_TOKEN`</td>
    85      <td>The task's Vault token. See [Vault Integration](/docs/vault-integration/index.html) for more details</td>
    86    </tr>
    87  </table>
    88  
    89  ## Task Identifiers
    90  
    91  Nomad will pass both the allocation ID and name as well as the task and job's
    92  names.  These are given as `NOMAD_ALLOC_ID`, `NOMAD_ALLOC_NAME`,
    93  `NOMAD_ALLOC_INDEX`, `NOMAD_JOB_NAME`, and `NOMAD_TASK_NAME`. The allocation ID
    94  and index can be useful when the task being run needs a unique identifier or to
    95  know its instance count.
    96  
    97  ## Resources
    98  
    99  When you request resources for a job, Nomad creates a resource offer. The final
   100  resources for your job are not determined until it is scheduled. Nomad will
   101  tell you which resources have been allocated after evaluation and placement.
   102  
   103  ### CPU and Memory
   104  
   105  Nomad will pass CPU and memory limits to your job as `NOMAD_CPU_LIMIT` and
   106  `NOMAD_MEMORY_LIMIT`. Your task should use these values to adapt its behavior to
   107  fit inside the resource allocation that nomad provides. For example, you can use
   108  the memory limit to inform how large your in-process cache should be, or to
   109  decide when to flush buffers to disk.
   110  
   111  Both CPU and memory are presented as integers. The unit for CPU limit is
   112  `1024 = 1GHz`. The unit for memory is `1 = 1 megabyte`.
   113  
   114  Writing your applications to adjust to these values at runtime provides greater
   115  scheduling flexibility since you can adjust the resource allocations in your
   116  job specification without needing to change your code. You can also schedule workloads
   117  that accept dynamic resource allocations so they can scale down/up as your
   118  cluster gets more or less busy.
   119  
   120  ### Networking
   121  
   122  Nomad assigns IPs and ports to your jobs and exposes them via environment
   123  variables. See the [Networking](/docs/job-specification/network.html) page for more
   124  details.
   125  
   126  ### Task Directories
   127  
   128  Nomad makes the following directories available to tasks:
   129  
   130  * `alloc/`: This directory is shared across all tasks in a task group and can be
   131    used to store data that needs to be used by multiple tasks, such as a log
   132    shipper.
   133  * `local/`: This directory is private to each task. It can be used to store
   134    arbitrary data that should not be shared by tasks in the task group.
   135  * `secrets/`: This directory is private to each task, not accessible via the
   136    `nomad fs` command or filesystem APIs and where possible backed by an
   137    in-memory filesystem. It can be used to store secret data that should not be
   138    visible outside the task.
   139  
   140  These directories are persisted until the allocation is removed, which occurs
   141  hours after all the tasks in the task group enter terminal states. This gives
   142  time to view the data produced by tasks.
   143  
   144  Depending on the driver and operating system being targeted, the directories are
   145  made available in various ways. For example, on `docker` the directories are
   146  bound to the container, while on `exec` on Linux the directories are mounted into the
   147  chroot. Regardless of how the directories are made available, the path to the
   148  directories can be read through the `NOMAD_ALLOC_DIR`, `NOMAD_TASK_DIR`, and
   149  `NOMAD_SECRETS_DIR` environment variables.
   150  
   151  ## Meta
   152  
   153  The job specification also allows you to specify a `meta` block to supply arbitrary
   154  configuration to a task. This allows you to easily provide job-specific
   155  configuration even if you use the same executable unit in multiple jobs. These
   156  key-value pairs are passed through to the job as `NOMAD_META_<key>=<value>`
   157  environment variables, where `key` is UPPERCASED from the job specification.
   158  
   159  Currently there is no enforcement that the meta keys be lowercase, but using
   160  multiple keys with the same uppercased representation will lead to undefined
   161  behavior.
   162  
   163  [jobspec]: /docs/job-specification/index.html "Nomad Job Specification"
   164  [vault]: /docs/vault-integration/index.html "Nomad Vault Integration"