快速入门:使用 ARM 模板预配 Azure Spring Apps

注意

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

本快速入门介绍如何使用 Azure 资源管理器模板(ARM 模板)将 Azure Spring Apps 群集部署到现有虚拟网络中。

借助 Azure Spring Apps,可以轻松地将 Spring 应用程序部署到 Azure,而无需更改代码。 该服务管理 Spring 应用程序的基础结构,让开发人员可以专注于代码。 Azure Spring Apps 可以通过以下方法提供生命周期管理:综合性监视和诊断、配置管理、服务发现、CI/CD 集成、蓝绿部署等。

资源管理器模板是定义项目基础结构和配置的 JavaScript 对象表示法 (JSON) 文件。 模板使用声明性语法。 在声明性语法中,你可以在不编写创建部署的编程命令序列的情况下,描述预期部署。

先决条件

  • Azure 订阅。 如果你没有订阅,请在开始之前创建一个试用版订阅。

  • Azure Spring Apps 群集的两个专用子网,一个用于服务运行时,另一个用于 Spring 应用程序。 有关子网和虚拟网络要求,请参阅在虚拟网络中部署 Azure Spring Apps虚拟网络要求部分。

  • 用于 Azure Spring Apps 诊断设置的现有 Log Analytics 工作区,以及一个基于工作区的 Application Insights 资源。 有关详细信息,请参阅使用诊断设置分析日志和指标以及 Azure Spring Apps 中的 Application Insights Java 进程内代理

  • 你已确定供 Azure Spring Apps 群集使用的三个内部无类别域际路由 (CIDR) 范围(每个范围至少为 /16)。 这些 CIDR 范围不可直接路由,只能由 Azure Spring Apps 群集在内部使用。 群集不能将 169.254.0.0/16、172.30.0.0/16、172.31.0.0/16 或 192.0.2.0/24 用于内部 Azure Spring Apps CIDR 范围。 群集也不能使用群集虚拟网络地址范围中包含的任何 IP 范围。

  • 已授予对虚拟网络的服务权限。 Azure Spring Apps 资源提供程序要求对虚拟网络拥有“所有者”权限,以便为虚拟网络中专用的动态服务主体授予访问权限,从而进行进一步的部署和维护。 有关说明和详细信息,请参阅在虚拟网络中部署 Azure Spring Apps向服务授予虚拟网络权限部分。

  • 如果使用 Azure 防火墙或网络虚拟设备 (NVA),则还需要满足以下先决条件:

查看模板

