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

     1  ---
     2  layout: docs
     3  page_title: update Stanza - Job Specification
     4  sidebar_title: update
     5  description: |-
     6    The "update" stanza specifies the group's update strategy. The update strategy
     7    is used to control things like rolling upgrades and canary deployments. If
     8    omitted, rolling updates and canaries are disabled.
     9  ---
    10  
    11  # `update` Stanza
    12  
    13  <Placement
    14    groups={[
    15      ['job', 'update'],
    16      ['job', 'group', 'update']
    17    ]}
    18  />
    19  
    20  The `update` stanza specifies the group's update strategy. The update strategy
    21  is used to control things like [rolling upgrades][rolling] and [canary
    22  deployments][canary]. If omitted, rolling updates and canaries are disabled. If
    23  specified at the job level, the configuration will apply to all groups within
    24  the job. If multiple `update` stanzas are specified, they are merged with the
    25  group stanza taking the highest precedence and then the job.
    26  
    27  ```hcl
    28  job "docs" {
    29    update {
    30      max_parallel      = 3
    31      health_check      = "checks"
    32      min_healthy_time  = "10s"
    33      healthy_deadline  = "5m"
    34      progress_deadline = "10m"
    35      auto_revert       = true
    36      auto_promote      = true
    37      canary            = 1
    38      stagger           = "30s"
    39    }
    40  }
    41  ```
    42  
    43  ~> For `system` jobs, only [`max_parallel`](#max_parallel) and
    44  [`stagger`](#stagger) are enforced. The job is updated at a rate of
    45  `max_parallel`, waiting `stagger` duration before the next set of updates.
    46  The `system` scheduler will be updated to support the new `update` stanza in
    47  a future release.
    48  
    49  ## `update` Parameters
    50  
    51  - `max_parallel` `(int: 1)` - Specifies the number of allocations within a task group that can be
    52    updated at the same time. The task groups themselves are updated in parallel.
    53  
    54    - `max_parallel = 0` - Specifies that the allocation should use forced updates instead of deployments
    55  
    56  - `health_check` `(string: "checks")` - Specifies the mechanism in which
    57    allocations health is determined. The potential values are:
    58  
    59    - "checks" - Specifies that the allocation should be considered healthy when
    60      all of its tasks are running and their associated [checks][] are healthy,
    61      and unhealthy if any of the tasks fail or not all checks become healthy.
    62      This is a superset of "task_states" mode.
    63  
    64    - "task_states" - Specifies that the allocation should be considered healthy when
    65      all its tasks are running and unhealthy if tasks fail.
    66  
    67    - "manual" - Specifies that Nomad should not automatically determine health
    68      and that the operator will specify allocation health using the [HTTP
    69      API](/api-docs/deployments#set-allocation-health-in-deployment).
    70  
    71  - `min_healthy_time` `(string: "10s")` - Specifies the minimum time the
    72    allocation must be in the healthy state before it is marked as healthy and
    73    unblocks further allocations from being updated. This is specified using a
    74    label suffix like "30s" or "15m".
    75  
    76  - `healthy_deadline` `(string: "5m")` - Specifies the deadline in which the
    77    allocation must be marked as healthy after which the allocation is
    78    automatically transitioned to unhealthy. This is specified using a label
    79    suffix like "2m" or "1h".
    80  
    81  - `progress_deadline` `(string: "10m")` - Specifies the deadline in which an
    82    allocation must be marked as healthy. The deadline begins when the first
    83    allocation for the deployment is created and is reset whenever an allocation
    84    as part of the deployment transitions to a healthy state. If no allocation
    85    transitions to the healthy state before the progress deadline, the deployment
    86    is marked as failed. If the `progress_deadline` is set to `0`, the first
    87    allocation to be marked as unhealthy causes the deployment to fail. This is
    88    specified using a label suffix like "2m" or "1h".
    89  
    90  - `auto_revert` `(bool: false)` - Specifies if the job should auto-revert to the
    91    last stable job on deployment failure. A job is marked as stable if all the
    92    allocations as part of its deployment were marked healthy.
    93  
    94  - `auto_promote` `(bool: false)` - Specifies if the job should auto-promote to the
    95    canary version when all canaries become healthy during a deployment. Defaults to
    96    false which means canaries must be manually updated with the `nomad deployment promote`
    97    command.
    98  
    99  - `canary` `(int: 0)` - Specifies that changes to the job that would result in
   100    destructive updates should create the specified number of canaries without
   101    stopping any previous allocations. Once the operator determines the canaries
   102    are healthy, they can be promoted which unblocks a rolling update of the
   103    remaining allocations at a rate of `max_parallel`.
   104  
   105  - `stagger` `(string: "30s")` - Specifies the delay between each set of
   106    [`max_parallel`](#max_parallel) updates when updating system jobs. This
   107    setting no longer applies to service jobs which use
   108    [deployments.][strategies]
   109  
   110  ## `update` Examples
   111  
   112  The following examples only show the `update` stanzas. Remember that the
   113  `update` stanza is only valid in the placements listed above.
   114  
   115  ### Parallel Upgrades Based on Checks
   116  
   117  This example performs 3 upgrades at a time and requires the allocations be
   118  healthy for a minimum of 30 seconds before continuing the rolling upgrade. Each
   119  allocation is given at most 2 minutes to determine its health before it is
   120  automatically marked unhealthy and the deployment is failed.
   121  
   122  ```hcl
   123  update {
   124    max_parallel     = 3
   125    min_healthy_time = "30s"
   126    healthy_deadline = "2m"
   127  }
   128  ```
   129  
   130  ### Parallel Upgrades Based on Task State
   131  
   132  This example is the same as the last but only requires the tasks to be healthy
   133  and does not require registered service checks to be healthy.
   134  
   135  ```hcl
   136  update {
   137    max_parallel     = 3
   138    min_healthy_time = "30s"
   139    healthy_deadline = "2m"
   140    health_check     = "task_states"
   141  }
   142  ```
   143  
   144  ### Canary Upgrades
   145  
   146  This example creates a canary allocation when the job is updated. The canary is
   147  created without stopping any previous allocations from the job and allows
   148  operators to determine if the new version of the job should be rolled out.
   149  
   150  ```hcl
   151  update {
   152    canary       = 1
   153    max_parallel = 3
   154  }
   155  ```
   156  
   157  Once the operator has determined the new job should be deployed, the deployment
   158  can be promoted and a rolling update will occur performing 3 updates at a time
   159  until the remainder of the groups allocations have been rolled to the new
   160  version.
   161  
   162  ```text
   163  # Promote the canaries for the job.
   164  $ nomad job promote <job-id>
   165  ```
   166  
   167  ### Blue/Green Upgrades
   168  
   169  By setting the canary count equal to that of the task group, blue/green
   170  deployments can be achieved. When a new version of the job is submitted, instead
   171  of doing a rolling upgrade of the existing allocations, the new version of the
   172  group is deployed along side the existing set. While this duplicates the
   173  resources required during the upgrade process, it allows very safe deployments
   174  as the original version of the group is untouched.
   175  
   176  ```hcl
   177  group "api-server" {
   178      count = 3
   179  
   180      update {
   181        canary       = 3
   182        max_parallel = 3
   183      }
   184      ...
   185  }
   186  ```
   187  
   188  Once the operator is satisfied that the new version of the group is stable, the
   189  group can be promoted which will result in all allocations for the old versions
   190  of the group to be shutdown. This completes the upgrade from blue to green, or
   191  old to new version.
   192  
   193  ```text
   194  # Promote the canaries for the job.
   195  $ nomad job promote <job-id>
   196  ```
   197  
   198  ### Serial Upgrades
   199  
   200  This example uses a serial upgrade strategy, meaning exactly one task group will
   201  be updated at a time. The allocation must be healthy for the default
   202  `min_healthy_time` of 10 seconds.
   203  
   204  ```hcl
   205  update {
   206    max_parallel = 1
   207  }
   208  ```
   209  
   210  ### Update Stanza Inheritance
   211  
   212  This example shows how inheritance can simplify the job when there are multiple
   213  task groups.
   214  
   215  ```hcl
   216  job "example" {
   217    ...
   218  
   219    update {
   220      max_parallel     = 2
   221      health_check     = "task_states"
   222      healthy_deadline = "10m"
   223    }
   224  
   225    group "one" {
   226      ...
   227  
   228      update {
   229        canary = 1
   230      }
   231    }
   232  
   233    group "two" {
   234      ...
   235  
   236      update {
   237        min_healthy_time = "3m"
   238      }
   239    }
   240  }
   241  ```
   242  
   243  By placing the shared parameters in the job's update stanza, each groups update
   244  stanza may be kept to a minimum. The merged update stanzas for each group
   245  becomes:
   246  
   247  ```hcl
   248  group "one" {
   249    update {
   250      canary           = 1
   251      max_parallel     = 2
   252      health_check     = "task_states"
   253      healthy_deadline = "10m"
   254    }
   255  }
   256  
   257  group "two" {
   258    update {
   259      min_healthy_time = "3m"
   260      max_parallel     = 2
   261      health_check     = "task_states"
   262      healthy_deadline = "10m"
   263    }
   264  }
   265  ```
   266  
   267  [canary]: https://learn.hashicorp.com/nomad/update-strategies/blue-green-and-canary-deployments 'Nomad Canary Deployments'
   268  [checks]: /docs/job-specification/service#check-parameters 'Nomad check Job Specification'
   269  [rolling]: https://learn.hashicorp.com/nomad/update-strategies/rolling-upgrades 'Nomad Rolling Upgrades'
   270  [strategies]: https://learn.hashicorp.com/nomad/update-strategies 'Nomad Update Strategies'