共用方式為


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 字串清單。
部署的批次大小上限。

preDeploypreDeployHook
Canary 部署策略的預先部署勾點。

deploydeployHook
部署 Canary 部署策略的攔截。

routeTrafficrouteTrafficHook
路由傳送 Canary 部署策略的流量攔截。

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

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

備註

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

Canary 部署策略支援 preDeploy 生命週期勾點 (執行一次) ,並使用 、 routeTrafficpostRouteTraffic 生命週期勾點逐一查看 deploy 。 然後,它會以 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... 

另請參閱