你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

将 Azure Spring Apps 基本或标准计划实例迁移到企业计划

注意

Azure Spring Apps 是 Azure Spring Cloud 服务的新名称。 虽然该服务有新名称,但一些地方仍会使用旧名称,我们仍在更新屏幕截图、视频和图形等资产。

本文适用于:✔️ 基本版/标准版 ✔️ 企业版

本文介绍如何将基本计划或标准计划中的现有应用程序迁移到企业计划。 从“基本”或“标准”计划迁移到企业计划时,VMware Tanzu 组件将替换开源软件(OSS)Spring Cloud 组件以提供更多功能支持。

本文使用 Pet Clinic 示例应用作为如何迁移的示例。

先决条件

  • Azure 订阅。 如果你没有订阅,请在开始之前创建一个免费帐户
  • Azure CLI 版本 2.45.0 或更高版本。
  • Azure Spring Apps 企业计划扩展。 使用以下命令删除以前的版本,并安装最新的企业计划扩展。 如果以前安装了 spring-cloud 扩展,请卸载它以避免配置和版本不匹配。
    az extension add --upgrade --name spring
    az extension remove --name spring-cloud
    
  • Git

预配服务实例

在 Azure Spring Apps Enterprise 计划中,VMware Tanzu 组件取代 OSS Spring Cloud 组件,以提供更多功能支持。 Tanzu 组件可根据你的需要按需启用。 在创建 Azure Spring Apps 服务实例之前,必须启用所需的组件。

注意

若要使用 Tanzu 组件,必须在预配 Azure Spring Apps 服务实例时启用它们。 目前无法在预配后启用它们。

使用以下步骤来预配 Azure Spring Apps 服务实例:

  1. 打开 Azure 门户

  2. 在顶部搜索框中,搜索“Azure Spring Apps”。

  3. 从结果中选择 Azure Spring Apps ,然后选择“ 创建”。

  4. “创建 Azure Spring Apps ”页上,设置 实例的订阅资源组名称

  5. 对于服务详细信息中的计划,请选择“更改”。

    Screenshot of the Azure portal Azure Spring Apps creation page with the Change button highlighted in the plan section.

  6. 在“ 选择计划 ”页上,选择表中的 “企业 ”行,然后选择“ 选择”。

    Screenshot of the Azure portal Azure Spring Apps creation page with Basics section and 'Choose your pricing tier' pane showing.

  7. 返回“创建 Azure Spring Apps”页,选择“条款”以同意Azure 市场中企业计划产品/服务的法律条款和隐私声明。

  8. 选择“ 下一步:VMware Tanzu 设置”。

  9. VMWare Tanzu 设置 选项卡上,滚动浏览列表以查看 Tanzu 组件。 默认情况下,所有组件都处于启用状态。

    Screenshot of the Azure portal Azure Spring Apps creation page with V M ware Tanzu Settings section showing.

    注意

    请仔细考虑要在预配阶段使用或启用哪些 Tanzu 组件。 预配 Azure Spring Apps 实例之后,无法启用或禁用 Tanzu 组件。

  10. 选择“Application Insights”选项卡,然后选择“启用 Application Insights”。 检查以下设置:

    • 应选择“启用 Application Insights ”。
    • 选择现有的 Application Insights 实例或创建新的 Application Insights 实例。
    • 在 0-100 范围内输入采样率,或使用默认值 10。

    你还可以在预配 Azure Spring Apps 实例后启用 Application Insights。 有关 Application Insights 定价的详细信息,请参阅 Azure Monitor 日志成本计算和选项Application Insights 计费部分。

    注意

    与 Azure Spring Apps 集成时,需要为 Application Insights 的使用付费。

  11. 选择“查看并创建”并等待验证完成,然后选择“创建”开始预配服务实例

完成资源预配大约需要 5 分钟。

创建和配置应用

