在本指南中,網路功能發行者和服務設計師會瞭解如何使用 Azure CLI AOSM 擴充功能將容器化網路功能佈建到 AOSM。 CNF 稍後可以部署到 Azure Arc 連線的 Kubernetes 叢集,包括 Azure 營運商 Nexus 叢集。
入職是個多步驟的過程。 一旦符合必要條件,您將使用 Azure CLI AOSM 擴充功能來:
- 根據 Helm 圖表和 values.yaml,產生 Bicep 檔案,以定義網路函式定義群組和版本 (NFD)。
- 發佈 NFD,並將 CNF 映像和圖表上傳至工件存儲庫(由 AOSM 管理的 Azure 容器註冊表(ACR))。
- 將已發佈的 NFD 新增至 Bicep 檔案,以定義網路服務設計群組和版本 (NSD)。
- 發佈 NSD。
先決條件
- 您已在您的 Azure 訂用帳戶上啟用 AOSM。
- 如果您的 CNF 是要在 Azure 作員 Nexus 上執行,您可以存取 Azure 作員 Nexus 實例,並已完成 工作負載部署的必要條件。
備註
強烈建議您在目標 Arc 連線的 Kubernetes 環境中測試 helm install Helm 套件的 成功。
設定許可權
- 您需要在您的訂用帳戶中擁有參與者角色,才能建立新的資源群組;或者,您需要在現有資源群組中擁有參與者角色。
- 您需要來源
Reader/AcrPullACR 上包含映像的角色指派。 - 您需要在包含 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 擴充功能會使用
values.yamlHelm 套件中的檔案。 CLI 支援使用替代的values.yaml來覆寫此行為。 此替代檔案必須存在於您執行 CLI 的電腦本機記憶體上。
- 根據預設,Azure CLI AOSM 擴充功能會使用
備註
強烈建議 Helm 套件包含 helm 值文件的架構,當您使用預期的 values.yaml 在上線至 AOSM 時執行 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 複製映像檔和圖表至 Artifact Store,或者,如果您沒有訂用帳戶範圍的 Contributor 和 AcrPush 角色,請在本地重新標記 Docker 映像檔,並透過使用 AOSM 服務產生的嚴格範圍認證上傳至 Artifact Store。
- 執行下列命令以發佈網路函式定義群組和版本。 如果您沒有訂用帳戶範圍
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" } } ] }備註
資源元素範本區段會定義NSD中包含哪些NFD。 屬性必須符合傳遞至
az aosm nfd build命令之輸入檔中使用的屬性。 這是因為 Azure CLI AOSM 擴充功能會驗證建置 NSD 時,NFD 是否已正確上線。執行下列命令來建置網路服務設計群組和版本 Bicep 檔案。
az aosm nsd build --config-file <nsd-output-filename.jsonc>
您可以檢視資料夾和檔案結構,並視需要進行修改。
發佈網路服務設計群組和版本
此步驟會建立 AOSM 資源,以定義網路服務設計群組和版本。 它也會將 NSD 所需的工件上傳至工件存放區(網路功能 ARM 模板)。
- 執行下列命令以發佈網路服務設計群組和版本。 如果您沒有訂用帳戶範圍
Contributor和AcrPush角色,請在命令中包含--no-subscription-permissions。
az aosm nsd publish --build-output-folder nsd-cli-output
您已具備一組完整的 AOSM 發行者資源,並準備好執行操作流程。