共用方式為


jobs.deployment.strategy.canary 定義

Canary 部署策略會推出對一小部分伺服器所做的變更。

canary:
  increments: [ string ] # Maximum batch size for deployment.
  preDeploy: # Pre deploy hook for canary deployment strategy.
    steps: [ task | script | powershell | pwsh | bash | checkout | download | downloadBuild | getPackage | publish | template | reviewApp ] # A list of steps to run.
    pool: string | pool # Pool where pre deploy steps will run.
  deploy: # Deploy hook for canary deployment strategy.
    steps: [ task | script | powershell | pwsh | bash | checkout | download | downloadBuild | getPackage | publish | template | reviewApp ] # A list of steps to run.
    pool: string | pool # Pool where deploy steps will run.
  routeTraffic: # Route traffic hook for canary deployment strategy.
    steps: [ task | script | powershell | pwsh | bash | checkout | download | downloadBuild | getPackage | publish | template | reviewApp ] # A list of steps to run.
    pool: string | pool # Pool where route traffic steps will run.
  postRouteTraffic: # Post route traffic hook for canary deployment strategy.
    steps: [ task | script | powershell | pwsh | bash | checkout | download | downloadBuild | getPackage | publish | template | reviewApp ] # A list of steps to run.
    pool: string | pool # Pool where post route traffic steps will run.
  on: # On success or failure hook for canary deployment strategy.
    failure: # Runs on failure of any step.
      steps: [ task | script | powershell | pwsh | bash | checkout | download | downloadBuild | getPackage | publish | template | reviewApp ] # A list of steps to run.
      pool: string | pool # Pool where post on failure steps will run.
    success: # Runs on success of all of the steps.
      steps: [ task | script | powershell | pwsh | bash | checkout | download | downloadBuild | getPackage | publish | template | reviewApp ] # A list of steps to run.
      pool: string | pool # Pool where on success steps will run.

參考此定義的定義:jobs.deployment.strategy

性能

increments 字串清單。
部署的批次大小上限。

preDeploy preDeployHook
Canary 部署策略的預先部署攔截。

deploy deployHook
Canary 部署策略的部署攔截。

routeTraffic routeTrafficHook
Canary 部署策略的路由流量攔截。

postRouteTraffic postRouteTrafficHook
針對 Canary 部署策略張貼路由流量攔截。

on onSuccessOrFailureHook
Canary 部署策略的成功或失敗勾點。

備註

Canary 部署策略是進階部署策略,可協助降低推出新版本應用程式所涉及的風險。 藉由使用此策略,您可以先對一小部分的伺服器推出變更。 隨著您對新版本的信心增加,便能發行到基礎結構中的更多伺服器,然後將更多流量路由到該版本。

Canary 部署策略支援 preDeploy 生命週期攔截(執行一次),並使用 deployrouteTrafficpostRouteTraffic 生命周期攔截進行反覆運算。 然後,它會以 successfailure 攔截結束。

此策略提供下列變數:

strategy.name:策略的名稱。 例如,Canary。
strategy.action:在 Kubernetes 叢集上執行的動作。 例如,部署、升級或拒絕。
strategy.increment:目前互動中使用的遞增值。 此變數僅適用於 deployrouteTrafficpostRouteTraffic 生命周期攔截。

生命週期勾點的描述

preDeploy:用來執行在應用程式部署開始前初始化資源的步驟。

deploy:用來執行部署應用程式的步驟。 下載成品工作只會在部署作業的 deploy 攔截中自動插入。 若要停止下載成品,請使用 - download: none,或指定 下載管線成品工作來下載特定成品。

routeTraffic:用來執行提供流量至更新版本的步驟。

postRouteTraffic:用來在路由傳送流量之後執行步驟。 一般而言,這些工作會監視已定義間隔更新版本的健康情況。

on: failureon: success:用來執行復原動作或清除的步驟。

範例

在下列範例中,AKS 的 Canary 策略會先部署具有 10% Pod 的變更,後面接著 20%,同時在 postRouteTraffic期間監視健康情況。 如果一切順利,它將升至100%。

jobs: 
- deployment: 
  environment: smarthotel-dev.bookings
  pool: 
    name: smarthotel-devPool
  strategy:                  
    canary:      
      increments: [10,20]  
      preDeploy:                                     
        steps:           
        - script: initialize, cleanup....   
      deploy:             
        steps: 
        - script: echo deploy updates... 
        - task: KubernetesManifest@0 
          inputs: 
            action: $(strategy.action)       
            namespace: 'default' 
            strategy: $(strategy.name) 
            percentage: $(strategy.increment) 
            manifests: 'manifest.yml' 
      postRouteTraffic: 
        pool: server 
        steps:           
        - script: echo monitor application health...   
      on: 
        failure: 
          steps: 
          - script: echo clean-up, rollback...   
        success: 
          steps: 
          - script: echo checks passed, notify... 

另請參閱