将 Azure Spring Apps 服务实例移到另一个区域
注意
基本、标准和企业计划将从 2025 年 3 月中旬开始弃用,停用期为 3 年。 建议转换到 Azure 容器应用。 有关详细信息,请参阅 Azure Spring Apps 停用公告。
标准消耗和专用计划将于 2024 年 9 月 30 日开始弃用,并在六个月后完全关闭。 建议转换到 Azure 容器应用。
本文介绍如何将 Azure Spring Apps 服务实例移到另一个区域。 移动实例很有作用,例如,在灾难恢复计划中或者在创建重复的测试环境时。
无法将 Azure Spring Apps 实例从一个区域直接移到另一个区域,但可以使用 Azure 资源管理器模板(ARM 模板)将实例部署到新区域。 有关使用 Azure 资源管理器和模板的详细信息,请参阅快速入门:使用 Azure 门户创建和部署 ARM 模板。
在移动服务实例之前,请考虑到以下限制:
- 不同的定价计划 (SKU) 支持不同的功能集。 如果更改 SKU,可能需要更改模板以便仅包含目标 SKU 支持的功能。
- 可能无法使用模板移动 Azure Spring Apps 中的所有子资源。 部署模板后,可能需要进行额外的设置才能移动模板。 有关详细信息,请参阅本文的配置新的 Azure Spring Apps 服务实例部分。
- 移动虚拟网络 (VNet) 实例时,必须创建新的网络资源。 有关详细信息,请参阅在虚拟网络中部署 Azure Spring Apps。
先决条件
- 一个现有的 Azure Spring Apps 服务实例。 要创建新的服务实例,请参阅快速入门:在 Azure Spring Apps 中部署首个应用程序。
- (可选)Azure CLI 2.11.2 版或更高版本。
导出模板
使用以下步骤导出模板:
- 登录 Azure 门户。
- 在左侧菜单中选择“所有资源”,然后选择你的 Azure Spring Apps 实例。
- 在“自动化”下,选择“导出模板”。
- 在“导出模板”窗格中选择“下载”。
- 找到 .zip 文件,将其解压缩,然后获取 template.json 文件。 此文件包含资源模板。
修改模板
使用以下步骤修改 template.json 文件。 在以下示例中,新的 Azure Spring Apps 实例名称为 new-service-name。 之前的实例名称为 old-service-name。
以下示例演示如何将模板中的所有
name
实例从 old-service-name 更改为 new-service-name:{ "type": "Microsoft.AppPlatform/Spring", "apiVersion": "{api-version}", "_comment": "the following line was changed from 'old-service-name'", "name": "[parameters('new-service-name')]", …. }
以下示例演示如何将模板中的
location
实例更改为新的目标位置:{ "type": "Microsoft.AppPlatform/Spring", "apiVersion": "{api-version}", "name": "[parameters('new_service_name')]", "_comment": "the following line was changed from 'old-region'", "location": "{new-region}", ….. }
如果要移动的实例是虚拟网络实例,以下示例演示如何更新模板中的目标虚拟网络资源
parameters
实例:"parameters": { … "virtualNetworks_service_vnet_externalid": { "_comment": "the following line was changed from 'old-vnet-resource-id'", "defaultValue": "{new-vnet-resource-id}", "type": "String" } },
以下示例演示如何确保
serviceRuntimeSubnetId
和appSubnetId
子网存在。 子网在networkProfile
服务中定义:{ "type": "Microsoft.AppPlatform/Spring", "apiVersion": "{api-version}", "name": "[parameters('Spring_new_service_name')]", … "properties": { "networkProfile": { "serviceRuntimeSubnetId": "[concat(parameters('virtualNetworks_service_vnet_externalid'), '/subnets/apps-subnet')]", "appSubnetId": "[concat(parameters('virtualNetworks_service_vnet_externalid'), '/subnets/service-runtime-subnet')]", } } }
如果配置了任何自定义域资源,请按照教程:将现有的自定义域映射到 Azure Spring Apps 中所述创建 CNAME 记录。 确保记录名称与新服务名称相符。
以下示例演示如何将所有应用资源的模板
properties
中的所有relativePath
实例更改为<default>
:{ "type": "Microsoft.AppPlatform/Spring/apps/deployments", "apiVersion": "{api-version}", "name": "[concat(parameters('Spring_new_service_name'), '/api-gateway/default')]", … "properties": { "active": true, "source": { "type": "Jar", "_comment": "the following line was changed to 'default'", "relativePath": "<default>" }, … } }
创建应用后,它将使用默认的横幅应用程序。 再次使用 Azure CLI 部署 JAR 文件。 有关详细信息,请参阅本文的配置新的 Azure Spring Apps 服务实例部分。
如果使用了服务绑定并且要将其导入新的服务实例,请为目标绑定资源添加
key
属性。 以下示例中包含绑定的 MySQL 数据库:{ "type": "Microsoft.AppPlatform/Spring/apps/bindings", "apiVersion": "{api-version}", "name": "[concat(parameters('Spring_new_service_name'), '/api-gateway/mysql')]", … "_comment": "the following line imports a mysql binding", "properties": { "resourceId": "[parameters('servers_test_mysql_name_externalid')]", "key": "{mysql-password}", "bindingParameters": { "databaseName": "mysql", "username": "{mysql-user-name}" } } }
部署模板
修改模板后,使用以下步骤部署该模板并创建新资源。
登录 Azure 门户。
在顶部搜索框中,搜索“部署自定义模板”。
在“服务”下,选择“部署自定义模板”。
转到“选择模板”选项卡,然后选择“在编辑器中生成自己的模板”。
在模板编辑器中,粘贴前面修改的 template.json 文件,然后选择“保存”。
在“基本信息”选项卡中填写以下信息:
- 目标订阅。
- 目标资源组。
- 目标区域。
- 模板所需的任何其他参数。
选择“查看 + 创建”以创建目标服务实例。
等待模板成功部署。 如果部署失败,请选择“部署详细信息”查看失败原因,然后相应地更新模板或配置。
配置新的 Azure Spring Apps 服务实例
某些功能不会导出到模板,或者无法与模板一起导入。 模板部署成功完成后,必须在新实例上手动设置一些 Azure Spring Apps 项。 以下指导描述了这些要求:
- 前一服务的 JAR 文件不会直接部署到新服务实例。 若要部署所有应用,请按照快速入门:生成应用并将其部署到 Azure Spring Apps 中的说明操作。 如果未自动配置活动部署,必须配置生产部署。 有关详细信息,请参阅在 Azure Spring Apps 中设置过渡环境。
- 不会自动导入 Config Server。 若要在新实例上设置 Config Server,请参阅在 Azure Spring Apps 中配置托管的 Spring Cloud Config Server。
- 将自动为新服务实例创建托管标识,但对象 ID 将与前一实例不同。 要在新服务实例中正常使用托管标识,请按照为 Azure Spring Apps 中的应用程序启用系统分配的托管标识中的说明操作。
- 对于“监视”->“指标”,请参阅 的指标。 为了避免混合数据,请创建新的 Log Analytics 实例来收集新数据。 此外,应为其他监视配置创建一个新实例。
- 对于“监视”->“诊断设置和日志”,请参阅使用诊断设置分析日志和指标。
- 对于“监视”->“Application Insights”,请参阅在 Azure Spring Apps 中使用 Application Insights Java 进程内代理。