github.com/ncodes/nomad@v0.5.7-0.20170403112158-97adf4a74fb3/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_ADDR_<task>_<label>`</td> 77 <td>The allocated address, given as IP:Port for the given label of other tasks in the same group</td> 78 </tr> 79 <tr> 80 <td>`NOMAD_PORT_<task>_<label>`</td> 81 <td>The allocated port for the given label of other tasks in the same group</td> 82 </tr> 83 <tr> 84 <td>`NOMAD_IP_<task>_<label>`</td> 85 <td>The allocated IP address for the given label of other tasks in the same group</td> 86 </tr> 87 <tr> 88 <td>`NOMAD_HOST_PORT_<label>`</td> 89 <td>The host port for the given label if the port is port mapped</td> 90 </tr> 91 <tr> 92 <td>`NOMAD_META_<key>`</td> 93 <td>The metadata of the task</td> 94 </tr> 95 <tr> 96 <td>`VAULT_TOKEN`</td> 97 <td>The task's Vault token. See [Vault Integration](/docs/vault-integration/index.html) for more details</td> 98 </tr> 99 </table> 100 101 ~> Port labels and task names will have any non-alphanumeric or underscore 102 characters in their names replaced by underscores `_` when they're used in 103 environment variable names such as `NOMAD_ADDR_<task>_<label>`. 104 105 ## Task Identifiers 106 107 Nomad will pass both the allocation ID and name as well as the task and job's 108 names. These are given as `NOMAD_ALLOC_ID`, `NOMAD_ALLOC_NAME`, 109 `NOMAD_ALLOC_INDEX`, `NOMAD_JOB_NAME`, and `NOMAD_TASK_NAME`. The allocation ID 110 and index can be useful when the task being run needs a unique identifier or to 111 know its instance count. 112 113 ## Resources 114 115 When you request resources for a job, Nomad creates a resource offer. The final 116 resources for your job are not determined until it is scheduled. Nomad will 117 tell you which resources have been allocated after evaluation and placement. 118 119 ### CPU and Memory 120 121 Nomad will pass CPU and memory limits to your job as `NOMAD_CPU_LIMIT` and 122 `NOMAD_MEMORY_LIMIT`. Your task should use these values to adapt its behavior to 123 fit inside the resource allocation that nomad provides. For example, you can use 124 the memory limit to inform how large your in-process cache should be, or to 125 decide when to flush buffers to disk. 126 127 Both CPU and memory are presented as integers. The unit for CPU limit is 128 `1024 = 1GHz`. The unit for memory is `1 = 1 megabyte`. 129 130 Writing your applications to adjust to these values at runtime provides greater 131 scheduling flexibility since you can adjust the resource allocations in your 132 job specification without needing to change your code. You can also schedule workloads 133 that accept dynamic resource allocations so they can scale down/up as your 134 cluster gets more or less busy. 135 136 ### Networking 137 138 Nomad assigns IPs and ports to your jobs and exposes them via environment 139 variables. See the [Networking](/docs/job-specification/network.html) page for more 140 details. 141 142 ### Task Directories 143 144 Nomad makes the following directories available to tasks: 145 146 * `alloc/`: This directory is shared across all tasks in a task group and can be 147 used to store data that needs to be used by multiple tasks, such as a log 148 shipper. 149 * `local/`: This directory is private to each task. It can be used to store 150 arbitrary data that should not be shared by tasks in the task group. 151 * `secrets/`: This directory is private to each task, not accessible via the 152 `nomad fs` command or filesystem APIs and where possible backed by an 153 in-memory filesystem. It can be used to store secret data that should not be 154 visible outside the task. 155 156 These directories are persisted until the allocation is removed, which occurs 157 hours after all the tasks in the task group enter terminal states. This gives 158 time to view the data produced by tasks. 159 160 Depending on the driver and operating system being targeted, the directories are 161 made available in various ways. For example, on `docker` the directories are 162 bound to the container, while on `exec` on Linux the directories are mounted into the 163 chroot. Regardless of how the directories are made available, the path to the 164 directories can be read through the `NOMAD_ALLOC_DIR`, `NOMAD_TASK_DIR`, and 165 `NOMAD_SECRETS_DIR` environment variables. 166 167 ## Meta 168 169 The job specification also allows you to specify a `meta` block to supply arbitrary 170 configuration to a task. This allows you to easily provide job-specific 171 configuration even if you use the same executable unit in multiple jobs. These 172 key-value pairs are passed through to the job as `NOMAD_META_<key>=<value>` 173 environment variables. Prior to Nomad 0.5.5 the key was uppercased and since 174 then both the original case and an uppercased version are injected. The 175 uppercased version will be deprecated in a future release. 176 177 Currently there is no enforcement that the meta keys be lowercase, but using 178 multiple keys with the same uppercased representation will lead to undefined 179 behavior. 180 181 [jobspec]: /docs/job-specification/index.html "Nomad Job Specification" 182 [vault]: /docs/vault-integration/index.html "Nomad Vault Integration"