应用创建步骤与标准计划相同。

  1. 使用以下命令设置 Azure CLI 默认值。 请务必将占位符替换为你自己的值。

    az config set defaults.group=<resource-group-name>
    az config set defaults.spring=<Azure-Spring-Apps-service-instance-name>
    
  2. 使用以下命令为 PetClinic 创建两个核心应用程序, api-gateway 以及 customers-service

    az spring app create --name api-gateway --instance-count 1 --memory 2Gi --assign-endpoint
    az spring app create --name customers-service --instance-count 1 --memory 2Gi
    

使用应用程序配置服务进行外部配置

对于分布式系统中的外部化配置,托管 Spring Cloud 配置服务器(OSS)仅在基本计划和标准计划中可用。 在企业计划中,Tanzu 的应用程序配置服务为应用提供类似的功能。 下表描述了 OSS 配置服务器与应用程序配置服务之间的使用情况差异。

组件 支持计划 Enabled 绑定到应用 配置文件
Spring Cloud 配置服务器 基本/标准 始终启用。 自动绑定 已在应用的源代码中配置。
Tanzu 的应用程序配置服务 企业 按需启用。 手动绑定 在 Azure Spring Apps 部署中作为 config-file-pattern 提供。

与 OSS 配置服务器中的客户端-服务器模式不同,应用程序配置服务使用 Kubernetes 原生 ConfigMap配置来管理配置,该配置从后端 Git 存储库中定义的属性填充。 应用程序配置服务无法获取在应用的源代码中配置的活动配置文件以匹配正确的配置,因此应在 Azure Spring Apps 部署级别指定显式配置 config-file-pattern

为 Tanzu 配置应用程序配置服务

按照以下步骤将 Tanzu 的应用程序配置服务用作集中式配置服务。

  1. 在 Azure Spring Apps Enterprise 实例中,选择 导航窗格中的应用程序配置服务 。 查看分配给 Tanzu 应用程序配置服务的正在运行状态和资源。

    Screenshot of the Azure portal showing the Overview tab of the Application Configuration Service page.

  2. 选择设置并完成存储库中的表单,以添加包含以下信息的新条目:

    • 名称:default
    • 模式:api-gateway,customers-service
    • URI:https://github.com/Azure-Samples/spring-petclinic-microservices-config
    • 标签:master

    Screenshot of the Azure portal showing the Settings tab of the Application Configuration Service page.

  3. 选择“验证”以验证对目标 URI 的访问。

  4. 验证成功完成后,选择“应用”以更新配置设置。

将应用程序绑定到 Tanzu 的应用程序配置服务

将 Tanzu 的应用程序配置服务与 Git 后端配合使用时,必须将应用绑定到 Tanzu 的应用程序配置服务。 绑定应用后,需要配置应用使用的模式。 使用以下步骤绑定和配置应用的模式。

使用以下步骤将应用绑定到 VMware Tanzu 的应用程序配置服务。

  1. 在 Azure Spring Apps Enterprise 实例中,选择 导航窗格中的应用程序配置服务

  2. 选择 “应用绑定 ”,然后选择“ 绑定应用”。

    Screenshot of the Azure portal showing the App binding tab of the Application Configuration Service page and the Bind app dropdown menu showing.

  3. 在下拉菜单中选择一个应用,然后选择“ 应用 ”将应用程序绑定到 Tanzu 的应用程序配置服务。

有关详细信息,请参阅使用 Tanzu 的应用程序配置服务

使用 Tanzu 服务注册表

服务注册表是专有 VMware Tanzu 组件之一。 它为应用提供了服务发现模式的实现,这是基于微服务的体系结构的关键概念之一。 在企业计划中,Tanzu 服务注册表提供服务注册表,并发现对应用的支持。 托管 Spring Cloud Eureka 仅在基本计划和标准计划中可用,在企业计划中不可用。

组件 标准计划 企业计划
服务注册表 OSS eureka
自动绑定(始终注入)
始终预配
Tanzu 的服务注册表
需要手动绑定到应用
按需启用

将应用程序绑定到 Tanzu 服务注册表

