github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/docs/job-specification/upstreams.mdx (about)

     1  ---
     2  layout: docs
     3  page_title: upstreams Stanza - Job Specification
     4  description: |-
     5    The "upstreams" stanza allows specifying options for configuring
     6    upstream services
     7  ---
     8  
     9  # `upstreams` Stanza
    10  
    11  <Placement
    12    groups={[
    13      'job',
    14      'group',
    15      'service',
    16      'connect',
    17      'sidecar_service',
    18      'proxy',
    19      'upstreams',
    20    ]}
    21  />
    22  
    23  The `upstreams` stanza allows configuring various options for managing upstream
    24  services that a [Consul
    25  Connect](/docs/integrations/consul-connect) proxy routes to. It
    26  is valid only within the context of a `proxy` stanza.
    27  
    28  For Consul-specific details see the [Consul Connect
    29  Guide](https://learn.hashicorp.com/consul/getting-started/connect#register-a-dependent-service-and-proxy).
    30  
    31  ```hcl
    32  job "countdash" {
    33    datacenters = ["dc1"]
    34  
    35    group "dashboard" {
    36      network {
    37        mode = "bridge"
    38  
    39        port "http" {
    40          static = 9002
    41          to     = 9002
    42        }
    43      }
    44  
    45      service {
    46        name = "count-dashboard"
    47        port = "9002"
    48  
    49        connect {
    50          sidecar_service {
    51            proxy {
    52              upstreams {
    53                destination_name = "count-api"
    54                local_bind_port  = 8080
    55                datacenter = "dc2"
    56                local_bind_address = "127.0.0.1"
    57                mesh_gateway {
    58                  mode = "local"
    59                }
    60              }
    61            }
    62          }
    63        }
    64      }
    65  
    66      task "dashboard" {
    67        driver = "docker"
    68  
    69        env {
    70          COUNTING_SERVICE_URL = "http://${NOMAD_UPSTREAM_ADDR_count_api}"
    71        }
    72  
    73        config {
    74          image = "hashicorpdev/counter-dashboard:v3"
    75        }
    76      }
    77    }
    78  }
    79  
    80  ```
    81  
    82  ## `upstreams` Parameters
    83  
    84  - `destination_name` `(string: <required>)` - Name of the upstream service.
    85  - `destination_namespace` `(string: <required>)` - Name of the upstream Consul namespace.
    86  - `local_bind_port` - `(int: <required>)` - The port the proxy will receive
    87    connections for the upstream on.
    88  - `datacenter` `(string: "")` - The Consul datacenter in which to issue the
    89    discovery query. Defaults to the empty string, which Consul interprets as the
    90    local Consul datacenter.
    91  - `local_bind_address` - `(string: "")` - The address the proxy will receive
    92    connections for the upstream on.
    93  - `mesh_gateway` <code>([mesh_gateway][mesh_gateway_param]: nil)</code> - Configures the mesh gateway
    94    behavior for connecting to this upstream.
    95  
    96  ### `mesh_gateway` Parameters
    97  
    98  - `mode` `(string: "")` - The mode of operation in which to use [Connect Mesh Gateways][mesh_gateways].
    99    If left unset, the mode will default to the mode as determined by the Consul [service-defaults][service_defaults_mode]
   100    configuration for the service. Can be configured with the following modes:
   101    - `local` - In this mode the Connect proxy makes its outbound connection to a
   102    gateway running in the same datacenter. That gateway is then responsible for
   103    ensuring the data gets forwarded along to gateways in the destination datacenter.
   104    - `remote` - In this mode the Connect proxy makes its outbound connection to a
   105    gateway running in the destination datacenter. That gateway will then forward
   106    the data to the final destination service.
   107    - `none` - In this mode, no gateway is used and a Connect proxy makes its
   108    outbound connections directly to the destination services.
   109  
   110  The `NOMAD_UPSTREAM_ADDR_<destination_name>` environment variables may be used
   111  to interpolate the upstream's `host:port` address.
   112  
   113  Applications are encouraged to connect to `127.0.0.1` and a well defined port
   114  (eg 6379 for Redis) by default. Then when using Consul Connect the application
   115  can be deployed with the Redis upstream's `local_bind_port = 6379` and require
   116  no explicit configuration.
   117  
   118  ## `upstreams` Examples
   119  
   120  The following example is an upstream config with the name of the destination service
   121  and a local bind port.
   122  
   123  ```hcl
   124      upstreams {
   125        destination_name = "count-api"
   126        local_bind_port = 8080
   127      }
   128  ```
   129  
   130  [job]: /docs/job-specification/job 'Nomad job Job Specification'
   131  [group]: /docs/job-specification/group 'Nomad group Job Specification'
   132  [task]: /docs/job-specification/task 'Nomad task Job Specification'
   133  [interpolation]: /docs/runtime/interpolation 'Nomad interpolation'
   134  [sidecar_service]: /docs/job-specification/sidecar_service 'Nomad sidecar service Specification'
   135  [upstreams]: /docs/job-specification/upstreams 'Nomad upstream config Specification'
   136  [service_defaults_mode]: https://developer.hashicorp.com/consul/docs/connect/config-entries/service-defaults#meshgateway
   137  [mesh_gateway_param]: /docs/job-specification/upstreams#mesh_gateway-parameters
   138  [mesh_gateways]: https://developer.hashicorp.com/consul/docs/connect/gateways/mesh-gateway/service-to-service-traffic-datacenters#mesh-gateways