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