j9九游会登录/ 应用平台 appstage/ / / / / 灰度升级配置demo
更新时间:2025-04-23 gmt 08:00

灰度升级配置demo-j9九游会登录

本文以灰度升级demo为例,介绍如何开发iac代码。

容器部署

iac主体描述文件meta.yaml:
type: wisecloud::environment
applypipeline: cn_product_cbu
pipelines:
  - name: gray_other_service_cn_product_cbu
    action: serial
    tasks:
      - name: gray_other_service_upgrade
        action: parallel
        tasks:
          - name: gray_slblogcollector_upgrade
            action: serial
            tasks:
              - name: slblogcollector_all_traffic_to_product_nodes    #启动灰度,灰度状态设置为阶段1,运行中
                action: apply
                component:
                  name: wisecloudgraylogcollectorservice
                  resources:
                    - type: "wisecloud::loadbalancer::grayconfig"
                      name: "logcollector"
                      properties:
                        currentstage: 1            #当前灰度阶段
                        currentstatus: processing  #当前状态,运行中
# 执行runtime灰度部署:4(生产) 0(灰度) -> 2(生产) 2(灰度),业务观察情况:pod正常,全网流量都引入生产节点(2个),灰度节点(2个)上没有流量              
- name: gray_slblogcollector_runtime_upgrade       #升级服务,将灰度流量设置为10%
                action: apply
                component:
                  name: wisecloudgraylogcollectorservice
                  resources:
                    - type: "wisecloud::microservice::nuwacontainer"
                      name: "wisecloudgraylogcollectorservice_runtime_tur"
                      properties:
                        graystage:
                          grayinstances: 50        #灰度升级的实例数比例,范围为1~100
                          grayprocess: "ingray"    #灰度状态,灰度处理中
                          graystatus: 2            #微服务平台实例管理页面pod的灰度状态,1:生产;2:灰度
# 进入第2阶段(切占全网20%的流量到灰度节点),业务观察情况:20%的灰度流量引入灰度节点(2个),剩余流量还是引入生产节点(2个)
              - name: slblogcollector_gray_traffic_to_gray_nodes    #将灰度状态设置阶段2,运行中
                action: apply
                component:
                  name: wisecloudgraylogcollectorservice
                  resources:
                    - type: "wisecloud::loadbalancer::grayconfig"
                      name: "logcollector"
                      properties:
                        currentstage: 2            #当前灰度阶段
                        currentstatus: processing  #当前状态,运行中
           
  - name: full_other_service_cn_product_cbu
    action: serial
    tasks:
      - name: full_other_service_upgrade
        action: parallel
        tasks:
          - name: full_slblogcollector_upgrade
            action: serial
            tasks:
# 先修改灰度阶段,进入第3阶段(切占全网70%的流量到灰度节点),业务观察情况:70%的灰度流量引入灰度节点(2个),剩余流量还是引入生产节点(2个)
              - name: full_slblogcollector_upgrade_stage1        #灰度状态设置为阶段3,运行中
                action: serial
                tasks:
                  - name: slblogcollector_all_traffic_to_gray_nodes
                    action: apply
                    component:
                      name: wisecloudgraylogcollectorservice
                      resources:
                        - type: "wisecloud::loadbalancer::grayconfig"
                          name: "logcollector"
                          properties:
                            currentstage: 3                     #当前灰度阶段
                            currentstatus: processing           #当前状态,运行中
#执行runtime灰度部署: 2(生产) 2(灰度) -> 0(生产) 4(灰度)
                  - name: full_slblogcollector_runtime_upgrade  #升级服务
                    action: apply
                    component:
                      name: wisecloudgraylogcollectorservice
                      resources:
                        - type: "wisecloud::microservice::nuwacontainer"
                          name: "wisecloudgraylogcollectorservice_runtime_tur"
                          properties:
                            graystage:
                              grayinstances: 100                #灰度升级的实例数比例,范围为1~100
                              grayprocess: "ingray"             #灰度状态,灰度处理中
                              graystatus: 2                     #灰度实例对接slb时的状态,1:生产,2:灰度
#修改灰度阶段:灰度比例100%,业务观察情况:所有流量随机分配到4个节点
              - name: full_slblogcollector_upgrade_stage2
                action: serial
                tasks:
                  - name: slblogcollector_complate_gray_release #灰度状态设置为阶段3,已完成
                    action: apply
                    component:
                      name: wisecloudgraylogcollectorservice
                      resources:
                        - type: "wisecloud::loadbalancer::grayconfig"
                          name: "logcollector"
                          properties:
                            currentstage: 3                    #当前灰度阶段
                            currentstatus: complete            #当前状态,已完成
