你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
本文档解释了 Azure CLI AOSM 扩展如何在 helm 图表中发现映像,从容器注册表中拉取图像,并将其上载到 AOSM 项目存储。 Azure CLI AOSM 扩展支持 Azure 容器注册表 (ACR) 和支持 Docker API 的任何容器注册表。
映像发现
az aosm nfd generate-config --definition-type cnf
生成的 Azure CLI AOSM 扩展网络功能定义版本 (NFDV) 输入文件包含参数,其指定 AOSM CLI 在容器映像加入期间查询的源注册表(以及可选的命名空间)。
// 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": [],
"image_sources"
是一个字符串数组。 每个字符串都是对容器注册表的引用,也可以是该注册表中的命名空间。
Az CLI AOSM 扩展:
- 分析
helm template
生成的 Kubernetes 定义文件以发现容器映像引用。 - 在“image_sources”数组中包含的注册表和命名空间中搜索容器映像引用。
- 将映像从源注册表复制到 AOSM 项目存储。
重要
AOSM CLI 要求源注册表中的映像与 helm 图表中写入的命名空间结构相匹配。 例如,helm 图表中作为 core/contoso-a:1.0.0
包含的映像必须在源注册表中以 core/contoso-a:1.0.0
结尾的路径中可用。 任何附加前缀都必须包含在 az aosm nfd generate-config --definition-type cnf
命令生成的 cnf-input.jsonc
文件中的 "image_sources"
参数中。
举例说明
此示例描述了虚构的容器化网络函数 (CNF)。 此 CNF 由三个提供核心 CNF 函数的映像和一个可以部署用于执行针对 CNF 的测试查询的测试映像组成。 映像的源注册表是名为 myregistry
的 ACR。 在本例中,我们将加入四个映像。
NFDV 输入文件中的“image_sources”字段设置如下:
// 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": ["myregistry.azurecr.io"],
helm template
的输入相对于此 CNF 的 helm 图表在 Kubernetes 部署定义中给出了四条映像线。
image: repository/release/contoso-a:1.0.0
image: repository/release/contoso-b:1.0.0
image: repository/release/contoso-c:1.0.0
image: repository/test-release/contoso-test:1.0.0
Azure CLI AOSM 扩展接受上述映像行并移除 repository
(AOSM 使用支持 AOSM 项目存储的新注册表覆盖存储库)。 然后,Azure CLI AOSM 扩展将搜索 myregistry.azurecr.io/release/contoso-a:1.0.0
、myregistry.azurecr.io/release/contoso-b:1.0.0
、myregistry.azurecr.io/release/contoso-c:1.0.0
和 myregistry.azurecr.io/test-release/contoso-test:1.0.0
中的映像。 映像必须在这些路径中可用。
命名空间
Azure CLI AOSM 扩展还支持源容器注册表中的映像命名空间。 例如,可以将 contoso-test
映像上载到源注册表中的 test/test-release/contoso-test:1.0.0
。 在这种情况下,必须在 NFDV 输入文件的 "image_sources"
参数中配置额外的前缀 test
。
// 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": ["myregistry.azurecr.io", "myregistry.azurecr.io/test"],
Azure AOSM CLI 扩展在 myregistry.azurecr.io
中搜索映像,并在其中发现 contoso-a
、contoso-b
和 contoso-c
。 然后,它在 myregistry.azurecr.io/test
中搜索,在该处它发现 contoso-test
。