github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/website/pages/docs/runtime/environment.mdx (about) 1 --- 2 layout: docs 3 page_title: Environment - Runtime 4 sidebar_title: Runtime Environment 5 description: Learn how to configure the Nomad runtime environment. 6 --- 7 8 # Runtime Environment 9 10 Some settings you specify in your [job specification][jobspec] are passed 11 to tasks when they start. Other settings are dynamically allocated when your job 12 is scheduled. Both types of values are made available to your job through 13 environment variables. 14 15 ## Summary 16 17 @include 'envvars.mdx' 18 19 ~> Port labels and task names will have any non-alphanumeric or underscore 20 characters in their names replaced by underscores `_` when they're used in 21 environment variable names such as `NOMAD_ADDR_<task>_<label>`. 22 23 ## Task Identifiers 24 25 Nomad will pass both the allocation ID and name as well as the task, group and 26 job's names. These are given as `NOMAD_ALLOC_ID`, `NOMAD_ALLOC_NAME`, 27 `NOMAD_ALLOC_INDEX`, `NOMAD_JOB_NAME`, `NOMAD_GROUP_NAME` and `NOMAD_TASK_NAME`. 28 The allocation ID and index can be useful when the task being run needs a unique 29 identifier or to know its instance count. 30 31 ## Resources 32 33 When you request resources for a job, Nomad creates a resource offer. The final 34 resources for your job are not determined until it is scheduled. Nomad will 35 tell you which resources have been allocated after evaluation and placement. 36 37 ### CPU and Memory 38 39 Nomad will pass CPU and memory limits to your job as `NOMAD_CPU_LIMIT` and 40 `NOMAD_MEMORY_LIMIT`. Your task should use these values to adapt its behavior to 41 fit inside the resource allocation that nomad provides. For example, you can use 42 the memory limit to inform how large your in-process cache should be, or to 43 decide when to flush buffers to disk. 44 45 Both CPU and memory are presented as integers. The unit for CPU limit is 46 `1024 = 1GHz`. The unit for memory is `1 = 1 megabyte`. 47 48 Writing your applications to adjust to these values at runtime provides greater 49 scheduling flexibility since you can adjust the resource allocations in your 50 job specification without needing to change your code. You can also schedule workloads 51 that accept dynamic resource allocations so they can scale down/up as your 52 cluster gets more or less busy. 53 54 ### Networking 55 56 Nomad assigns IPs and ports to your jobs and exposes them via environment 57 variables. See the [Networking](/docs/job-specification/network) page for more 58 details. 59 60 ### Task Directories 61 62 Nomad makes the following directories available to tasks: 63 64 - `alloc/`: This directory is shared across all tasks in a task group and can be 65 used to store data that needs to be used by multiple tasks, such as a log 66 shipper. 67 - `local/`: This directory is private to each task. It can be used to store 68 arbitrary data that should not be shared by tasks in the task group. 69 - `secrets/`: This directory is private to each task, not accessible via the 70 `nomad alloc fs` command or filesystem APIs and where possible backed by an 71 in-memory filesystem. It can be used to store secret data that should not be 72 visible outside the task. 73 74 These directories are persisted until the allocation is removed, which occurs 75 hours after all the tasks in the task group enter terminal states. This gives 76 time to view the data produced by tasks. 77 78 Depending on the driver and operating system being targeted, the directories are 79 made available in various ways. For example, on `docker` the directories are 80 bound to the container, while on `exec` on Linux the directories are mounted into the 81 chroot. Regardless of how the directories are made available, the path to the 82 directories can be read through the `NOMAD_ALLOC_DIR`, `NOMAD_TASK_DIR`, and 83 `NOMAD_SECRETS_DIR` environment variables. 84 85 ## Meta 86 87 The job specification also allows you to specify a `meta` block to supply arbitrary 88 configuration to a task. This allows you to easily provide job-specific 89 configuration even if you use the same executable unit in multiple jobs. These 90 key-value pairs are passed through to the job as `NOMAD_META_<key>=<value>` 91 environment variables. Prior to Nomad 0.5.5 the key was uppercased and since 92 then both the original case and an uppercased version are injected. The 93 uppercased version will be deprecated in a future release. 94 95 Currently there is no enforcement that the meta keys be lowercase, but using 96 multiple keys with the same uppercased representation will lead to undefined 97 behavior. 98 99 [jobspec]: /docs/job-specification 'Nomad Job Specification' 100 [vault]: /docs/vault-integration 'Nomad Vault Integration'