Share via


將 Azure Spring Apps 基本或標準方案實例移轉至企業方案

注意

Azure Spring Apps 是 Azure Spring Cloud 服務的新名稱。 雖然服務有新的名稱,但在我們努力更新資產,例如螢幕快照、影片和圖表時,您會在某些地方看到舊名稱一段時間。

本文適用於: ✔️基本/標準✔️企業

本文說明如何將基本或標準方案中的現有應用程式移轉至企業方案。 當您從基本或標準方案移轉至企業方案時,VMware Tanzu 元件會取代開放原始碼軟體 (OSS) Spring Cloud 元件,以提供更多功能支援。

本文使用寵物診所範例應用程式作為如何移轉的範例。

必要條件

  • Azure 訂用帳戶。 如果您沒有訂用帳戶,請在開始之前建立 免費帳戶
  • Azure CLI 2.45.0 版或更高版本。
  • Azure Spring Apps 企業版方案延伸模組。 使用下列命令來移除舊版並安裝最新的 Enterprise 方案擴充功能。 如果您先前已安裝擴充 spring-cloud 功能,請將其卸載,以避免設定和版本不符。
    az extension add --upgrade --name spring
    az extension remove --name spring-cloud
    
  • Git

布建服務實例

在 Azure Spring Apps 企業版方案中,VMware Tanzu 元件會取代 OSS Spring Cloud 元件,以提供更多功能支援。 Tanzu 元件會根據您的需求視需要啟用。 您必須先啟用所需的元件,才能建立 Azure Spring Apps 服務實例。

注意

若要使用 Tanzu 元件,您必須在布建 Azure Spring Apps 服務實例時加以啟用。 您目前無法在布建之後加以啟用。

使用下列步驟來布建 Azure Spring Apps 服務實例:

  1. 開啟 Azure 入口網站

  2. 在頂端搜尋方塊中,搜尋 Azure Spring Apps

  3. 從結果中選取 [Azure Spring Apps ],然後選取 [ 建立]。

  4. 在 [ 建立 Azure Spring Apps] 頁面上,設定實例 的 [訂用帳戶]、 [資源群組] 和 [名稱 ]。

  5. 針對 [服務詳細數據] 中的 [規劃],選取 [變更]。

    Screenshot of the Azure portal Azure Spring Apps creation page with the Change button highlighted in the plan section.

  6. 在 [ 選擇方案] 頁面上,選取 數據表中的 [企業 ] 數據列,然後選取 [ 選取]。

    Screenshot of the Azure portal Azure Spring Apps creation page with Basics section and 'Choose your pricing tier' pane showing.

  7. 回到 [ 建立 Azure Spring Apps] 頁面,選取 [條款 ] 以同意 Azure Marketplace 中企業方案供應專案的法律條款和隱私聲明。

  8. 選取 [下一步:VMware Tanzu 設定]。

  9. 在 [ VMWare Tanzu 設定 ] 索引標籤上,捲動清單以檢閱 Tanzu 元件。 默認會啟用所有元件。

    Screenshot of the Azure portal Azure Spring Apps creation page with V M ware Tanzu Settings section showing.

    注意

    請仔細考慮您要在布建階段使用或啟用的 Tanzu 元件。 布建 Azure Spring Apps 實例之後,您無法啟用或停用 Tanzu 元件。

  10. 選取 [ Application Insights ] 索引卷標,然後選取 [ 啟用 Application Insights]。 檢閱下列設定:

    • 應選取 [啟用 Application Insights ]。
    • 選擇現有的 Application Insights 實例,或建立新的 Application Insights 實例。
    • 在 0-100 的範圍內輸入取樣率,或使用預設值 10。

    您也可以在布建 Azure Spring Apps 實例之後啟用 Application Insights。 如需 Application Insights 定價的詳細資訊,請參閱 Azure 監視器記錄成本計算和選項Application Insights 計費一節。

    注意

    與 Azure Spring Apps 整合時,您將支付 Application Insights 的使用費用。

  11. 選取 [ 檢閱並建立 ],然後等待驗證完成,然後選取 [ 建立 ] 開始布建服務實例。

完成資源布建大約需要 5 分鐘的時間。

建立和設定應用程式

