github.com/smintz/nomad@v0.8.3/website/source/docs/job-specification/index.html.md (about) 1 --- 2 layout: "docs" 3 page_title: "Job Specification" 4 sidebar_current: "docs-job-specification-syntax" 5 description: |- 6 Learn about the Job specification used to submit jobs to Nomad. 7 --- 8 9 # Job Specification 10 11 The Nomad job specification (or "jobspec" for short) defines the schema for 12 Nomad jobs. Nomad jobs are specified in [HCL][], which aims to strike a balance 13 between human readable and editable, and machine-friendly. 14 15 The job specification is broken down into smaller pieces, which you will find 16 expanded in the navigation menu. We recommend getting started at the [job][] 17 stanza. Alternatively, you can keep reading to see a few examples. 18 19 For machine-friendliness, Nomad can also read JSON-equivalent configurations. In 20 general, we recommend using the HCL syntax. 21 22 The general hierarchy for a job is: 23 24 ```text 25 job 26 \_ group 27 \_ task 28 ``` 29 30 Each job file has only a single job, however a job may have multiple groups, and 31 each group may have multiple tasks. Groups contain a set of tasks that are 32 co-located on a machine. 33 34 ## Example 35 36 This example shows a sample job file. We tried to keep it as simple as possible, 37 while still showcasing the power of Nomad. For a more detailed explanation of 38 any of these fields, please use the navigation to dive deeper. 39 40 ```hcl 41 # This declares a job named "docs". There can be exactly one 42 # job declaration per job file. 43 job "docs" { 44 # Specify this job should run in the region named "us". Regions 45 # are defined by the Nomad servers' configuration. 46 region = "us" 47 48 # Spread the tasks in this job between us-west-1 and us-east-1. 49 datacenters = ["us-west-1", "us-east-1"] 50 51 # Run this job as a "service" type. Each job type has different 52 # properties. See the documentation below for more examples. 53 type = "service" 54 55 # Specify this job to have rolling updates, two-at-a-time, with 56 # 30 second intervals. 57 update { 58 stagger = "30s" 59 max_parallel = 2 60 } 61 62 # A group defines a series of tasks that should be co-located 63 # on the same client (host). All tasks within a group will be 64 # placed on the same host. 65 group "webs" { 66 # Specify the number of these tasks we want. 67 count = 5 68 69 # Create an individual task (unit of work). This particular 70 # task utilizes a Docker container to front a web application. 71 task "frontend" { 72 # Specify the driver to be "docker". Nomad supports 73 # multiple drivers. 74 driver = "docker" 75 76 # Configuration is specific to each driver. 77 config { 78 image = "hashicorp/web-frontend" 79 } 80 81 # The service block tells Nomad how to register this service 82 # with Consul for service discovery and monitoring. 83 service { 84 # This tells Consul to monitor the service on the port 85 # labelled "http". Since Nomad allocates high dynamic port 86 # numbers, we use labels to refer to them. 87 port = "http" 88 89 check { 90 type = "http" 91 path = "/health" 92 interval = "10s" 93 timeout = "2s" 94 } 95 } 96 97 # It is possible to set environment variables which will be 98 # available to the task when it runs. 99 env { 100 "DB_HOST" = "db01.example.com" 101 "DB_USER" = "web" 102 "DB_PASS" = "loremipsum" 103 } 104 105 # Specify the maximum resources required to run the task, 106 # include CPU, memory, and bandwidth. 107 resources { 108 cpu = 500 # MHz 109 memory = 128 # MB 110 111 network { 112 mbits = 100 113 114 # This requests a dynamic port named "http". This will 115 # be something like "46283", but we refer to it via the 116 # label "http". 117 port "http" {} 118 119 # This requests a static port on 443 on the host. This 120 # will restrict this task to running once per host, since 121 # there is only one port 443 on each host. 122 port "https" { 123 static = 443 124 } 125 } 126 } 127 } 128 } 129 } 130 ``` 131 132 [hcl]: https://github.com/hashicorp/hcl "HashiCorp Configuration Language" 133 [job]: /docs/job-specification/job.html "Nomad job Job Specification"