你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
在此作指南中,网络函数发布者和服务设计器了解如何使用 Azure CLI AOSM 扩展将容器化网络函数载入 AOSM。 接着,可以将 CNF 部署到已连接 Azure Arc 的 Kubernetes 群集上,包括 Azure 运营商关系群集。
载入是一个多步骤过程。 满足先决条件后,您将使用 Azure CLI 的 AOSM 扩展来执行以下操作:
- 生成 Bicep 文件,该文件会根据 Helm 图表和 value.yaml 定义网络功能定义 (NFD) 组和版本。
- 发布 NFD,并将 CNF 映像和图表上传到制品库(由 AOSM 管理的 Azure 容器注册表 (ACR))。
- 将已发布的 NFD 添加到定义网络服务设计组和版本(NSD)的 Bicep 文件中。
- 发布 NSD。
先决条件
- 已在 Azure 订阅上启用了 AOSM。
- 如果计划在 Azure Operator Nexus 上运行 CNF,那么您可以访问 Azure Operator Nexus 实例,并已完成 工作负载部署的先决条件。
注释
强烈建议在已连接 Arc 的目标 Kubernetes 环境中测试 Helm 包的 helm install
是否成功。
配置权限
- 需要在订阅中使用参与者角色才能创建资源组,或创建具有参与者角色的现有资源组。
- 您需要在包含映像的源 ACR 上进行
Reader
/AcrPull
角色分配。 - 对于包含 AOSM 管理的项目存储的订阅,需获配
Contributor
和AcrPush
角色。 这些权限允许 Azure CLI AOSM 扩展执行 ACR 到 ACR 的直接复制。 直接复制是将图像从一个 ACR 传输到另一个 ACR 的最快方法。- 公司策略可能会阻止你拥有订阅范围的权限。 参数
--no-subscription-permissions
在az aosm nfd publish
az aosm nsd publish
命令上可用,使用从 AOSM 服务派生的严格范围权限来协调与本地计算机之间的双向两步复制。 此两步复制速度较慢,但不需要订阅范围的权限。
- 公司策略可能会阻止你拥有订阅范围的权限。 参数
Helm 包
- 要载入的 Helm 包必须存在于要从中执行 CLI 的计算机的本地存储中。
- 默认情况下,Azure CLI AOSM 扩展将默认使用 helm 包中的
values.yaml
文件。 CLI 支持使用备用values.yaml
覆盖此行为。 此备用文件必须存在于要从中执行 CLI 的计算机的本地存储中。
- 默认情况下,Azure CLI AOSM 扩展将默认使用 helm 包中的
注释
强烈建议在 Helm 包中加入 helm 值的架构,并且当使用你在加入 AOSM 时打算使用的 value.yaml 运行 helm template
时,Helm 包模板应符合预期。
容器映像
- 容器映像存在于现有的 ACR 或支持 Docker API 的备用容器注册表中。 容器映像必须存储在源注册表中,映像结构需与 helm 图表中定义的映像位置相符。 CLI CNF 映像发现和上传中介绍了此要求。
- 在运行任何
docker login
命令之前,使用az aosm
命令登录到托管您的容器映像的非 Azure 的容器注册表。 如果使用 ACR,则不需要此步骤:Azure CLI AOSM 扩展将自动登录。
Helm 和 Docker 引擎
下载并安装 Azure CLI
要在本地安装 Azure CLI,请参阅如何安装 Azure CLI。
要登录 Azure CLI,请使用 az login
命令并完成终端中显示的提示以完成身份验证。 有关更多登录选项,请参阅使用 Azure CLI 登录。
注释
如果在 Windows 或 macOS 上运行,请考虑在 Docker 容器中运行 Azure CLI。 有关详细信息,请参阅如何在 Docker 容器中运行 Azure CLI。 还可以在 Azure Cloud Shell 中使用 Bash 环境。 有关详细信息,请参阅启动 Cloud Shell 以在 Azure Cloud Shell 中使用 Bash 环境。
安装 AOSM CLI 扩展
Az CLI AOSM 扩展需要 Azure CLI 2.54.0 或更高版本。
- 运行
az version
以查看安装的版本和依赖库。 - 运行
az upgrade
以升级到 Azure CLI 的当前版本。
使用以下命令安装 AOSM CLI 扩展:
az extension add --name aosm
生成网络函数定义组和版本
此步骤在工作目录中创建一个名为 cnf-cli-output
的文件夹,其中包含 AOSM 资源的 Bicep 文件(用于定义网络功能定义组和版本)以及项目存储。 这些资源最终将包含在网络服务设计中。
为 CNF 生成 Azure CLI AOSM 扩展输入文件。
az aosm nfd generate-config --definition-type cnf --output-file <filename.jsonc>
打开在上一步中生成的输入文件,并使用内联注释输入所需的值。 此示例显示的是针对虚构的 Contoso CNF 的 Az CLI AOSM 扩展输入文件。
注释
默认情况下,Azure CLI AOSM 扩展仅公开所需的参数,而不公开输入
values.yaml
中的默认值。 可以将expose_all_parameters
设置为true
以公开网络功能定义版本 (NFDV) 和配置组架构 (CGS) 中的所有 helm 值。 有关详细信息,请参阅 使用 AOSM CLI 扩展公开的参数。{ // Azure ___location to use when creating resources e.g uksouth "___location": "eastus", // Name of the Publisher resource you want your definition published to. // Will be created if it does not exist. "publisher_name": "contoso", // Resource group for the Publisher resource. // You should create this before running the publish command "publisher_resource_group_name": "contoso", // Name of the ACR Artifact Store resource. // Will be created if it does not exist. "acr_artifact_store_name": "contoso-artifact-store", // Name of NF definition. "nf_name": "contoso-cnf-nfd", // Version of the NF definition in 1.1.1 format (three integers separated by dots). "version": "1.0.0", // If set to true, all NFD configuration parameters are made available to the designer, including optional parameters and those with defaults. // If not set or set to false, only required parameters without defaults will be exposed. "expose_all_parameters": false, // List of registries from which to pull the image(s). // For example ["sourceacr.azurecr.io/test", "myacr2.azurecr.io", "ghcr.io/path"]. // For non Azure Container Registries, ensure you have run a docker login command before running build. "image_sources": ["contoso.azuercr.io/contoso", "docker.io"], // List of Helm packages to be included in the CNF. "helm_packages": [ { // The name of the Helm package. "name": "contoso-helm-package", // The file path to the helm chart on the local disk, relative to the directory from which the command is run. // Accepts .tgz, .tar or .tar.gz, or an unpacked directory. Use Linux slash (/) file separator even if running on Windows. "path_to_chart": "/home/cnf-onboard/contoso-cnf-helm-chart-0-1-0.tgz", // The file path (absolute or relative to this configuration file) of YAML values file on the local disk which will be used instead of the values.yaml file present in the helm chart. // Accepts .yaml or .yml. Use Linux slash (/) file separator even if running on Windows. "default_values": "", } ] }
执行以下命令以构建网络功能定义组和版本 Bicep 文件。
az aosm nfd build --definition-type cnf --config-file <filename.jsonc>
可以查看文件夹和文件结构,并在必要时进行修改。
发布网络函数定义组和版本
此步骤创建用于定义网络功能定义的 AOSM 资源,以及用于存储网络功能容器镜像的工件库。 这一步还可以通过直接从源 ACR 复制映像和图表,将映像和图表上传到项目存储,或者,如果你在订阅范围内不具备 Contributor
和 AcrPush
角色,则可以通过以下方法完成上传:在本地重新标记 docker 映像,然后使用 AOSM 服务生成的权限范围严格的凭据将这些映像上传到项目存储。
- 执行以下命令以发布网络函数定义组和版本。 如果您没有订阅范围
Contributor
和AcrPush
角色,请在命令中包含--no-subscription-permissions
。
注释
如果使用的是 Windows,则必须在发布步骤中运行 Docker Desktop。
az aosm nfd publish --build-output-folder cnf-cli-output --definition-type cnf
生成网络服务设计组和版本
本部分将在工作目录中创建一个名为 nsd-cli-output
的文件夹。 此文件夹包含定义网络服务设计组和版本的 AOSM 资源的 Bicep 文件。 此网络服务设计是站点网络服务资源中使用的模板,用于部署在上一部分中加入的网络函数。
生成 Azure CLI AOSM 扩展 NSD 输入文件。
az aosm nsd generate-config --output-file <nsd-output-filename.jsonc>
打开在上一步中生成的输入文件,并使用内联注释输入所需的值。 生成的输入文件包含
resource_element_type
类型的附加ArmTemplate
。 载入 CNF 时不需要这样做;可以将其删除。 结果应如下例所示。 该示例演示虚拟 Contoso NSD 的 Az CLI AOSM 扩展输入文件,该文件可用于将虚构的 Contoso CNF 部署到连接 Arc 的 Nexus Kubernetes 群集。{ // Azure ___location to use when creating resources e.g uksouth "___location": "eastus", // Name of the Publisher resource you want your definition published to. // Will be created if it does not exist. "publisher_name": "contoso", // Resource group for the Publisher resource. // Will be created if it does not exist. "publisher_resource_group_name": "contoso", // Name of the ACR Artifact Store resource. // Will be created if it does not exist. "acr_artifact_store_name": "contoso-artifact-store", // Network Service Design (NSD) name. This is the collection of Network Service Design Versions. Will be created if it does not exist. "nsd_name": "contoso-nsd", // Version of the NSD to be created. This should be in the format A.B.C "nsd_version": "1.0.0", // Optional. Description of the Network Service Design Version (NSDV). "nsdv_description": "An NSD that deploys the onboarded contoso-cnf NFD", // List of Resource Element Templates (RETs). // There must be at least one NF RET. // ArmTemplate RETs are optional. Delete if not required. "resource_element_templates": [ { // Type of Resource Element. Either NF or ArmTemplate "resource_element_type": "NF", "properties": { // The name of the existing publisher for the NSD. "publisher": "contoso", // The resource group that the publisher is hosted in. "publisher_resource_group": "contoso", // The name of the existing Network Function Definition Group to deploy using this NSD. // This will be the same as the NF name if you published your NFDV using the CLI. "name": "contoso-cnf-nfd", // The version of the existing Network Function Definition to base this NSD on. // This NSD will be able to deploy any NFDV with deployment parameters compatible with this version. "version": "1.0.0", // The region that the NFDV is published to. "publisher_offering_location": "eastus", // Type of Network Function. Valid values are 'cnf' or 'vnf'. "type": "cnf" } } ] }
注释
资源元素模板部分用于定义哪些 NFD 被包含在 NSD 中。 属性必须与传递给
az aosm nfd build
命令的输入文件中所使用的属性匹配。 这是因为 Azure CLI AOSM 扩展在生成 NSD 时会验证 NFD 是否已正确集成。执行以下命令以生成网络服务设计组和版本 Bicep 文件。
az aosm nsd build --config-file <nsd-output-filename.jsonc>
可以查看文件夹和文件结构,并根据需要进行修改。
发布网络服务设计组和版本
此步骤创建定义网络服务设计组和版本的 AOSM 资源。 它还将 NSD 所需的工件上传到 Artifact Store(网络功能 ARM 模板)。
- 执行以下命令以发布网络服务设计组和版本。 如果您没有订阅范围
Contributor
和AcrPush
角色,请在命令中包含--no-subscription-permissions
。
az aosm nsd publish --build-output-folder nsd-cli-output
现在,你已拥有一套完整的 AOSM 发布者资源,并已准备好执行操作流程。