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

     1  ---
     2  layout: docs
     3  page_title: sidecar_task Stanza - Job Specification
     4  description: |-
     5    The "sidecar_task" stanza allows specifying options for configuring
     6    the task of the sidecar proxies used in Consul Connect integration
     7  ---
     8  
     9  # `sidecar_task` Stanza
    10  
    11  <Placement groups={['job', 'group', 'service', 'connect', 'sidecar_task']} />
    12  
    13  The `sidecar_task` stanza allows configuring various options for the proxy
    14  sidecar or Connect gateway managed by Nomad for the [Consul
    15  Connect](/docs/integrations/consul-connect) integration such as
    16  resource requirements, kill timeouts and more as defined below. It is valid
    17  only within the context of a [`connect`][connect] stanza.
    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          sidecar_task {
    36            resources {
    37              cpu    = 500
    38              memory = 1024
    39            }
    40          }
    41        }
    42      }
    43  
    44      task "web" {
    45        driver = "docker"
    46  
    47        config {
    48          image = "hashicorpdev/counter-api:v3"
    49        }
    50      }
    51    }
    52  }
    53  ```
    54  
    55  ## Default Envoy configuration
    56  
    57  Nomad automatically launches and manages an Envoy task for use as a proxy sidecar
    58  or connect gateway, when [`sidecar_service`][sidecar_service] or [`gateway`][gateway]
    59  are configured.
    60  
    61  The default Envoy task is equivalent to:
    62  
    63  ```hcl
    64  sidecar_task {
    65    name = "connect-proxy-<service>"
    66    #      "connect-gateway-<service>" when used as a gateway
    67  
    68    lifecycle { # absent when used as a gateway
    69      hook    = "prestart"
    70      sidecar = true
    71    }
    72  
    73    driver = "docker"
    74  
    75    config {
    76      image = "${meta.connect.sidecar_image}"
    77      #       "${meta.connect.gateway_image}" when used as a gateway
    78  
    79      args = [
    80        "-c",
    81        "${NOMAD_SECRETS_DIR}/envoy_bootstrap.json",
    82        "-l",
    83        "${meta.connect.log_level}",
    84        "--concurrency",
    85        "${meta.connect.proxy_concurrency}",
    86        "--disable-hot-restart"
    87      ]
    88    }
    89  
    90    logs {
    91      max_files     = 2
    92      max_file_size = 2 # MB
    93    }
    94  
    95    resources {
    96      cpu    = 250 # MHz
    97      memory = 128 # MB
    98    }
    99  
   100    shutdown_delay = "5s"
   101  }
   102  ```
   103  
   104  The `meta.connect.sidecar_image`, `meta.connect.gateway_image`, `meta.connect.log_level`,
   105  and `meta.connect.proxy_concurrency` variables are [client configurable][nodemeta]
   106  variables with the following defaults:
   107  
   108  - `sidecar_image` - `(string: "envoyproxy/envoy:v${NOMAD_envoy_version}")` - The official
   109    upstream Envoy Docker image, where `${NOMAD_envoy_version}` is resolved automatically
   110    by a query to Consul.
   111  - `gateway_image` - `(string: "envoyproxy/envoy:v${NOMAD_envoy_version}")` - The official
   112    upstream Envoy Docker image, where `${NOMAD_envoy_version}` is resolved automatically
   113    by a query to Consul.
   114  - `log_level` - `(string: "info")` - Envoy sidecar log level. "`debug`" is useful for
   115    debugging Connect related issues.
   116  - `proxy_concurrency` - `(string: "1")` - The number of [worker threads][worker_threads] the Envoy
   117    sidecar will run.
   118  
   119  Custom images can make use of Consul's preferred Envoy version by making use of
   120  Nomad's version interpolation, e.g.
   121  
   122  ```hcl
   123  meta.connect.sidecar_image = custom/envoy-${NOMAD_envoy_version}:latest
   124  ```
   125  
   126  ## `sidecar_task` Parameters
   127  
   128  - `name` `(string: "connect-[proxy|gateway]-<service>")` - Name of the task. Defaults to
   129    including the name of the service the proxy or gateway is providing.
   130  
   131  - `driver` `(string: "docker")` - Driver used for the sidecar task.
   132  
   133  - `user` `(string: nil)` - Determines which user is used to run the task, defaults
   134    to the same user the Nomad client is being run as.
   135  
   136  - `config` `(map: nil)` - Configuration provided to the driver for initialization.
   137    Keys and values support [runtime variable interpolation][interpolation].
   138  
   139  - `env` `(map: nil)` - Map of environment variables used by the driver.
   140  
   141  - `resources` <code>([Resources][resources])</code> - Resources needed by the sidecar task.
   142  
   143  - `meta` `(map: nil)` - Arbitrary metadata associated with this task that's opaque to Nomad.
   144  
   145  - `logs` <code>([Logs][]: nil)</code> - Specifies logging configuration for the
   146    `stdout` and `stderr` of the task.
   147  
   148  - `kill_timeout` `(string: "5s")` - Time between signalling a task that will be
   149    killed and killing it.
   150  
   151  - `shutdown_delay` `(string: "5s")` - Delay between deregistering the task from
   152    Consul and sending it a signal to shutdown.
   153  
   154  - `kill_signal` `(string:SIGINT)` - Kill signal to use for the task, defaults to SIGINT.
   155  
   156  ## `sidecar_task` Examples
   157  
   158  The following example configures resources for the sidecar task and other configuration.
   159  
   160  ```hcl
   161     sidecar_task {
   162       resources {
   163         cpu = 500
   164         memory = 1024
   165       }
   166  
   167       env {
   168         FOO = "abc"
   169       }
   170  
   171       shutdown_delay = "5s"
   172     }
   173  
   174  ```
   175  
   176  [connect]: /docs/job-specification/connect 'Nomad connect Job Specification'
   177  [gateway]: /docs/job-specification/gateway
   178  [group]: /docs/job-specification/group 'Nomad group Job Specification'
   179  [interpolation]: /docs/runtime/interpolation 'Nomad interpolation'
   180  [job]: /docs/job-specification/job 'Nomad job Job Specification'
   181  [logs]: /docs/job-specification/logs 'Nomad logs Job Specification'
   182  [resources]: /docs/job-specification/resources 'Nomad resources Job Specification'
   183  [sidecar_service]: /docs/job-specification/sidecar_service 'Nomad sidecar service Specification'
   184  [task]: /docs/job-specification/task 'Nomad task Job Specification'
   185  [nodemeta]: /docs/configuration/client#meta
   186  [worker_threads]: https://www.envoyproxy.io/docs/envoy/latest/operations/cli#cmdoption-concurrency