#修改灰度阶段,完成灰度发布
                  - name: slblogcollector_runtime_switch_to_product #升级服务
                    action: apply
                    component:
                      name: wisecloudgraylogcollectorservice
                      resources:
                        - type: "wisecloud::microservice::nuwacontainer"
                          name: "wisecloudgraylogcollectorservice_runtime_tur"
                          properties:
                            graystage:
                              grayinstances: 100            #灰度升级的实例数比例,范围为1~100
                              grayprocess: "finished"       #灰度状态,灰度处理完成
                              graystatus: 2                 #灰度实例对接slb时的状态,1:生产,2:灰度

资源列表resources.yaml:

- name: wisecloudgraylogcollectorservice_runtime_tur
  type: wisecloud::microservice::nuwacontainer
  metadata:
    annotations: {}
  properties:
    bindslb:                    #引用config/values.yaml文件中的bindslb配置,用于绑定slb
      $ref: 'config/values.yaml#/values/bindslb'
    configs:
      private:
        schema:
          $ref: config/config_schema.yaml#
        records:
          $ref: config/config_records.yaml#
    sidecars:
      - param: '{}'
        requestsflavor: 0.1c500m
        name: rasp
        limitsflavor: 0.3c500m
        version: 2.2.1.102
      - param:
          $ref: config/aiopslog_sidecar_param.json
        requestsflavor: 0.1c1g
        name: aiopslog
        limitsflavor: 0.5c1g
        version: 3.9.0.200
    terminationgraceperiodseconds: 30  #优雅退出宽限时间,此时间为整个pod的最大退出时间,设置为30秒
    microservicename: wisecloudgraylogcollectorservice
    replicas: 4                       #单az主机数量,<=100
    clustername: runtime_tur
    volumes:                         #引用config/values.yaml文件中的volumes配置
      $ref: 'config/values.yaml#/values/volumes'
    resourcetag:                     #指定集群部署的分组,此处配置的信息要在管理台提前预置好
      group: cce-turbo
    containers:                      #微服务基于容器化的部署
      - flavor: 2c8gi
        image: >-                    #镜像地址
          swr.cn-north-2.myhuaweicloud.com/appstage-trustservices/slb-log-collector:log_collector_version
        livenessprobe:
          $ref: 'config/common_config.yaml#/config/livenessprobe'
          httpget:
            path: /health
            scheme: http
            port: 18088
        envs:
          - name: java_opts
            value: '-dfastjson.parser.safemode=true'
        readinessprobe:
          $ref: 'config/common_config.yaml#/config/readinessprobe'
          exec:
            command:
              - sh
              - /opt/huawei/app/bin/status.sh
              - '18088'
        stsenable: true
        hostaliases:
          $ref: config/hosts.yaml#
        ports:
          - 18088
        prestopconfig:
          execcommand:
            $ref: 'config/common_config.yaml#/config/execcommand'
    network:
      slbenable: true            #启用slb
      slbcloudmapconfigs: []
#实例logcollector需要在slb管理台创建,并且名称一致,灰度阶段流量设置请根据实际情况进行调整
- name: logcollector
  type: wisecloud::loadbalancer::grayconfig
  properties:
    ruletype: slb
    currentstage: 2
    currentstatus: complete
    stages:
      - stageindex: 1            #阶段编号1
        rules:                   #灰度规则列表
            - values: percent[0]
              variable: advance
        greyrulerelation: or    #设置当前阶段下多个分流配置子项之间的关系为或
      - stageindex: 2           #阶段编号2
        rules:
          - values: percent[10]
            variable: advance
        greyrulerelation: or    #设置当前阶段下多个分流配置子项之间的关系为或
      - stageindex: 3           #阶段编号3
        rules:                  #灰度规则列表
          - values: percent[20]
            variable: advance
        greyrulerelation: or   #设置当前阶段下多个分流配置子项之间的关系为或
      - stageindex: 4          #阶段编号4
        rules:                 #灰度规则列表
          - values: percent[100]
            variable: advance
        greyrulerelation: or  #设置当前阶段下多个分流配置子项之间的关系为或

公共资源参数值values.yaml:

在resources.yaml中通过$ref的方式来引用。
values:
  volumes:
    - size: 100gi
      name: log_volume
    - size: 5gi
      name: data_volume
  bindslb:
    - targetgroup:
        name: ngx-log-collector-runtime
      port: 18088
      graystatus: 1
      weight: 1
      listenergroupname: wgp_slb
      maxfails: 3
      timeout: 2

