
# Spring Cloud应用无损上线
#### 概述
在组件运维过程中，不可避免要进行升级、重启、扩容等操作，在这些操作中，无损上线是常见的要求，本文介绍如何配置Spring Cloud无损上线。
#### 约束与限制
当前不支持"源码仓库"和"软件包"功能，推荐使用[CAE对接GitHub Actions实现自动CICD部署](https://support.huaweicloud.com/bestpractice-cae/cae_05_0064.html)。
#### 前提条件
- 已[创建环境](https://support.huaweicloud.com/usermanual-cae/cae_03_0003.html#section0)。
- 已[创建应用](https://support.huaweicloud.com/usermanual-cae/cae_03_0002.html#section0)。
- 已[创建并部署组件](https://support.huaweicloud.com/usermanual-cae/cae_03_0005.html)，确保您的组件为Spring Cloud。
 
#### 操作步骤
1. Spring Cloud启用spring-boot-starter-actuator。 
   1. 在组件对应的源码的pom.xml中添加spring-boot-starter-actuator依赖（建议使用2.3.0及以上版本）。
      ```
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-actuator</artifactId>
          <version>{您使用的spring boot版本}</version>
      </dependency>
      ```
      
   
   2. 修改application.properties，添加如下配置：
      表1application.properties配置 
      | spring boot版本 | 配置                                                                                                                                                                                                   |
      |:---|:---|
      | 2.3.0/2.3.1   | management.health.probes.enabled=true                                                                                                                                                                |
      | \>= 2.3.2     | management.endpoint.health.probes.enabled=true management.health.livenessState.enabled=true management.health.readinessState.enabled=true |
         
      
   
   3. 更新代码。
      - 若您的组件使用源码部署，请将修改的源码更新至源码仓库。
      
      - 若您的组件使用软件包部署，请将新代码打包为软件包，并将新的软件包上传至软件包仓库。
       
   
   4. 使用新的源码或软件包，[升级组件](https://support.huaweicloud.com/usermanual-cae/cae_03_0033.html)。
   
   
   
   
2. 配置组件健康检查。 
   1. 登录CAE控制台。选择"组件配置"。
   
   2. 在"组件配置"页面上方的下拉框中选择待操作的组件。
   
   3. 参考[配置健康检查](https://support.huaweicloud.com/usermanual-cae/cae_03_0025.html)，配置就绪探针，具体参数如下：
      表2就绪探针参数 
      | 配置内容   | 值                                                                                                                                                                                                                                                   |
      |:---|:---|
      | 检查方式   | HTTP请求检查。                                                                                                                                                                                                                                           |
      | 端口     | 您的组件的实际监听端口。                                                                                                                                                                                                                                        |
      | 路径     | - spring boot 2.3及以上版本：/actuator/health/readiness。  - spring boot 2.3以下版本：/actuator/health。   |
      | 协议     | 您的组件的实际协议。                                                                                                                                                                                                                                          |
      | 检测周期   | 10                                                                                                                                                                                                                                                  |
      | 延迟时间   | 0                                                                                                                                                                                                                                                   |
      | 超时时间   | 1                                                                                                                                                                                                                                                   |
      | 成功阈值   | 1                                                                                                                                                                                                                                                   |
      | 最大失败次数 | 3                                                                                                                                                                                                                                                   |
         
      
   
   4. 升级组件，具体操作请参考[升级组件](https://support.huaweicloud.com/usermanual-cae/cae_03_0033.html)。
   
   
   
   
3. 验证配置。 
   1. 选择"组件列表"，若操作的组件状态为"运行中"，则进入下一步，否则配置失败。
   
   2. 选择"组件事件"，在页面上方的下拉框中选择操作的组件。若存在"组件实例健康"的事件，则配置成功，否则配置失败。
   
   
   ![](https://support.huaweicloud.com/bestpractice-cae/zh-cn_image_0000001686066924.png "点击放大")
   
   
 
