更新时间:2024-12-25 GMT+08:00
灰度升级配置demo
本文以灰度升级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 #升级服务,将灰度流量设置为50% 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阶段(切占全网10%的流量到灰度节点),业务观察情况:10%的灰度流量引入灰度节点(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阶段(切占全网20%的流量到灰度节点),业务观察情况:20%的灰度流量引入灰度节点(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
父主题: SLB