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

快速入门:通过 Azure CLI 在 Azure 容器应用中创建服务连接

本快速入门介绍如何使用 Azure CLI 和服务连接器将 Azure 容器应用连接到其他云资源。 使用服务连接器可以快速将计算服务连接到云服务,同时管理连接身份验证和网络设置。

重要

容器应用中的服务连接器目前为预览版。 有关 beta 版本、预览版或尚未正式发布的版本的 Azure 功能所适用的法律条款,请参阅 Microsoft Azure 预览版的补充使用条款

先决条件

  • 必须安装 2.37.0 或更高版本的 Azure CLI。 若要升级到最新版本,请运行 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 以获取容器应用支持的目标服务列表。

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

创建服务连接

使用托管标识或访问密钥创建连接。

重要

要使用托管标识,必须有权修改 Microsoft Entra 角色分配。 没有该权限,创建连接的操作会失败。 要求订阅所有者向你授予此权限,或改用访问密钥来创建连接。

  1. 运行 az containerapp connection create 命令,通过系统分配的托管标识创建容器应用到 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

输出还显示连接的预配状态:失败或成功。

后续步骤