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

快速入门:使用 Azure CLI 预配 Azure Spring Apps

注意

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

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

本快速入门介绍如何使用 Azure CLI 将 Azure Spring Apps 群集部署到现有虚拟网络中。

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

企业部署计划包括以下 Tanzu 组件:

  • 生成服务
  • 应用程序配置服务
  • 服务注册表
  • Spring Cloud 网关
  • API 门户

先决条件

  • 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 用于内部 Spring 应用 CIDR 范围,或群集虚拟网络地址范围内包含的任何 IP 范围。
  • 已授予对虚拟网络的服务权限。 Azure Spring Apps 资源提供程序要求对虚拟网络拥有“所有者”权限,以便为虚拟网络中专用的动态服务主体授予访问权限,从而进行进一步的部署和维护。 有关说明和详细信息,请参阅在虚拟网络中部署 Azure Spring Apps向服务授予虚拟网络权限部分。
  • 如果使用 Azure 防火墙或网络虚拟设备 (NVA),则还需要满足以下先决条件:
  • Azure CLI
  • 如果你是首次在目标订阅中部署 Azure Spring Apps 企业计划实例,请参阅 Azure 市场中的企业计划要求部分。

查看 Azure CLI 部署脚本

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

#!/bin/bash

echo "Enter Azure Subscription ID: "
read subscription
subscription=$subscription

echo "Enter Azure region for resource deployment: "
read region
location=$region

echo "Enter Azure Spring  Resource Group Name: "
read azurespringrg
azurespring_resource_group_name=$azurespringrg

echo "Enter Azure Spring VNet Resource Group Name: "
read azurespringvnetrg
azurespring_vnet_resource_group_name=$azurespringvnetrg

echo "Enter Azure Spring Spoke VNet : "
read azurespringappspokevnet
azurespringappspokevnet=$azurespringappspokevnet

echo "Enter Azure Spring App SubNet : "
read azurespringappsubnet
azurespring_app_subnet_name='/subscriptions/'$subscription'/resourcegroups/'$azurespring_vnet_resource_group_name'/providers/Microsoft.Network/virtualNetworks/'$azurespringappspokevnet'/subnets/'$azurespringappsubnet

echo "Enter Azure Spring Service SubNet : "
read azurespringservicesubnet
azurespring_service_subnet_name='/subscriptions/'$subscription'/resourcegroups/'$azurespring_vnet_resource_group_name'/providers/Microsoft.Network/virtualNetworks/'$azurespringappspokevnet'/subnets/'$azurespringservicesubnet

echo "Enter Azure Log Analytics Workspace Resource Group Name: "
read loganalyticsrg
loganalyticsrg=$loganalyticsrg

echo "Enter Log Analytics Workspace Resource ID: "
read workspace
workspaceID='/subscriptions/'$subscription'/resourcegroups/'$loganalyticsrg'/providers/microsoft.operationalinsights/workspaces/'$workspace

echo "Enter Reserved CIDR Ranges for Azure Spring: "
read reservedcidrrange
reservedcidrrange=$reservedcidrrange

echo "Enter key=value pair used for tagging Azure Resources (space separated for multiple tags): "
read tag
tags=$tag

randomstring=$(LC_ALL=C tr -dc 'a-z0-9' < /dev/urandom | fold -w 13 | head -n 1)
azurespring_service='spring-'$randomstring #Name of unique Spring resource
azurespring_appinsights=$azurespring_service
azurespring_resourceid='/subscriptions/'$subscription'/resourceGroups/'$azurespring_resource_group_name'/providers/Microsoft.AppPlatform/Spring/'$azurespring_service

# Create Application Insights
az monitor app-insights component create \
    --app ${azurespring_service} \
    --location ${location} \
    --kind web \
    -g ${azurespringrg} \
    --application-type web \
    --workspace ${workspaceID}

az spring create \
    -n ${azurespring_service} \
    -g ${azurespringrg} \
    -l ${location} \
    --sku Enterprise \
    --build-pool-size S1 \
    --enable-application-configuration-service \
    --enable-service-registry \
    --enable-gateway \
    --enable-api-portal \
    --api-portal-instance-count 2 \
    --enable-java-agent true \
    --app-insights ${azurespring_service} \
    --app-subnet ${azurespring_app_subnet_name} \
    --service-runtime-subnet ${azurespring_service_subnet_name} \
    --reserved-cidr-range ${reservedcidrrange} \
    --tags ${tags}

# Update diagnostic setting for Azure Spring instance
az monitor diagnostic-settings create  \
   --name monitoring \
   --resource ${azurespring_resourceid} \
   --logs    '[{"category": "ApplicationConsole","enabled": true}]' \
   --workspace  ${workspaceID}

部署群集

若要使用 Azure CLI 脚本部署 Azure Spring Apps 群集,请执行以下步骤:

  1. 使用以下命令登录到 Azure:

    az login
    

    登录后,此命令将输出有关你有权访问的所有订阅的信息。 记下要使用的订阅的名称和 ID。

  2. 设置目标订阅。

    az account set --subscription "<your subscription name>"
    
  3. 注册 Azure Spring Apps 资源提供程序。

    az provider register --namespace 'Microsoft.AppPlatform'
    
  4. 将所需的扩展添加到 Azure CLI。

    az extension add --name spring
    
  5. 从提供 Azure Spring Apps 的区域中选择一个部署位置,如各区域的产品可用性中所示。

  6. 使用以下命令生成 Azure 位置列表。 记下在上一步中选择的区域的简短 Name 值。

    az account list-locations --output table
    
  7. 创建要将资源部署到其中的资源组。

    az group create --name <your-resource-group-name> --location <location-name>
    
  8. 将 Azure Spring Apps 标准计划企业计划的脚本保存到本地,然后从 Bash 提示符运行该脚本。

    标准计划:

    ./azuredeploySpringStandard.sh
    

    企业计划:

    ./azuredeploySpringEnterprise.sh
    
  9. 在脚本提示时输入以下值:

    • 之前保存的 Azure 订阅 ID。
    • 之前保存的 Azure 位置名称。
    • 之前创建的资源组的名称。
    • 将在其中部署资源的虚拟网络资源组的名称。
    • 分支虚拟网络的名称(例如 vnet-spoke)。
    • Azure Spring Apps 应用程序服务要使用的子网名称(例如 snet-app)。
    • Azure Spring Apps 运行时服务要使用的子网名称(例如 snet-runtime)。
    • 要用于存储诊断日志的 Azure Log Analytics 工作区的资源组的名称。
    • Azure Log Analytics 工作区的名称(例如 la-cb5sqq6574o2a)。
    • Azure Spring Apps 要使用的虚拟网络中的 CIDR 范围(例如 XX.X.X.X/16,XX.X.X.X/16,XX.X.X.X/16)。
    • 要在所有支持标记的资源上作为标记应用的键/值对。 有关详细信息,请参阅使用标记对 Azure 资源和管理层次结构进行组织。 使用空格分隔列表来应用多个标记(例如 environment=Dev BusinessUnit=finance)。

提供此信息后,脚本将创建和部署 Azure 资源。

查看已部署的资源

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

清理资源

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

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

后续步骤

在本快速入门中,你使用 Azure CLI 将 Azure Spring Apps 实例部署到了现有虚拟网络中,然后验证了部署。 若要详细了解 Azure Spring Apps,请继续访问以下资源。