将 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

先决条件

导出模板

使用以下步骤导出模板:

  1. 登录 Azure 门户
  2. 在左侧菜单中选择“所有资源”,然后选择你的 Azure Spring Apps 实例。
  3. 在“自动化”下,选择“导出模板”。
  4. 在“导出模板”窗格中选择“下载”。
  5. 找到 .zip 文件,将其解压缩,然后获取 template.json 文件。 此文件包含资源模板。

修改模板

使用以下步骤修改 template.json 文件。 在以下示例中,新的 Azure Spring Apps 实例名称为 new-service-name。 之前的实例名称为 old-service-name。

  1. 以下示例演示如何将模板中的所有 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')]",
        ….
    }
    
  2. 以下示例演示如何将模板中的 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}",
            …..
        }
    
  3. 如果要移动的实例是虚拟网络实例,以下示例演示如何更新模板中的目标虚拟网络资源 parameters 实例:

    "parameters": {
        …
        "virtualNetworks_service_vnet_externalid": {
            "_comment": "the following line was changed from 'old-vnet-resource-id'",
            "defaultValue": "{new-vnet-resource-id}",
            "type": "String"
        }
    },
    

    以下示例演示如何确保 serviceRuntimeSubnetIdappSubnetId 子网存在。 子网在 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')]",
            }
        }
    }
    
  4. 如果配置了任何自定义域资源,请按照教程:将现有的自定义域映射到 Azure Spring Apps 中所述创建 CNAME 记录。 确保记录名称与新服务名称相符。

  5. 以下示例演示如何将所有应用资源的模板 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 服务实例部分。

  6. 如果使用了服务绑定并且要将其导入新的服务实例,请为目标绑定资源添加 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}"
            }
        }
    }
    

部署模板

修改模板后,使用以下步骤部署该模板并创建新资源。

  1. 登录 Azure 门户

  2. 在顶部搜索框中,搜索“部署自定义模板”。

  3. 在“服务”下,选择“部署自定义模板”。

  4. 转到“选择模板”选项卡,然后选择“在编辑器中生成自己的模板”。

  5. 在模板编辑器中,粘贴前面修改的 template.json 文件,然后选择“保存”。

  6. 在“基本信息”选项卡中填写以下信息:

    • 目标订阅。
    • 目标资源组。
    • 目标区域。
    • 模板所需的任何其他参数。

    Azure 门户的屏幕截图,其中显示了“自定义部署”窗格。

  7. 选择“查看 + 创建”以创建目标服务实例。

  8. 等待模板成功部署。 如果部署失败,请选择“部署详细信息”查看失败原因,然后相应地更新模板或配置。

配置新的 Azure Spring Apps 服务实例

某些功能不会导出到模板,或者无法与模板一起导入。 模板部署成功完成后,必须在新实例上手动设置一些 Azure Spring Apps 项。 以下指导描述了这些要求:

后续步骤