github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/website/content/docs/job-specification/multiregion.mdx (about) 1 --- 2 layout: docs 3 page_title: multiregion Stanza - Job Specification 4 sidebar_title: multiregion 5 description: |- 6 The "multiregion" stanza specifies that a job will be deployed to multiple federated 7 regions. 8 --- 9 10 # `multiregion` Stanza 11 12 <Placement groups={[['job', 'multiregion']]} /> 13 14 <EnterpriseAlert /> 15 16 The `multiregion` stanza specifies that a job will be deployed to multiple 17 [federated regions]. If omitted, the job will be deployed to a single region 18 — the one specified by the `region` field or the `-region` command line 19 flag to `nomad job run`. 20 21 Federated Nomad clusters are members of the same gossip cluster but not the 22 same raft cluster; they don't share their data stores. Each region in a 23 multiregion deployment gets an independent copy of the job, parameterized with 24 the values of the `region` stanza. Nomad regions coordinate to rollout each 25 region's deployment using rules determined by the `strategy` stanza. 26 27 ```hcl 28 job "docs" { 29 multiregion { 30 31 strategy { 32 max_parallel = 1 33 on_failure = "fail_all" 34 } 35 36 region "west" { 37 count = 2 38 datacenters = ["west-1"] 39 meta { 40 my-key = "my-value-west" 41 } 42 } 43 44 region "east" { 45 count = 5 46 datacenters = ["east-1", "east-2"] 47 meta { 48 my-key = "my-value-east" 49 } 50 } 51 } 52 } 53 ``` 54 55 ## Multiregion Deployment States 56 57 A single region deployment using one of the various [upgrade strategies] 58 begins in the `running` state, and ends in the `successful` state, the 59 `canceled` state (if another deployment supersedes it before it it's 60 complete), or the `failed` state. A failed single region deployment may 61 automatically revert to the previous version of the job if its `update` 62 stanza has the [`auto_revert`][update-auto-revert] setting. 63 64 In a multiregion deployment, regions begin in the `pending` state. This allows 65 Nomad to determine that all regions have accepted the job before 66 continuing. At this point up to `max_parallel` regions will enter `running` at 67 a time. When each region completes its local deployment, it enters a `blocked` 68 state where it waits until the last region has completed the deployment. The 69 final region will unblock the regions to mark them as `successful`. 70 71 ## `multiregion` Parameters 72 73 - `strategy` <code>([Strategy](#strategy-parameters): nil)</code> - Specifies 74 a rollout strategy for the regions. 75 76 - `region` <code>([Region](#region-parameters): nil)</code> - Specifies the 77 parameters for a specific region. This can be specified multiple times to 78 define the set of regions for the multiregion deployment. Regions are 79 ordered; depending on the rollout strategy Nomad may roll out to each region 80 in order or to several at a time. 81 82 ~> **Note:** Regions can be added, but regions that are removed will not be 83 stopped and will be ignored by the deployment. This behavior may change before 84 multiregion deployments are considered GA. 85 86 ### `strategy` Parameters 87 88 - `max_parallel` `(int: <optional>)` - Specifies the maximum number 89 of region deployments that a multiregion will have in a running state at a 90 time. By default, Nomad will deploy all regions simultaneously. 91 92 - `on_failure` `(string: <optional>)` - Specifies the behavior when a region 93 deployment fails. Available options are `"fail_all"`, `"fail_local"`, or 94 the default (empty `""`). This field and its interactions with the job's 95 [`update` stanza] is described in the [examples] below. 96 97 Each region within a multiregion deployment follows the `auto_revert` 98 strategy of its own `update` stanza (if any). The multiregion `on_failure` 99 field tells Nomad how many other regions should be marked as failed when one 100 region's deployment fails: 101 102 - The default behavior is that the failed region and all regions that come 103 after it in order are marked as failed. 104 105 - If `on_failure: "fail_all"` is set, all regions will be marked as 106 failed. If all regions have already completed their deployments, it's 107 possible that a region may transition from `blocked` to `successful` while 108 another region is failing. This successful region cannot be rolled back. 109 110 - If `on_failure: "fail_local"` is set, only the failed region will be marked 111 as failed. The remaining regions will move on to `blocked` status. At this 112 point, you'll need to manually unblock regions to mark them successful 113 with the [`nomad deployment unblock`] command or correct the conditions 114 that led to the failure and resubmit the job. 115 116 ~> For `system` jobs, only [`max_parallel`](#max_parallel) is enforced. The 117 `system` scheduler will be updated to support `on_failure` when the the 118 [`update` stanza] is fully supported for system jobs in a future release. 119 120 ### `region` Parameters 121 122 The name of a region must match the name of one of the [federated regions]. 123 124 - `count` `(int: <optional>)` - Specifies a count override for task groups in 125 the region. If a task group specifies a `count = 0`, its count will be 126 replaced with this value. If a task group specifies its own `count` or omits 127 the `count` field, this value will be ignored. This value must be 128 non-negative. 129 130 - `datacenters` `(array<string>: <optional>)` - A list of 131 datacenters in the region which are eligible for task placement. If not 132 provided, the `datacenters` field of the job will be used. 133 134 - `meta` - `Meta: nil` - The meta stanza allows for user-defined arbitrary 135 key-value pairs. The meta specified for each region will be merged with the 136 meta stanza at the job level. 137 138 As described above, the parameters for each region replace the default values 139 for the field with the same name for each region. 140 141 ## `multiregion` Examples 142 143 The following examples only show the `multiregion` stanza and the other 144 stanzas it might be interacting with. 145 146 ### Max Parallel 147 148 This example shows the use of `max_parallel`. This job will deploy first to 149 the "north" and "south" regions. If either "north" finishes and enters the 150 `blocked` state, then "east" will be next. At most 2 regions will be in a 151 `running` state at any given time. 152 153 ```hcl 154 multiregion { 155 156 strategy { 157 max_parallel = 2 158 } 159 160 region "north" {} 161 region "south" {} 162 region "east" {} 163 region "west" {} 164 } 165 ``` 166 167 ### Rollback Regions 168 169 This example shows the default value of `on_failure`. Because `max_parallel = 1`, 170 the "north" region will deploy first, followed by "south", and so on. But 171 supposing the "east" region failed, both the "east" region and the "west" 172 region would be marked `failed`. Because the job has an `update` stanza with 173 `auto_revert=true`, both regions would then rollback to the previous job 174 version. The "north" and "south" regions would remain `blocked` until an 175 operator intervenes. 176 177 ```hcl 178 multiregion { 179 180 strategy { 181 on_failure = "" 182 max_parallel = 1 183 } 184 185 region "north" {} 186 region "south" {} 187 region "east" {} 188 region "west" {} 189 } 190 191 update { 192 auto_revert = true 193 } 194 ``` 195 196 ### Override Counts 197 198 This example shows how the `count` field override the default `count` of the 199 task group. The job the deploys 2 "worker" and 1 "controller" allocations to 200 the "west" region, and 5 "worker" and 1 "controller" task groups to the "east" 201 region. 202 203 ```hcl 204 multiregion { 205 206 region "west" { 207 count = 2 208 } 209 210 region "east" { 211 count = 5 212 } 213 } 214 } 215 216 group "worker" { 217 count = 0 218 } 219 220 group "controller" { 221 count = 1 222 } 223 ``` 224 225 ### Merging Meta 226 227 This example shows how the `meta` is merged with the `meta` field of the job, 228 group, and task. A task in "west" will have the values 229 `first-key="regional-west"`, `second-key="group-level"`, whereas a task in 230 "east" will have the values `first-key="job-level"`, 231 `second-key="group-level"`. 232 233 ```hcl 234 multiregion { 235 236 region "west" { 237 meta { 238 first-key = "regional-west" 239 second-key = "regional-west" 240 } 241 } 242 243 region "east" { 244 meta { 245 second-key = "regional-east" 246 } 247 } 248 } 249 } 250 251 meta { 252 first-key = "job-level" 253 } 254 255 group "worker" { 256 meta { 257 second-key = "group-level" 258 } 259 } 260 ``` 261 262 [federated regions]: https://learn.hashicorp.com/tutorials/nomad/federation 263 [`update` stanza]: /docs/job-specification/update 264 [update-auto-revert]: /docs/job-specification/update#auto_revert 265 [examples]: #multiregion-examples 266 [upgrade strategies]: https://learn.hashicorp.com/collections/nomad/job-updates 267 [`nomad deployment unblock`]: /docs/commands/deployment/unblock