diff --git a/client/driver/env/env.go b/client/driver/env/env.go index 1846403ac..d301c924c 100644 --- a/client/driver/env/env.go +++ b/client/driver/env/env.go @@ -25,9 +25,6 @@ const ( // The tasks limit in MHz. CpuLimit = "NOMAD_CPU_LIMIT" - // The IP address for the task. - TaskIP = "NOMAD_IP" - // Prefix for passing both dynamic and static port allocations to // tasks. // E.g. $NOMAD_IP_1=127.0.0.1:1 or $NOMAD_IP_http=127.0.0.1:80 diff --git a/website/source/docs/drivers/docker.html.md b/website/source/docs/drivers/docker.html.md index 140522b15..9b59302e8 100644 --- a/website/source/docs/drivers/docker.html.md +++ b/website/source/docs/drivers/docker.html.md @@ -40,11 +40,11 @@ The following options are available for use in the job specification. * `args` - (Optional) A list of arguments to the optional `command`. If no `command` is present, `args` are ignored. References to environment variables or any [intepretable Nomad - variables](/docs/jobspec/index.html#interpreted_vars) will be interpreted + variables](/docs/jobspec/interpreted.html) will be interpreted before launching the task. For example: ``` - args = ["${nomad.ip}", "${MY_ENV}", "${meta.foo}"] + args = ["${nomad.datacenter}", "${MY_ENV}", "${meta.foo}"] ``` * `labels` - (Optional) A key/value map of labels to set to the containers on diff --git a/website/source/docs/drivers/exec.html.md b/website/source/docs/drivers/exec.html.md index fd64569bf..790bb7740 100644 --- a/website/source/docs/drivers/exec.html.md +++ b/website/source/docs/drivers/exec.html.md @@ -34,11 +34,11 @@ The `exec` driver supports the following configuration in the job spec: * `args` - (Optional) A list of arguments to the optional `command`. References to environment variables or any [intepretable Nomad - variables](/docs/jobspec/index.html#interpreted_vars) will be interpreted + variables](/docs/jobspec/interpreted.html) will be interpreted before launching the task. For example: ``` - args = ["${nomad.ip}", "${MY_ENV}", "${meta.foo}"] + args = ["${nomad.datacenter}", "${MY_ENV}", "${meta.foo}"] ``` ## Client Requirements diff --git a/website/source/docs/drivers/java.html.md b/website/source/docs/drivers/java.html.md index 6f1473e3c..2692fac46 100644 --- a/website/source/docs/drivers/java.html.md +++ b/website/source/docs/drivers/java.html.md @@ -29,11 +29,11 @@ The `java` driver supports the following configuration in the job spec: * `args` - (Optional) A list of arguments to the optional `command`. References to environment variables or any [intepretable Nomad - variables](/docs/jobspec/index.html#interpreted_vars) will be interpreted + variables](/docs/jobspec/interpreted.html) will be interpreted before launching the task. For example: ``` - args = ["${nomad.ip}", "${MY_ENV}", "${meta.foo}"] + args = ["${nomad.datacenter}", "${MY_ENV}", "${meta.foo}"] ``` * `jvm_options` - (Optional) A list of JVM options to be passed while invoking diff --git a/website/source/docs/drivers/raw_exec.html.md b/website/source/docs/drivers/raw_exec.html.md index 520ea70ee..375a28d38 100644 --- a/website/source/docs/drivers/raw_exec.html.md +++ b/website/source/docs/drivers/raw_exec.html.md @@ -32,11 +32,11 @@ The `raw_exec` driver supports the following configuration in the job spec: * `args` - (Optional) A list of arguments to the optional `command`. References to environment variables or any [intepretable Nomad - variables](/docs/jobspec/index.html#interpreted_vars) will be interpreted + variables](/docs/jobspec/interpreted.html) will be interpreted before launching the task. For example: ``` - args = ["${nomad.ip}", "${MY_ENV}", "${meta.foo}"] + args = ["${nomad.datacenter}", "${MY_ENV}", "${meta.foo}"] ``` ## Client Requirements diff --git a/website/source/docs/drivers/rkt.html.md b/website/source/docs/drivers/rkt.html.md index 6ed0cd8b5..c43db15c1 100644 --- a/website/source/docs/drivers/rkt.html.md +++ b/website/source/docs/drivers/rkt.html.md @@ -26,11 +26,11 @@ The `rkt` driver supports the following configuration in the job spec: * `args` - (Optional) A list of arguments to the optional `command`. References to environment variables or any [intepretable Nomad - variables](/docs/jobspec/index.html#interpreted_vars) will be interpreted + variables](/docs/jobspec/interpreted.html) will be interpreted before launching the task. For example: ``` - args = ["${nomad.ip}", "${MY_ENV}", ${meta.foo}"] + args = ["${nomad.datacenter}", "${MY_ENV}", ${meta.foo}"] ``` * `trust_prefix` - (Optional) The trust prefix to be passed to rkt. Must be diff --git a/website/source/docs/jobspec/index.html.md b/website/source/docs/jobspec/index.html.md index 0f66462ca..b53f21b2c 100644 --- a/website/source/docs/jobspec/index.html.md +++ b/website/source/docs/jobspec/index.html.md @@ -244,7 +244,7 @@ The `task` object supports the following keys: * `env` - A map of key/value representing environment variables that will be passed along to the running process. Nomad variables are interpreted when set in the environment variable values. See the table of - interpreted variables [here](#interpreted_vars). + interpreted variables [here](/docs/jobspec/interpreted.html). For example the below environment map will be reinterpreted: @@ -344,7 +344,7 @@ restart { The `constraint` object supports the following keys: * `attribute` - Specifies the attribute to examine for the - constraint. See the table of attributes [below](#interpreted_vars). + constraint. See the table of attributes [here](/docs/jobspec/interpreted.html#interpreted_node_vars). * `operator` - Specifies the comparison operator. Defaults to equality, and can be `=`, `==`, `is`, `!=`, `not`, `>`, `>=`, `<`, `<=`. The @@ -376,96 +376,6 @@ The `constraint` object supports the following keys: Tasks within a task group are always co-scheduled. -### Interpreted Variables - -Certain Nomad variables are interpretable for use in constraints, task -environment variables and task arguments. Below is a table documenting the -variables that can be interpreted: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
VariableDescription
${node.id}The client node identifier
${node.datacenter}The client node datacenter
${node.name}The client node name
${node.class}The client node class
${attr.\The attribute given by `key` on the client node.
${meta.\}The metadata value given by `key` on the client node.
- -Below is a table documenting common node attributes: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AttributeDescription
archCPU architecture of the client. Examples: `amd64`, `386`
consul.datacenterThe Consul datacenter of the client node if Consul found
cpu.numcoresNumber of CPU cores on the client
driver.\See the [task drivers](/docs/drivers/index.html) for attribute documentation
hostnameHostname of the client
kernel.nameKernel of the client. Examples: `linux`, `darwin`
kernel.versionVersion of the client kernel. Examples: `3.19.0-25-generic`, `15.0.0`
platform.aws.ami-idOn EC2, the AMI ID of the client node
platform.aws.instance-typeOn EC2, the instance type of the client node
os.nameOperating system of the client. Examples: `ubuntu`, `windows`, `darwin`
os.versionVersion of the client OS
- ## JSON Syntax Job files can also be specified in JSON. The conversion is straightforward diff --git a/website/source/docs/jobspec/interpreted.html.md b/website/source/docs/jobspec/interpreted.html.md new file mode 100644 index 000000000..fde6f1eb2 --- /dev/null +++ b/website/source/docs/jobspec/interpreted.html.md @@ -0,0 +1,199 @@ +--- +layout: "docs" +page_title: "Interpreted Variables" +sidebar_current: "docs-jobspec-interpreted" +description: |- + Learn about the Nomad's interpreted variables. +--- +# Interpreted Variables + +Nomad support interpreting two classes of variables, node attributes and runtime +environment variables. Node attributes are interpretable in constraints, task +environment variables and certain driver fields. Runtime environment variables +are not interpretable in constraints because they are only defined once the +scheduler has placed them on a particular node. + +The syntax for interpreting variables is `${variable}`. An example and a +comprehensive list of interpretable fields can be seen below: + +``` +task "demo" { + driver = "docker" + + # Drivers support interpreting node attributes and runtime environment + # variables + config { + image = "my-app" + + # Interpret runtime variables to inject the address to bind to and the + # location to write logs to. + args = ["--bind=${NOMAD_ADDR_RPC}", "--logs=${NOMAD_ALLOC_DIR}/logs"] + + port_map { + RPC = 6379 + } + } + + # Constraints only support node attributes as runtime environment variables + # are only defined after the task is placed on a node. + constraint { + attribute = "${attr.kernel.name}" + value = "linux" + } + + # Environment variables are interpreted and can contain both runtime and + # node attributes. + env { + "DC" = "Running on datacenter ${node.datacenter}" + "VERSION" = "Version ${NOMAD_META_VERSION}" + } + + # Meta keys are also interpretable. + meta { + VERSION = "v0.3" + } +} +``` + +## Node Variables + +Below is a full listing of node attributes that are interpretable. These +attributes are Interpreted by __both__ constraints and within the task and +driver. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
VariableDescription
${node.unique.id}The client node identifier
${node.datacenter}The client node datacenter
${node.unique.name}The client node name
${node.class}The client node class
${attr.\The attribute given by `key` on the client node.
${meta.\}The metadata value given by `key` on the client node.
+ +Below is a table documenting common node attributes: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
AttributeDescription
archCPU architecture of the client. Examples: `amd64`, `386`
consul.datacenterThe Consul datacenter of the client node if Consul found
cpu.numcoresNumber of CPU cores on the client
driver.\See the [task drivers](/docs/drivers/index.html) for attribute documentation
hostnameHostname of the client
kernel.nameKernel of the client. Examples: `linux`, `darwin`
kernel.versionVersion of the client kernel. Examples: `3.19.0-25-generic`, `15.0.0`
platform.aws.ami-idOn EC2, the AMI ID of the client node
platform.aws.instance-typeOn EC2, the instance type of the client node
os.nameOperating system of the client. Examples: `ubuntu`, `windows`, `darwin`
os.versionVersion of the client OS
+ +## Environment Variables + +The following are runtime environment variables that describe the environment +the task is running in. These are only defined once the task has been placed on +a particular node and as such can not be used in constraints. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
VariableDescription
${NOMAD_ALLOC_DIR}The path to the shared `alloc/` directory. See + [here](/docs/jobspec/environment.html#task_dir) for more + information.
${NOMAD_TASK_DIR}The path to the task `local/` directory. See + [here](/docs/jobspec/environment.html#task_dir) for more + information.
${NOMAD_MEMORY_LIMIT}The memory limit in MBits for the task
${NOMAD_CPU_LIMIT}The CPU limit in MHz for the task
${NOMAD_ADDR_"label"}>The `ip:port` pair for the given port `label`. See + [here](/docs/jobspec/networking.html) for more information.
${NOMAD_HOST_PORT_"label"}The port on the host if port forwarding is being used for the port + `label`. See [here](/docs/jobspec/networking.html#mapped_ports) for more + information.
${NOMAD_META_"key"}The metadata value given by `key` on the task's metadata
${"env_key"}Interpret an environment variable with key `env_key` set on the task.
+ diff --git a/website/source/docs/jobspec/networking.html.md b/website/source/docs/jobspec/networking.html.md index 3dfd726f4..d9888e0f6 100644 --- a/website/source/docs/jobspec/networking.html.md +++ b/website/source/docs/jobspec/networking.html.md @@ -86,7 +86,7 @@ When the task is started, it is passed an environment variable named NOMAD_ADDR_http=127.0.0.1:53423 ./start-command ``` -### Mapped Ports +### Mapped Ports Some drivers (such as Docker and QEMU) allow you to map ports. A mapped port means that your application can listen on a fixed port (it does not need to diff --git a/website/source/layouts/docs.erb b/website/source/layouts/docs.erb index 023efba11..62ccf6445 100644 --- a/website/source/layouts/docs.erb +++ b/website/source/layouts/docs.erb @@ -38,6 +38,9 @@ > Syntax + > + Interpreted Variables + > Runtime Environment