github.com/huiliang/nomad@v0.2.1-0.20151124023127-7a8b664699ff/website/source/docs/jobspec/servicediscovery.html.md (about)

     1  ---
     2  layout: "docs"
     3  page_title: "Service Discovery in Nomad"
     4  sidebar_current: "docs-jobspec-service-discovery"
     5  description: |-
     6    Learn how to add service discovery to jobs
     7  ---
     8  
     9  # Service Discovery
    10  
    11  Nomad schedules workloads of various types across a cluster of generic hosts.
    12  Because of this, placement is not known in advance and you will need to use
    13  service discovery to connect tasks to other services deployed across your
    14  cluster. Nomad integrates with [Consul](https://consul.io) to provide service
    15  discovery and monitoring.
    16  
    17  Note that in order to use Consul with Nomad, you will need to configure and
    18  install Consul on your nodes alongside Nomad, or schedule it as a system job.
    19  Nomad does not currently run Consul for you.
    20  
    21  ## Configuration
    22  
    23  * `consul.address`: This is a Nomad client configuration which can be used to
    24    override the default Consul Agent HTTP port that Nomad uses to connect to
    25    Consul. The default for this is `127.0.0.1:8500`.
    26  
    27  ## Service Definition Syntax
    28  
    29  The service blocks in a Task definition defines a service which Nomad will
    30  register with Consul. Multiple Service blocks are allowed in a Task definition,
    31  which allow registering multiple services for a task that exposes multiple
    32  ports.
    33  
    34  ### Example
    35  
    36  A brief example of a service definition in a Task
    37  
    38  ```
    39  group "database" {
    40      task "mysql" {
    41          driver = "docker"
    42          service {
    43              tags = ["master", "mysql"]
    44              port = "db"
    45              check {
    46                  type = "tcp"
    47                  delay = "10s"
    48                  timeout = "2s"
    49              }
    50          }
    51          resources {
    52              cpu = 500
    53              memory = 1024
    54              network {
    55                  mbits = 10
    56                  port "db" {
    57                  }
    58              }
    59          }
    60      }
    61  }
    62  ```
    63  
    64  * `name`: Nomad automatically determines the name of a Task. By default the
    65    name of a service is $(job-name)-$(task-group)-$(task-name). Users can
    66    explicitly name the service by specifying this option. If multiple services
    67    are defined for a Task then only one task can have the default name, all the
    68    services have to be explicitly named. Nomad will add the prefix ```$(job-name
    69    )-${task-group}-${task-name}``` prefix to each user defined name.
    70  
    71  * `tags`: A list of tags associated with this Service.
    72  
    73  * `port`: The port indicates the port associated with the Service. Users are
    74    required to specify a valid port label here which they have defined in the
    75    resources block. This could be a label to either a dynamic or a static port.
    76    If an incorrect port label is specified, Nomad doesn't register the service
    77    with Consul.
    78  
    79  * `check`: A check block defines a health check associated with the service.
    80    Multiple check blocks are allowed for a service. Nomad currently supports
    81    only the `http` and `tcp` Consul Checks.
    82  
    83  ### Check Syntax
    84  
    85  * `type`: This indicates the check types supported by Nomad. Valid options are
    86    currently `http` and `tcp`. In the future Nomad will add support for more
    87    Consul checks.
    88  
    89  * `delay`: This indicates the frequency of the health checks that Consul with
    90    perform.
    91  
    92  * `timeout`: This indicates how long Consul will wait for a health check query
    93    to succeed.
    94  
    95  * `path`: The path of the http endpoint which Consul will query to query the
    96    health of a service if the type of the check is `http`. Nomad will add the ip
    97    of the service and the port, users are only required to add the relative url
    98    of the health check endpoint.
    99  
   100  * `protocol`: This indicates the protocol for the http checks. Valid options
   101    are `http` and `https`. We default it to `http`
   102  
   103  ## Assumptions
   104  
   105  * Consul 0.6 is needed for using the TCP checks.
   106  
   107  * The Service Discovery feature in Nomad depends on Operators making sure that
   108    the Nomad client can reach the consul agent.
   109  
   110  * Nomad assumes that it controls the life cycle of all the externally
   111    discoverable services running on a host.
   112  
   113  * Tasks running inside Nomad also needs to reach out to the Consul agent if
   114    they want to use any of the Consul APIs. Ex: A task running inside a docker
   115    container in the bridge mode won't be able to talk to a Consul Agent running
   116    on the loopback interface of the host since the container in the bridge mode
   117    has it's own network interface and doesn't see interfaces on the global
   118    network namespace of the host. There are a couple of ways to solve this, one
   119    way is to run the container in the host networking mode, or make the Consul
   120    agent listen on an interface on the network namespace of the container.