虚机部署

meta.yaml:

type: wisecloud::environment
applypipeline: cn_product_cbu
pipelines:
  - name: gray_dispatch_cn_product_cbu
    action: serial
    tasks:
      - name: dispatch_upgrade_gray
        action: parallel
        tasks:
          - name: dispatch_upgrade_gray
            action: serial
            tasks:
              - name: offine_dispatch_gray_az1
                action: apply
                component:
                  name: wisecloudgrayopenservice
                  resources:
                    - type: "wisecloud::eap::workflow"
                      name: "dispatch_offline_gray_server" #执行action任务,实现灰度节点下线
              - name: upgrade_dispatch_gray_az1
                action: apply
                component:
                  name: wisecloudgrayopenservice
                  resources:
                    - type: "wisecloud::eap::workflow"    #灰度节点升级服务
                      name: "dispatch_gray"
              - name: switch_to_gray_stage1
                action: apply
                confirm:
                  message: 确认dispatch是否切到一阶段
                  users:
                    - l30035828
                component:
                  name: wisecloudgrayopenservice
                  resources:
                    - type: "wisecloud::eap::workflow"  #在action任务管理创建action任务:执行action任务将灰度节点上线,并且将灰度规则切换为阶段1
                      name: "dispatch_switch_to_gray_stage1"
  - action: serial
    name: full_upgrade_cn_product_cbu
    tasks:
      - action: parallel
        name: switch_to_full_release
        confirm:
          message: 确认执行switch_to_full_release
          users:
            - l30035828
        tasks:
          - action: serial
            name: dispatch_full_release
            tasks:
              - name: switch_dispatch_full_and_offline
                action: apply
                component:
                  name: wisecloudgrayopenservice
                  resources:
                    - type: "wisecloud::eap::workflow" #功能验证完成后执行:在action任务管理创建action任务,实现生产节点下线,并且灰度规则完成发布
                      name: dispatch_switch_to_full_release_stage
      - action: parallel
        name: upgrade_product_server
        confirm:
          message: 确认执行upgrade_product_server
          users:
            - l30035828
        tasks:
          - action: serial
            name: dispatch_upgrade_product
            tasks:
              - action: apply
                name: dispatch_upgrade_product
                component:
                  name: wisecloudgrayopenservice    #生产节点升级服务
                  resources:
                    - type: "wisecloud::eap::workflow"
                      name: dispatch_product
      - action: parallel
        name: confirm_online_product_server
        confirm:
          message: 确认执行online_product_server
          users:
            - l30035828
        tasks:
          - action: serial
            name: online_product_dispatch
            tasks:
              - action: apply
                name: online_product_dispatch
                component:
                  name: wisecloudgrayopenservice   #在action任务管理创建action任务,实现生产节点上线
                  resources:
                    - type: "wisecloud::eap::workflow"
                      name: dispatch_online_product_server

resources.yaml:

#灰度
- name: dispatch_gray
  type: wisecloud::eap::workflow
  properties:
    workflowname: iac
    params:
      instance: microservice/cn/trustservices/cn_product_cbu/wisecloudgrayservice/cn_product_cbu/wisecloudgrayopenservice/cn_product_cbu
      group: gray
      version: dispatch_version
      variables: {}
#生产
- name: dispatch_product
  type: wisecloud::eap::workflow
  properties:
    workflowname: iac
    params:
      instance: microservice/cn/trustservices/cn_product_cbu/wisecloudgrayservice/cn_product_cbu/wisecloudgrayopenservice/cn_product_cbu
      group: product
      version: dispatch_version
      variables: {}
- name: dispatch_offline_gray_server
  type: wisecloud::eap::workflow
  properties:
    workflowname: graystagechange
    params:
      actionname: dispatch_offine_gray_server_cbu
- name: dispatch_switch_to_gray_stage1
  type: wisecloud::eap::workflow
  properties:
    workflowname: graystagechange
    params:
      actionname: dispatch_switch_to_gray_stage1_cbu
- name: dispatch_switch_to_full_release_stage
  type: wisecloud::eap::workflow
  properties:
    workflowname: graystagechange
    params:
      actionname: dispatch_switch_to_full_release_stage_cbu
- name: dispatch_online_product_server
  type: wisecloud::eap::workflow
  properties:
    workflowname: graystagechange
    params:
      actionname: dispatch_online_produce_server_cbu

相关文档

网站地图