若要将应用绑定到 VMware Tanzu 的应用程序配置服务,请执行以下步骤。

  1. 在 Azure Spring Apps Enterprise 实例中,选择 “服务注册表”。

  2. 选择 “应用绑定”。 当前绑定的应用显示在应用名称

  3. 选择“ 绑定应用”。

  4. 在下拉菜单中选择一个应用,然后选择“ 应用 ”将应用程序绑定到 Tanzu 服务注册表。

    Screenshot of the Azure portal Azure Spring Apps with Service Registry page and 'Bind app' dialog showing.

注意

更改绑定/取消绑定状态时,必须重启或重新部署应用才能使更改生效。

有关详细信息,请参阅使用 Tanzu 服务注册表

生成和部署应用程序

在企业计划中,Tanzu 生成服务用于生成应用。 它提供了更多功能,例如从源代码和 zip 文件等项目部署的多语言应用。

若要使用 Tanzu Build Service,需要指定生成任务和生成器使用的资源。 还可以指定 --build-env 参数来设置生成环境。

如果应用与 Tanzu 的应用程序配置服务绑定,则需要指定额外的参数 —config-file-pattern

有关详细信息,请参阅 使用 Tanzu 生成服务

在本地生成应用程序

使用以下步骤在本地生成:

  1. 使用以下命令克隆 Azure 帐户中的示例应用存储库,更改目录并生成项目:

    git clone -b enterprise https://github.com/azure-samples/spring-petclinic-microservices
    cd spring-petclinic-microservices
    mvn clean package -DskipTests
    

    编译项目可能需要几分钟时间。 完成后,每个服务在其各自的文件夹中都有单独的 JAR 文件。

  2. 使用以下命令部署上一步中内置的 JAR 文件:

    az spring app deploy \
        --name api-gateway \
        --artifact-path spring-petclinic-api-gateway/target/spring-petclinic-api-gateway-2.3.6.jar \
        --config-file-patterns api-gateway
    az spring app deploy \
        --name customers-service \
        --artifact-path spring-petclinic-customers-service/target/spring-petclinic-customers-service-2.3.6.jar \
        --config-file-patterns customers-service
    
  3. 使用以下命令在部署后查询应用程序状态:

    az spring app list --output table
    

    此命令会生成类似于以下示例的输出:

    Name                  Location    ResourceGroup       Public Url                                                 Production Deployment    Provisioning State    CPU    Memory    Running Instance    Registered Instance    Persistent Storage    Bind Service Registry    Bind Application Configuration Service
    --------------------  ----------  ---------------  ---------------------------------------------------------  -----------------------  --------------------  -----  --------  ------------------  ---------------------  --------------------  -----------------------  ----------------------------------------
    api-gateway           eastus      <resource group>   https://<service_name>-api-gateway.asc-test.net                    default                  Succeeded             1      2Gi       1/1                1/1                    -                     True                     True
    customers-service     eastus      <resource group>                                                                      default                  Succeeded             1      2Gi       1/1                1/1                    -                     True                     True
    

使用 Application Insights

Azure Spring Apps Enterprise 计划使用 buildpack 绑定将 Application Insights 与类型ApplicationInsights(而不是进程内代理)集成。 有关详细信息,请参阅如何配置 APM 集成和 CA 证书

下表列出了可用的计划 APM 提供程序。

标准计划 企业计划
Application insight
New Relic
Dynatrace
AppDynamics
Application insight
New Relic
Dynatrace
AppDynamics
ElasticAPM

若要检查或更新 Application Insights 中的当前设置,请使用以下步骤:

  1. 在 Azure Spring Apps Enterprise 实例中,选择 Application Insights

  2. 通过选择“编辑绑定”或取消绑定”启用或禁用 Application Insights。

    Screenshot of the Azure portal Application Insights page with the Edit binding option dropdown menu showing.

  3. 选择“ 编辑绑定”。 编辑绑定设置,然后选择“ 保存”。

    Screenshot of the Azure portal 'Edit binding' pane.

后续步骤