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

将 Spring Cloud Config Server 从 Azure Spring Apps 迁移到 Azure 容器应用

注意

基本、标准和企业计划将从 2025 年 3 月中旬开始弃用,停用期为 3 年。 建议转换到 Azure 容器应用。 有关详细信息,请参阅 Azure Spring Apps 停用公告

标准消耗和专用计划将于 2024 年 9 月 30 日开始弃用,并在六个月后完全关闭。 建议转换到 Azure 容器应用。 有关详细信息,请参阅将 Azure Spring Apps 标准消耗和专用计划迁移到 Azure 容器应用

本文适用于:✅基本计划/标准计划 ✅ 企业计划

本文介绍如何将 Spring Cloud Config Server 迁移到 Azure 容器应用中的 Config Server for Spring。 Azure 容器应用管理 Config Server for Spring,其功能与 Azure Spring Apps 中的 Spring Cloud Config Server 类似。

先决条件

  • 启用了配置服务器的 Azure Spring Apps 实例。
  • 用于 Config Server 的 Azure 容器应用环境和 Azure 容器应用实例。

预配 Config Server

以下步骤演示如何在 Azure 容器应用中预配 Config Server for Spring:

  1. 在 Azure 门户中导航到 Azure 容器应用环境。

  2. 在菜单中,选择“服务”>“服务”。

  3. 打开“配置”下拉列表,然后选择“Java 组件”。

  4. 在“配置 Java 组件”面板中,输入以下值:

    属性 Value
    Java 组件类型 选择“Config Server for Spring”
    Java 组件名称 输入“configserver”
  5. 在“Git 存储库”部分中,选择“添加”,然后将值从应用程序配置服务迁移到此处,如下表所示。 选择一个存储库作为 Config Server for Spring 的默认存储库。

    属性
    类型 选择“DEFAULT”。
    URI 输入存储库的 URI 值。
    分支名称 输入存储库的标签值。
    搜索路径 输入存储库的搜索路径值。
    身份验证 选择存储库的身份验证类型并输入相应的信息。

    将其余字段保留为默认值,然后选择“添加”

  6. 如果有多个存储库,请选择“添加”以迁移其他存储库。 对于“类型”,选择“其他”,然后迁移其他属性,如下一步和下表所示:

    属性
    类型 选择“DEFAULT”。
    模式 {application}{application}/{profile} 格式输入存储库的“模式”值。
  7. 在“绑定”部分中,打开下拉列表以选择要绑定到 Config Server for Spring 的应用。

  8. 选择下一步

  9. 若要设置 Config Server,请在“查看”选项卡上,选择“配置”,然后按照配置部分中的说明进行操作。

成功创建后,可以看到 Config Server for Spring 的“预配状态”为“成功”

资源分配

Azure 容器应用中托管 Config Server 的容器资源分配固定为以下值:

  • CPU:0.5 vCPU
  • 内存:1 Gi

若要配置 Config Server for Spring 的实例计数,需要使用相同的值更新参数 --min-replicas--max-replicas。 此配置可确保实例计数保持固定。 目前,系统不支持动态缩放的自动缩放配置。

配置 Config Server

将 Azure Spring Apps 中 Spring Cloud 配置服务器中配置的默认 Git 存储库和附加存储库映射到 Azure 容器应用中部署的 Config Server for Spring 中的默认存储库和其他存储库。 下表显示了属性的映射关系:

Azure Spring Apps 中的属性名称 CONFIGURATION_KEY CONFIGURATION_VALUE
uri spring.cloud.config.server.git.uri
spring.cloud.config.server.git.repos.{repoName}.uri
远程存储库的 uri
search path spring.cloud.config.server.git.search-paths
spring.cloud.config.server.git.repos.{repoName}.search-paths
要在本地工作副本中使用的搜索路径。 默认情况下,仅搜索根目录。
label spring.cloud.config.server.git.default-label
spring.cloud.config.server.git.repos.{repoName}.default-label
用于 Git 的标签。
其他存储库中的 name 以下配置中的 {repoName}
其他存储库中的 Patterns spring.cloud.config.server.git.repos.{repoName}.pattern
username spring.cloud.config.server.git.username
spring.cloud.config.server.git.repos.{repoName}.username
如果身份验证类型为 HTTP Basic,则输入 username 以向远程存储库进行身份验证。
password spring.cloud.config.server.git.password
spring.cloud.config.server.git.repos.{repoName}.password
如果身份验证类型为 HTTP Basic,则输入 password 以向远程存储库进行身份验证。
private key spring.cloud.config.server.git.private-key
spring.cloud.config.server.git.repos.{repoName}.private-key
如果身份验证类型为 SSH,则为有效的 SSH 私钥。
host key spring.cloud.config.server.git.host-key
spring.cloud.config.server.git.repos.{repoName}.host-key
如果身份验证类型为 SSH,则为有效的 SSH 主机密钥。 如果还设置了 host-key-algorithm,则必须设置。
host key algorithm spring.cloud.config.server.git.host-key-algorithm
spring.cloud.config.server.git.repos.{repoName}.host-key-algorithm
如果身份验证类型为 SSH,则为 ssh-dssssh-rsassh-ed25519ecdsa-sha2-nistp256ecdsa-sha2-nistp384ecdsa-sha2-nistp521 之一。 如果还设置了主机键,则必须设置。

有关更多 Config Server 属性,请参阅在 Azure 容器应用中连接到适用于 Spring 的托管配置服务器配置选项部分。

将应用程序部署到 Azure 容器应用

在本地测试应用程序后,可以将新映像部署到 Azure 容器应用应用程序。

使用以下步骤部署:

  1. 在 Azure 门户中导航到 Azure 容器应用应用程序。
  2. 在菜单中,选择“应用程序”>“容器”。
  3. 选择“编辑并部署”以打开“创建和部署新修订”页。
  4. 在“容器映像”部分中,选择该映像,然后选择“编辑”。
  5. 在“编辑容器”部分的“属性”选项卡上,选择应用程序的新映像。
  6. 在“环境变量”选项卡上,对于“名称”,指定 spring.application.name。 然后,对于“源”,选择“手动输入”并指定应用程序使用配置的配置文件名称。
  7. 选择“保存”以部署新修订。

疑难解答

可以使用 Log Analytics 在 Azure 容器应用中查看适用于 Spring 的托管配置服务器的日志。 请使用以下步骤:

  1. 在 Azure 门户中导航到 Azure 容器应用环境。

  2. 选择“监视”>“日志”菜单。

  3. 若要查看日志,请在 ContainerAppSystemLogs_CL 表的查询编辑器中输入查询,如以下示例所示:

    ContainerAppSystemLogs_CL
    | where ComponentType_s == "SpringCloudConfig"
    | project Time=TimeGenerated, ComponentName=ComponentName_s, Message=Log_s
    | take 100
    

有关查询日志的详细信息,请参阅 Azure 容器应用中托管 Java 组件的可观测性