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

另请参阅