github.com/jmitchell/nomad@v0.1.3-0.20151007230021-7ab84c2862d8/website/source/docs/jobspec/index.html.md (about) 1 --- 2 layout: "docs" 3 page_title: "Job Specification" 4 sidebar_current: "docs-jobspec" 5 description: |- 6 Learn about the Job specification used to submit jobs to Nomad. 7 --- 8 9 # Job Specification 10 11 Jobs can be specified either in [HCL](https://github.com/hashicorp/hcl) or JSON. 12 HCL is meant to strike a balance between human readable and editable, as well 13 as being machine-friendly. 14 15 For machine-friendliness, Nomad can also read JSON configurations. In general, we recommend 16 using the HCL syntax. 17 18 ## HCL Syntax 19 20 For a detailed description of HCL general syntax, [see this guide](https://github.com/hashicorp/hcl#syntax). 21 Here we cover the details of the Job specification for Nomad: 22 23 ``` 24 # Define a job called my-service 25 job "my-service" { 26 # Job should run in the US region 27 region = "us" 28 29 # Spread tasks between us-west-1 and us-east-1 30 datacenters = ["us-west-1", "us-east-1"] 31 32 # Rolling updates should be sequential 33 update { 34 stagger = "30s" 35 max_parallel = 1 36 } 37 38 group "webs" { 39 # We want 5 web servers 40 count = 5 41 42 # Create a web front end using a docker image 43 task "frontend" { 44 driver = "docker" 45 config { 46 image = "hashicorp/web-frontend" 47 } 48 env { 49 DB_HOST = "db01.example.com" 50 DB_USER = "web" 51 DB_PASSWORD = "loremipsum" 52 } 53 resources { 54 cpu = 500 55 memory = 128 56 network { 57 mbits = 100 58 dynamic_ports = [ 59 "http", 60 "https", 61 ] 62 } 63 } 64 } 65 } 66 } 67 ``` 68 69 This is a fairly simple example job, but demonstrates many of the features and syntax 70 of the job specification. The primary "objects" are the job, task group, and task. 71 Each job file has only a single job, however a job may have multiple task groups, 72 and each task group may have multiple tasks. Task groups are a set of tasks that 73 must be co-located on a machine. Groups with a single task and count of one 74 can be declared outside of a group which is created implicitly. 75 76 Constraints can be specified at the job, task group, or task level to restrict 77 where a task is eligible for running. An example constraint looks like: 78 79 ``` 80 # Restrict to only nodes running linux 81 constraint { 82 attribute = "$attr.kernel.os" 83 value = "linux" 84 } 85 ``` 86 87 Jobs can also specify additional metadata at the job, task group, or task level. 88 This metadata is opaque to Nomad and can be used for any purpose, including 89 defining constraints on the metadata. Metadata can be specified by: 90 91 ``` 92 # Setup ELB via metadata and setup foo 93 meta { 94 foo = "bar" 95 elb_mode = "tcp" 96 elb_check_interval = "10s" 97 } 98 ``` 99 100 ## Syntax Reference 101 102 Following is a syntax reference for the possible keys that are supported 103 and their default values if any for each type of object. 104 105 ### Job 106 107 The `job` object supports the following keys: 108 109 * `all_at_once` - Controls if the entire set of tasks in the job must 110 be placed atomically or if they can be scheduled incrementally. 111 This should only be used for special circumstances. Defaults to `false`. 112 113 * `constraint` - This can be provided multiple times to define additional 114 constraints. See the constraint reference for more details. 115 116 * `datacenters` - A list of datacenters in the region which are eligible 117 for task placement. This must be provided, and does not have a default. 118 119 * `group` - This can be provided multiple times to define additional 120 task groups. See the task group reference for more details. 121 122 * `meta` - Annotates the job with opaque metadata. 123 124 * `priority` - Specifies the job priority which is used to prioritize 125 scheduling and access to resources. Must be between 1 and 100 inclusively, 126 and defaults to 50. 127 128 * `region` - The region to run the job in, defaults to "global". 129 130 * `task` - This can be specified multiple times to add a task as 131 part of the job. Tasks defined directly in a job are wrapped in 132 a task group of the same name. 133 134 * `type` - Specifies the job type and switches which scheduler 135 is used. Nomad provides the `service` and `batch` schedulers, 136 and defaults to `service`. 137 138 * `update` - Specifies the task update strategy. This requires providing 139 `max_parallel` as an integer and `stagger` as a time duration. If stagger 140 is provided as an integer, seconds are assumed. Otherwise the "s", "m", 141 and "h" suffix can be used, such as "30s". Both values default to zero, 142 which disables rolling updates. 143 144 ### Task Group 145 146 The `group` object supports the following keys: 147 148 * `count` - Specifies the number of the task groups that should 149 be running. Must be positive, defaults to one. 150 151 * `constraint` - This can be provided multiple times to define additional 152 constraints. See the constraint reference for more details. 153 154 * `task` - This can be specified multiple times, to add a task as 155 part of the group. 156 157 * `meta` - Annotates the task group with opaque metadata. 158 159 ### Task 160 161 The `task` object supports the following keys: 162 163 * `driver` - Specifies the task driver that should be used to run the 164 task. See the [driver documentation](/docs/drivers/index.html) for what 165 is available. Examples include "docker", "qemu", "java", and "exec". 166 167 * `constraint` - This can be provided multiple times to define additional 168 constraints. See the constraint reference for more details. 169 170 * `config` - A map of key/value configuration passed into the driver 171 to start the task. The details of configurations are specific to 172 each driver. 173 174 * `env` - A map of key/value representing environment variables that 175 will be passed along to the running process. 176 177 * `resources` - Provides the resource requirements of the task. 178 See the resources reference for more details. 179 180 * `meta` - Annotates the task group with opaque metadata. 181 182 ### Resources 183 184 The `resources` object supports the following keys: 185 186 * `cpu` - The CPU required in MHz. 187 188 * `disk` - The disk required in MB. 189 190 * `iops` - The number of IOPS required given as a weight between 10-1000. 191 192 * `memory` - The memory required in MB. 193 194 * `network` - The network required. Details below. 195 196 The `network` object supports the following keys: 197 198 * `dynamic_ports` - List of port labels which may contain letters, 199 numbers and underscores (`^[a-zA-Z0-9_]+$`). Each label will be assigned a 200 dynamic port when the task starts. Ports are passed to the task environment as 201 `NOMAD_PORT_{LABEL}`. Drivers may infer additional semantics from the label. 202 See the relevant driver docs for details. 203 204 * `mbits` - The number of MBits in bandwidth required. 205 206 * `reserved_ports` - This is a list of specific ports required. 207 For applications that cannot use a dynamic port, they can 208 request a specific port. 209 210 ### Constraint 211 212 The `constraint` object supports the following keys: 213 214 * `attribute` - Specifies the attribute to examine for the 215 constraint. See the table of attributes below. 216 217 * `hard` - Specifies if this is a hard or soft constraint. Defaults 218 to true. Soft constraints are not currently supported. 219 220 * `operator` - Specifies the comparison operator. Defaults to equality, 221 and can be `=`, `==`, `is`, `!=`, `not`. 222 223 * `value` - Specifies the value to compare the attribute against. 224 This can be a literal value or another attribute. 225 226 Below is a table documenting the variables that can be interpreted: 227 228 <table class="table table-bordered table-striped"> 229 <tr> 230 <th>Variable</th> 231 <th>Description</th> 232 </tr> 233 <tr> 234 <td>$node.id</td> 235 <td>The client node identifier</td> 236 </tr> 237 <tr> 238 <td>$node.datacenter</td> 239 <td>The client node datacenter</td> 240 </tr> 241 <tr> 242 <td>$node.name</td> 243 <td>The client node name</td> 244 </tr> 245 <tr> 246 <td>$attr.\<key\></td> 247 <td>The attribute given by `key` on the client node.</td> 248 </tr> 249 <tr> 250 <td>$meta.\<key\></td> 251 <td>The metadata value given by `key` on the client node.</td> 252 </tr> 253 </table> 254 255 Below is a table documenting common node attributes: 256 257 <table class="table table-bordered table-striped"> 258 <tr> 259 <th>Attribute</th> 260 <th>Description</th> 261 </tr> 262 <tr> 263 <td>arch</td> 264 <td>CPU architecture of the client. Examples: "amd64", "386"</td> 265 </tr> 266 <tr> 267 <td>consul.datacenter</td> 268 <td>The Consul datacenter of the client node if Consul found</td> 269 </tr> 270 <tr> 271 <td>cpu.numcores</td> 272 <td>Number of CPU cores on the client</td> 273 </tr> 274 <tr> 275 <td>driver.\<key\></td> 276 <td>See the [task drivers](/docs/drivers/index.html) for attribute documentation</td> 277 </tr> 278 <tr> 279 <td>hostname</td> 280 <td>Hostname of the client</td> 281 </tr> 282 <tr> 283 <td>platform.aws.ami-id</td> 284 <td>On EC2, the AMI ID of the client node</td> 285 </tr> 286 <tr> 287 <td>platform.aws.instance-type</td> 288 <td>On EC2, the instance type of the client node</td> 289 </tr> 290 <tr> 291 <td>os.name</td> 292 <td>Operating system of the client. Examples: "linux", "windows", "darwin"</td> 293 </tr> 294 <tr> 295 <td>os.version</td> 296 <td>Version of the client OS</td> 297 </tr> 298 </table> 299 300 ## JSON Syntax 301 302 Job files can also be specified in JSON. The conversion is straightforward 303 and self-documented. The downsides of JSON are less human readability and 304 the lack of comments. Otherwise, the two are completely interoperable. 305 306 See the API documentation for more details on the JSON structure. 307 308