快速入門:使用 Azure CLI 布建 Azure Spring Apps
注意
Azure Spring Apps 是 Azure Spring Cloud 服務的新名稱。 雖然服務有新的名稱,但在我們努力更新資產,例如螢幕快照、影片和圖表時,您會在某些地方看到舊名稱一段時間。
本文適用於:❌ 基本✔️標準✔️企業
本快速入門說明如何使用 Azure CLI 將 Azure Spring Apps 叢集部署到現有的虛擬網路。
Azure Spring Apps 可讓您輕鬆地將 Spring 應用程式部署至 Azure,而不需要變更任何程式碼。 服務會管理 Spring 應用程式的基礎結構,讓開發人員可以專注於處理程式碼。 Azure Spring 應用程式提供生命週期管理,使用全方位的監視和診斷、組態管理、服務探索、持續整合與持續傳遞的整合、藍綠部署等等。
企業部署方案包含下列 Tanzu 元件:
- 建置服務
- 應用程式組態服務
- 服務登錄
- Spring Cloud Gateway
- 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 app CIDR 範圍,或叢集虛擬網路地址範圍中包含的任何 IP 範圍。
- 授與虛擬網路的服務許可權。 Azure Spring Apps 資源提供者需要虛擬網路的擁有者許可權,才能授與虛擬網路上的專用動態服務主體,以進行進一步的部署和維護。 如需指示和詳細資訊,請參閱在虛擬網路中部署 Azure Spring Apps 的授與服務許可權一節。
- 如果您使用 Azure 防火牆 或網路虛擬設備 (NVA),您也必須滿足下列必要條件:
- 網路和完整功能變數名稱 (FQDN) 規則。 如需詳細資訊,請參閱 虛擬網路需求。
- 套用至每個服務運行時間和 Spring 應用程式子網的唯一使用者定義路由(UDR)。 如需 UDR 的詳細資訊,請參閱 虛擬網路流量路由。 部署 Azure Spring Apps 叢集之前,UDR 應該使用 0.0.0.0.0/0 的目的地設定 UDR。 如需詳細資訊,請參閱在虛擬網路中部署 Azure Spring Apps 的自備路由表一節。
- Azure CLI
- 如果您是第一次在目標訂用帳戶中部署 Azure Spring Apps Enterprise 方案實例,請參閱 Azure Marketplace 中企業方案的需求一節。
檢閱 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 叢集,請遵循下列步驟:
使用下列命令登入 Azure:
az login
登入之後,此命令會輸出您有權存取之所有訂用帳戶的相關信息。 記下您想要使用的訂用帳戶名稱和標識碼。
設定目標訂用帳戶。
az account set --subscription "<your subscription name>"
註冊 Azure Spring Apps 資源提供者。
az provider register --namespace 'Microsoft.AppPlatform'
將必要的擴充功能新增至 Azure CLI。
az extension add --name spring
從 Azure Spring Apps 可供使用的區域選擇部署位置,如依區域提供的產品所示。
使用下列命令來產生 Azure 位置的清單。 記下您在上一個步驟中選取之區域的簡短 Name 值。
az account list-locations --output table
建立要部署資源的資源群組。
az group create --name <your-resource-group-name> --location <location-name>
將 Azure Spring Apps Standard 方案或 Enterprise 方案的腳本儲存在本機,然後從 Bash 提示字元執行。
標準方案:
./azuredeploySpringStandard.sh
企業方案:
./azuredeploySpringEnterprise.sh
當文稿提示時,請輸入下列值:
- 您稍早儲存的 Azure 訂用帳戶標識碼。
- 您稍早儲存的 Azure 位置名稱。
- 您稍早建立的資源群組名稱。
- 您要在其中部署資源的虛擬網路資源組名。
- 輪輻虛擬網路的名稱(例如 vnet-spoke)。
- Azure Spring Apps 應用程式服務要使用的子網名稱(例如 snet-app)。
- Azure Spring Apps 運行時間服務要使用的子網名稱(例如 snet-runtime)。
- 要用於儲存診斷記錄之 Azure Log Analytics 工作區的資源群組名稱。
- Azure Log Analytics 工作區的名稱(例如 la-cb5sqq6574o2a)。
- CIDR 範圍來自 Azure Spring Apps 要使用的虛擬網路(例如 XX.X.X.X/16,XX.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,請繼續進行下列資源。
- 從下列位置部署下列其中一個範例應用程式:
- 搭配 Azure Spring Apps 使用 自定義網域 。
- 使用 Azure 應用程式閘道 將 Azure Spring Apps 中的應用程式公開至因特網。 如需詳細資訊,請參閱 在虛擬網路中使用端對端 TLS 公開應用程式。
- 檢視以 Microsoft Azure Well-Architected Framework 為基礎的安全端對端 Azure Spring Apps 參考架構。