github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/website/pages/docs/job-specification/index.mdx (about)

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