github.com/hhrutter/nomad@v0.6.0-rc2.0.20170723054333-80c4b03f0705/website/source/docs/job-specification/update.html.md (about)

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