應用程式建立步驟與標準方案相同。

  1. 使用下列命令來設定 Azure CLI 預設值。 請務必將佔位元取代為您自己的值。

    az config set defaults.group=<resource-group-name>
    az config set defaults.spring=<Azure-Spring-Apps-service-instance-name>
    
  2. 使用下列命令建立 PetClinic api-gatewaycustomers-service的兩個核心應用程式:

    az spring app create --name api-gateway --instance-count 1 --memory 2Gi --assign-endpoint
    az spring app create --name customers-service --instance-count 1 --memory 2Gi
    

使用應用程式組態服務進行外部設定

針對分散式系統中的外部化組態,受控 Spring Cloud Config Server (OSS) 僅適用於基本和標準方案。 在企業方案中,Tanzu 的應用程式組態服務會為您的應用程式提供類似的功能。 下表說明 OSS 組態伺服器與應用程式組態服務之間使用量的一些差異。

元件 支援方案 已啟用 系結至應用程式 設定檔
Spring Cloud Config Server 基本/標準 一律啟用。 自動系結 在應用程式的原始碼中設定。
Tanzu 的應用程式組態服務 企業 視需要啟用。 手動系結 在 Azure Spring Apps 部署中提供 。config-file-pattern

與 OSS 組態伺服器中的用戶端-伺服器模式不同,應用程式組態服務會使用 Kubernetes-native ConfigMap來管理組態,而 Kubernetes 原生會從後端 Git 存放庫中定義的屬性填入。 應用程式組態服務無法取得在應用程式原始碼中設定的作用中配置檔,以符合正確的組態,因此應在 Azure Spring Apps 部署層級指定明確 config-file-pattern 設定。

設定 Tanzu 的應用程式組態服務

請遵循下列步驟,將 Tanzu 的應用程式組態服務作為集中式組態服務。

  1. 在您的 Azure Spring Apps 企業實例中,選取 瀏覽窗格中的 [應用程式組態服務 ]。 檢視配置給 Tanzu 應用程式組態服務的執行中狀態和資源。

    Screenshot of the Azure portal showing the Overview tab of the Application Configuration Service page.

  2. 選取 [設定],然後在 [存放庫] 中完成窗體,以新增具有下列資訊的新專案:

    • 名稱:default
    • 模式: api-gateway,customers-service
    • Uri: https://github.com/Azure-Samples/spring-petclinic-microservices-config
    • 標籤: master

    Screenshot of the Azure portal showing the Settings tab of the Application Configuration Service page.

  3. 選取 [驗證 ] 以驗證目標 URI 的存取權。

  4. 驗證成功完成之後,選取 [ 套用 ] 以更新組態設定。

將應用程式系結至 Tanzu 的應用程式組態服務

當您搭配 Git 後端使用適用於 Tanzu 的應用程式組態服務時,必須將應用程式系結至 Tanzu 的應用程式組態服務。 系結應用程式之後,您必須設定應用程式所使用的模式。 使用下列步驟來系結和設定應用程式的模式。

使用下列步驟將應用程式系結至 VMware Tanzu 的應用程式組態服務。

  1. 在您的 Azure Spring Apps 企業實例中,選取 瀏覽窗格中的 [應用程式組態服務 ]。

  2. 選取 [ 應用程式系結 ],然後選取 [ 系結應用程式]。

    Screenshot of the Azure portal showing the App binding tab of the Application Configuration Service page and the Bind app dropdown menu showing.

  3. 在下拉功能表中選取應用程式,然後選取 [ 套用 ] 將應用程式系結至 Tanzu 的應用程式組態服務。

如需詳細資訊,請參閱 使用 Tanzu 的應用程式組態服務。

使用 Tanzu 的服務登錄

Service Registry 是其中一個專屬 VMware Tanzu 元件。 它提供您的應用程式實作服務探索模式,這是微服務架構的重要概念之一。 在企業方案中,Tanzu 的服務登錄提供服務登錄,並探索應用程序的支援。 受控 Spring Cloud Eureka 僅適用於基本和標準方案,且無法在企業方案中使用。

元件 標準方案 企業方案
服務登錄 OSS eureka
自動繫結 (永遠插入)
一律布建
Tanzu 的服務登錄
需要手動系結至應用程式
視需要啟用

將應用程式系結至 Tanzu Service Registry

