共用方式為


快速入門:使用 Azure CLI,在 Azure 容器應用程式中建立服務連線

本快速入門說明如何使用 Azure CLI 和服務連接器,將 Azure 容器應用程式連線到其他雲端資源。 服務連接器可讓您快速將計算服務連線到雲端服務,同時管理連線的驗證和網路設定。

重要

Azure 容器應用程式中的服務連接器目前為預覽狀態。 請參閱 Microsoft Azure 預覽版增補使用規定,以了解適用於 Azure 功能 (搶鮮版 (Beta)、預覽版,或尚未正式發行的版本) 的法律條款。

必要條件

  • 必需安裝 Azure CLI 2.37.0 或更新版本。 若要升級至最新版本,請執行 az upgrade。 如果您是使用 Azure Cloud Shell,就已安裝最新版本。

  • 容器應用程式延伸模組必須安裝在 Azure CLI 或 Cloud Shell 中。 若要進行安裝,請執行 az extension add --name containerapp

初始設定

  1. 如果您是第一次使用服務連接器,請從執行命令 az provider register 開始,註冊服務連接器資源提供者。

    az provider register -n Microsoft.ServiceLinker
    

    提示

    您可以執行命令 az provider show -n "Microsoft.ServiceLinker" --query registrationState 來檢查資源提供者是否已註冊。 如果輸出是 Registered,表示服務連接器已經註冊。

  2. 選擇性地執行命令 az containerapp connection list-support-types ,以取得 Azure 容器應用程式支援的目標服務清單。

    az containerapp connection list-support-types --output table
    

建立服務連線

使用受控識別或存取金鑰建立連線。

重要

若要使用受控識別,您必須擁有修改 Microsoft Entra 角色指派的權限。 沒有這個權限,就無法建立連線。 您可以要求訂用帳戶擁有者授與您此權限,或改為使用存取金鑰來建立連線。

  1. 執行 az containerapp connection create 命令,以使用系統指派的受控識別,從 Azure 容器應用程式建立前往 Blob 儲存體的服務連線。

    az containerapp connection create storage-blob --system-identity
    
  2. 在 Azure CLI 要求時提供下列資訊:

    設定 描述
    The resource group that contains the container app 包含容器應用程式的資源群組名稱。
    Name of the container app 容器應用程式名稱。
    The container where the connection information will be saved 容器應用程式的容器名稱。
    The resource group which contains the storage account 包含儲存體帳戶之資源群組的名稱。
    Name of the storage account 您要連線之儲存體帳戶的名稱。 在本指南中,我們會使用 Blob 儲存體。

注意

如果您沒有 Blob 儲存體,您可以執行 az containerapp connection create storage-blob --new --system-identity 來佈建新的 Blob 儲存體,並使用受控識別直接連線到您的容器應用程式。

檢視連線

使用 Azure CLI 命令 az containerapp connection list 來列出所有容器應用程式的佈建連線。 將下列命令中的預留位置 <container-app-resource-group><container-app-name> 取代為容器應用程式的資源組名和名稱。 您也可以移除 [--output table] 選項,以檢視連線的詳細資訊。

az containerapp connection list -g "<container-app-resource-group>" --name "<container-app-name>" --output table

輸出也會顯示連線的佈建狀態:失敗或成功。

下一步