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

     1  ---
     2  layout: docs
     3  page_title: connect Stanza - Job Specification
     4  sidebar_title: connect
     5  description: The "connect" stanza allows specifying options for Consul Connect integration
     6  ---
     7  
     8  # `connect` Stanza
     9  
    10  <Placement groups={['job', 'group', 'service', 'connect']} />
    11  
    12  The `connect` stanza allows configuring various options for
    13  [Consul Connect](/docs/integrations/consul-connect). It is
    14  valid only within the context of a service definition at the task group
    15  level. For using `connect` when Consul ACLs are enabled, be sure to read through
    16  the [Secure Nomad Jobs with Consul Connect](https://learn.hashicorp.com/nomad/consul-integration/nomad-connect-acl)
    17  guide.
    18  
    19  ```hcl
    20  job "countdash" {
    21    datacenters = ["dc1"]
    22  
    23    group "api" {
    24      network {
    25        mode = "bridge"
    26      }
    27  
    28      service {
    29        name = "count-api"
    30        port = "9001"
    31  
    32        connect {
    33          sidecar_service {}
    34        }
    35      }
    36  
    37      task "web" {
    38        driver = "docker"
    39  
    40        config {
    41          image = "hashicorpnomad/counter-api:v2"
    42        }
    43      }
    44    }
    45  }
    46  ```
    47  
    48  ## `connect` Parameters
    49  
    50  - `sidecar_service` - <code>([sidecar_service][]: nil)</code> - This is used to configure the sidecar
    51    service injected by Nomad for Consul Connect.
    52  
    53  - `sidecar_task` - <code>([sidecar_task][]:nil)</code> - This modifies the configuration of the Envoy
    54    proxy task.
    55  
    56  ## `connect` Examples
    57  
    58  The following example is a minimal connect stanza with defaults and is
    59  sufficient to start an Envoy proxy sidecar for allowing incoming connections
    60  via Consul Connect.
    61  
    62  ```hcl
    63    connect {
    64      sidecar_service {}
    65    }
    66  ```
    67  
    68  The following example includes specifying [`upstreams`][upstreams].
    69  
    70  ```hcl
    71    connect {
    72       sidecar_service {
    73         proxy {
    74           upstreams {
    75             destination_name = "count-api"
    76             local_bind_port = 8080
    77           }
    78         }
    79       }
    80    }
    81  ```
    82  
    83  The following is the complete `countdash` example. It includes an API service
    84  and a frontend Dashboard service which connects to the API service as a Connect
    85  upstream. Once running, the dashboard is accessible at `localhost:9002`.
    86  
    87  ```hcl
    88  job "countdash" {
    89    datacenters = ["dc1"]
    90  
    91    group "api" {
    92      network {
    93        mode = "bridge"
    94      }
    95  
    96      service {
    97        name = "count-api"
    98        port = "9001"
    99  
   100        connect {
   101          sidecar_service {}
   102        }
   103  
   104        check {
   105          expose   = true
   106          type     = "http"
   107          name     = "api-health"
   108          path     = "/health"
   109          interval = "10s"
   110          timeout  = "3s"
   111        }
   112      }
   113  
   114      task "web" {
   115        driver = "docker"
   116  
   117        config {
   118          image = "hashicorpnomad/counter-api:v2"
   119        }
   120      }
   121    }
   122  
   123    group "dashboard" {
   124      network {
   125        mode = "bridge"
   126  
   127        port "http" {
   128          static = 9002
   129          to     = 9002
   130        }
   131      }
   132  
   133      service {
   134        name = "count-dashboard"
   135        port = "9002"
   136  
   137        connect {
   138          sidecar_service {
   139            proxy {
   140              upstreams {
   141                destination_name = "count-api"
   142                local_bind_port  = 8080
   143              }
   144            }
   145          }
   146        }
   147      }
   148  
   149      task "dashboard" {
   150        driver = "docker"
   151  
   152        env {
   153          COUNTING_SERVICE_URL = "http://${NOMAD_UPSTREAM_ADDR_count_api}"
   154        }
   155  
   156        config {
   157          image = "hashicorpnomad/counter-dashboard:v2"
   158        }
   159      }
   160    }
   161  }
   162  ```
   163  
   164  ### Limitations
   165  
   166  [Consul Connect Native services][native] and [Nomad variable
   167  interpolation][interpolation] are _not_ yet supported.
   168  
   169  [job]: /docs/job-specification/job 'Nomad job Job Specification'
   170  [group]: /docs/job-specification/group 'Nomad group Job Specification'
   171  [task]: /docs/job-specification/task 'Nomad task Job Specification'
   172  [interpolation]: /docs/runtime/interpolation 'Nomad interpolation'
   173  [sidecar_service]: /docs/job-specification/sidecar_service 'Nomad sidecar service Specification'
   174  [sidecar_task]: /docs/job-specification/sidecar_task 'Nomad sidecar task config Specification'
   175  [upstreams]: /docs/job-specification/upstreams 'Nomad sidecar service upstreams Specification'
   176  [native]: https://www.consul.io/docs/connect/native.html