若要將應用程式系結至 VMware Tanzu 的應用程式組態服務,請遵循下列步驟。

  1. 在您的 Azure Spring Apps 企業實例中,選取 [服務登錄]。

  2. 選取 [ 應用程式系結]。 目前系結的應用程式會出現在 [應用程式名稱] 底下

  3. 選取 [ 系結應用程式]。

  4. 在下拉功能表中選取應用程式,然後選取 [ 套用 ] 將應用程式系結至 Tanzu Service Registry。

    Screenshot of the Azure portal Azure Spring Apps with Service Registry page and 'Bind app' dialog showing.

注意

當您變更系結/解除系結狀態時,您必須重新啟動或重新部署應用程式,讓變更生效。

如需詳細資訊,請參閱 使用 Tanzu 服務登錄

建置和部署應用程式

在企業方案中,Tanzu Build Service 是用來建置應用程式。 它提供更多功能,例如 Polyglot 應用程式,從原始程式碼和 zip 檔案等成品進行部署。

若要使用 Tanzu 建置服務,您必須指定要使用之建置工作和建置器的資源。 您也可以指定要 --build-env 設定建置環境的參數。

如果應用程式與 Tanzu 的應用程式組態服務系結,您需要指定額外的自變數 —config-file-pattern

如需詳細資訊,請參閱 使用 Tanzu 建置服務

在本機建置應用程式

使用下列步驟在本機建置:

  1. 使用下列命令來複製 Azure 帳戶中的範例應用程式存放庫、變更目錄,以及建置專案:

    git clone -b enterprise https://github.com/azure-samples/spring-petclinic-microservices
    cd spring-petclinic-microservices
    mvn clean package -DskipTests
    

    編譯專案可能需要幾分鐘的時間。 完成時,您會在其個別資料夾中為每個服務提供個別的 JAR 檔案。

  2. 使用下列命令來部署上一個步驟中內建的 JAR 檔案:

    az spring app deploy \
        --name api-gateway \
        --artifact-path spring-petclinic-api-gateway/target/spring-petclinic-api-gateway-2.3.6.jar \
        --config-file-patterns api-gateway
    az spring app deploy \
        --name customers-service \
        --artifact-path spring-petclinic-customers-service/target/spring-petclinic-customers-service-2.3.6.jar \
        --config-file-patterns customers-service
    
  3. 使用下列命令在部署後查詢應用程式狀態:

    az spring app list --output table
    

    這個指令會產生類似下列範例的輸出:

    Name                  Location    ResourceGroup       Public Url                                                 Production Deployment    Provisioning State    CPU    Memory    Running Instance    Registered Instance    Persistent Storage    Bind Service Registry    Bind Application Configuration Service
    --------------------  ----------  ---------------  ---------------------------------------------------------  -----------------------  --------------------  -----  --------  ------------------  ---------------------  --------------------  -----------------------  ----------------------------------------
    api-gateway           eastus      <resource group>   https://<service_name>-api-gateway.asc-test.net                    default                  Succeeded             1      2Gi       1/1                1/1                    -                     True                     True
    customers-service     eastus      <resource group>                                                                      default                  Succeeded             1      2Gi       1/1                1/1                    -                     True                     True
    

使用 Application Insights

Azure Spring Apps Enterprise 方案會使用 buildpack 系結來整合 Application Insights 與類型 ApplicationInsights ,而不是同進程代理程式。 如需詳細資訊,請參閱 如何設定 APM 整合和 CA 憑證

下表列出可用的 APM 提供者方案。

標準方案 企業方案
Application Insight
New Relic
Dynatrace
AppDynamics
Application Insight
New Relic
Dynatrace
AppDynamics
ElasticAPM

若要檢查或更新 Application Insights 中的目前設定,請使用下列步驟:

  1. 在您的 Azure Spring Apps 企業實例中,選取 [Application Insights]。

  2. 選取 [編輯系結] 或 [解除系結] 來啟用或停用 Application Insights。

    Screenshot of the Azure portal Application Insights page with the Edit binding option dropdown menu showing.

  3. 選取 [ 編輯系結]。 編輯系結設定,然後選取 [ 儲存]。

    Screenshot of the Azure portal 'Edit binding' pane.

下一步