github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/website/content/docs/job-specification/sidecar_task.mdx (about) 1 --- 2 layout: docs 3 page_title: sidecar_task Stanza - Job Specification 4 sidebar_title: sidecar_task 5 description: |- 6 The "sidecar_task" stanza allows specifying options for configuring 7 the task of the sidecar proxies used in Consul Connect integration 8 --- 9 10 # `sidecar_task` Stanza 11 12 <Placement groups={['job', 'group', 'service', 'connect', 'sidecar_task']} /> 13 14 The `sidecar_task` stanza allows configuring various options for the proxy 15 sidecar or Connect gateway managed by Nomad for the [Consul 16 Connect](/docs/integrations/consul-connect) integration such as 17 resource requirements, kill timeouts and more as defined below. It is valid 18 only within the context of a [`connect`][connect] stanza. 19 20 ```hcl 21 job "countdash" { 22 datacenters = ["dc1"] 23 24 group "api" { 25 network { 26 mode = "bridge" 27 } 28 29 service { 30 name = "count-api" 31 port = "9001" 32 33 connect { 34 sidecar_service = {} 35 36 sidecar_task { 37 resources { 38 cpu = 500 39 memory = 1024 40 } 41 } 42 } 43 } 44 45 task "web" { 46 driver = "docker" 47 48 config { 49 image = "hashicorpnomad/counter-api:v3" 50 } 51 } 52 } 53 } 54 ``` 55 56 ## Default Envoy configuration 57 58 Nomad automatically launches and manages an Envoy task for use as a proxy sidecar 59 or connect gateway, when [`sidecar_service`][sidecar_service] or [`gateway`][gateway] 60 are configured. 61 62 The default Envoy task is equivalent to: 63 64 ```hcl 65 sidecar_task { 66 name = "connect-proxy-<service>" 67 # "connect-gateway-<service>" when used as a gateway 68 69 lifecycle { # absent when used as a gateway 70 hook = "prestart" 71 sidecar = true 72 } 73 74 driver = "docker" 75 76 config { 77 image = "${meta.connect.sidecar_image}" 78 # "${meta.connect.gateway_image}" when used as a gateway 79 80 args = [ 81 "-c", 82 "${NOMAD_SECRETS_DIR}/envoy_bootstrap.json", 83 "-l", 84 "${meta.connect.log_level}", 85 "--concurrency", 86 "${meta.connect.proxy_concurrency}", 87 "--disable-hot-restart" 88 ] 89 } 90 91 logs { 92 max_files = 2 93 max_file_size = 2 # MB 94 } 95 96 resources { 97 cpu = 250 # MHz 98 memory = 128 # MB 99 } 100 101 shutdown_delay = "5s" 102 } 103 ``` 104 105 The `meta.connect.sidecar_image`, `meta.connect.gateway_image`, `meta.connect.log_level`, 106 and `meta.connect.proxy_concurrency` variables are [client configurable][nodemeta] 107 variables with the following defaults: 108 109 - `sidecar_image` - `(string: "envoyproxy/envoy:v${NOMAD_envoy_version}")` - The official 110 upstream Envoy Docker image, where `${NOMAD_envoy_version}` is resolved automatically 111 by a query to Consul. 112 - `gateway_image` - `(string: "envoyproxy/envoy:v${NOMAD_envoy_version}")` - The official 113 upstream Envoy Docker image, where `${NOMAD_envoy_version}` is resolved automatically 114 by a query to Consul. 115 - `log_level` - `(string: "info")` - Envoy sidecar log level. "`debug`" is useful for 116 debugging Connect related issues. 117 - `proxy_concurrency` - `(string: "1")` - The number of [worker threads][worker_threads] the Envoy 118 sidecar will run. 119 120 Custom images can make use of Consul's preferred Envoy version by making use of 121 Nomad's version interpolation, e.g. 122 123 ```hcl 124 meta.connect.sidecar_image = custom/envoy-${NOMAD_envoy_version}:latest 125 ``` 126 127 ## `sidecar_task` Parameters 128 129 - `name` `(string: "connect-[proxy|gateway]-<service>")` - Name of the task. Defaults to 130 including the name of the service the proxy or gateway is providing. 131 132 - `driver` `(string: "docker")` - Driver used for the sidecar task. 133 134 - `user` `(string: nil)` - Determines which user is used to run the task, defaults 135 to the same user the Nomad client is being run as. 136 137 - `config` `(map: nil)` - Configuration provided to the driver for initialization. 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