本快速入门中使用的模板来自 Azure Spring Apps 参考体系结构

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "springCloudInstanceName": {
            "type": "string",
            "metadata": {
                "description": "The instance name of the Azure Spring Cloud resource"
            }
        },
        "appInsightsName": {
            "type": "string",
            "metadata": {
                "description": "The name of the Application Insights instance for Azure Spring Cloud"
            }
        },
        "laWorkspaceResourceId": {
            "type": "string",
            "metadata": {
                "description": "The resource ID of the existing Log Analytics workspace. This will be used for both diagnostics logs and Application Insights"
            }
        },
        "springCloudAppSubnetID": {
            "type": "string",
            "metadata": {
                "description": "The resourceID of the Azure Spring Cloud App Subnet"
            }
        },
        "springCloudRuntimeSubnetID": {
            "type": "string",
            "metadata": {
                "description": "The resourceID of the Azure Spring Cloud Runtime Subnet"
            }
        },
        "springCloudServiceCidrs": {
            "type": "string",
            "defaultValue": "10.0.0.0/16,10.2.0.0/16,10.3.0.1/16",
            "metadata": {
                "description": "Comma-separated list of IP address ranges in CIDR format. The IP ranges are reserved to host underlying Azure Spring Cloud infrastructure, which should be 3 at least /16 unused IP ranges, must not overlap with any Subnet IP ranges"
            }
            
        },
        
        "tags": {
            "type": "object",
            "metadata": {
                "description": "The tags that will be associated to the Resources"
            },
            "defaultValue": {
                "environment": "lab"
            }
        }
    },
    "variables": {              
        "location": "[resourceGroup().location]"                                   
    },
    "resources": [
        {
            "type": "Microsoft.Insights/components",
            "name": "[parameters('appInsightsName')]",
            "apiVersion": "2020-02-02-preview",
            "location": "[variables('location')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "Application_Type": "web",
                "ApplicationId": "[parameters('appInsightsName')]",
                "Flow_Type": "Bluefield",
                "Request_Source": "rest",
                "WorkspaceResourceId": "[parameters('laWorkspaceResourceId')]"
            }
        },
        {
            "apiVersion": "2022-03-01-preview",
            "name": "[parameters('springCloudInstanceName')]",
            "location": "[variables('location')]",
            "tags": "[parameters('tags')]",
            "dependsOn": [
                "[resourceId('Microsoft.Insights/components', parameters('appInsightsName'))]"
                
            ],
            "type": "Microsoft.AppPlatform/Spring",
            "sku": {
                "name": "S0",
                "tier": "Standard"
            },
            "properties": {
                "networkProfile": {
                    "serviceCidr": "[parameters('springCloudServiceCidrs')]",
                    "serviceRuntimeSubnetId": "[parameters('springCloudRuntimeSubnetID')]",
                    "appSubnetId": "[parameters('springCloudAppSubnetID')]"
                }
            }
        },
        {
            "apiVersion": "2022-03-01-preview",
            "name": "[concat(parameters('springCloudInstanceName'), '/default')]",
            "type": "Microsoft.AppPlatform/Spring/monitoringSettings",
            "properties": {
                "traceEnabled": true,
                "appInsightsInstrumentationKey": "[reference(resourceId('Microsoft.Insights/components', parameters('appInsightsName')), '2020-02-02-preview').InstrumentationKey]"
            },
            "dependsOn": [
                "[resourceId('Microsoft.AppPlatform/Spring/', parameters('springCloudInstanceName'))]"
            ]
        },
        {
            "type": "Microsoft.AppPlatform/Spring/providers/diagnosticSettings",
            "name": "[concat(parameters('springCloudInstanceName'), '/Microsoft.Insights/monitoring')]",
            "dependsOn": [  
                "[resourceId('Microsoft.AppPlatform/Spring/', parameters('springCloudInstanceName'))]"       
            ],
            "apiVersion": "2017-05-01-preview",
            "properties": {
                "name": "monitoring",
                "workspaceId": "[parameters('laWorkspaceResourceId')]",
                "logs": [
                    {
                        "category": "ApplicationConsole",
                        "enabled": true,
                        "retentionPolicy": {
                            "days": 30,
                            "enabled": false
                        }
                    }
                ]
            }
        }
               
    ],
    "outputs": {
    }
}

该模板中定义了两个 Azure 资源:

部署模板

若要部署该模板,请执行以下步骤。

首先,选择下图登录到 Azure 并打开一个模板。 模板将在现有的虚拟网络中创建一个 Azure Spring Apps 实例,并在现有的 Azure Monitor Log Analytics 工作区中创建一个基于工作区的 Application Insights 实例。

接下来,为以下字段输入值:

  • 资源组:选择“新建”,为“资源组”输入一个独一无二的名称,然后选择“确定”。
  • springCloudInstanceName:输入 Azure Spring Apps 资源的名称。
  • appInsightsName:输入 Azure Spring Apps 的 Application Insights 实例的名称。
  • laWorkspaceResourceId:输入现有 Log Analytics 工作区的资源 ID(例如 /subscriptions/<你的订阅>/resourcegroups/<你的日志分析资源组>/providers/Microsoft.OperationalInsights/workspaces/<你的日志分析工作区名称>)。
  • springCloudAppSubnetID:输入 Azure Spring Apps 应用程序子网的资源 ID。
  • springCloudRuntimeSubnetID:输入 Azure Spring Apps 运行时子网的资源 ID。
  • springCloudServiceCidrs:以 CIDR 格式输入 IP 地址范围(共三个)的逗号分隔列表。 这些 IP 范围将保留下来,用于托管底层的 Azure Spring Apps 基础结构。 这 3 个范围应该至少是 /16 的未使用 IP 范围,且不能与网络中使用的任何可路由子网 IP 范围重叠。
  • tags:输入任何自定义标记。

最后,选择“查看 + 创建”,然后选择“创建”。

查看已部署的资源

可以使用 Azure 门户来检查已部署的资源,也可以使用 Azure CLI 或 Azure PowerShell 脚本列出已部署的资源。

清理资源

如果打算继续使用后续的快速入门和教程,则可能需要保留这些资源。 如果不再需要资源组,可以将其删除,这将删除资源组中的资源。 若要使用 Azure CLI 或 Azure PowerShell 删除资源组,请使用以下命令:

echo "Enter the Resource Group name:" &&
read resourceGroupName &&
az group delete --name $resourceGroupName &&
echo "Press [ENTER] to continue ..."

后续步骤

在本快速入门中,你已使用 ARM 模板将一个 Azure Spring Apps 实例部署到了现有虚拟网络中,然后验证了部署。 若要详细了解 Azure Spring Apps 和 Azure 资源管理器,请继续参阅以下资源。