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
预部署挂钩,用于金丝雀部署策略。

deploydeployHook
为金丝雀部署策略部署挂钩。

routeTrafficrouteTrafficHook
用于金丝雀部署策略的路由流量挂钩。

postRouteTrafficpostRouteTrafficHook
针对金丝雀部署策略的后路由流量挂钩。

ononSuccessOrFailureHook
金丝雀部署策略的成功或失败挂钩。

备注

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... 

请参阅