4.7.2.2. 对 Package Manifest Format 目录镜像进行镜像(mirror)

集群管理员可以根据 Package Manifest Format 将自定义 Operator 目录镜像(mirror)到 registry 中,并使用目录源将内容加载到其集群中。本例中的流程使用之前构建并推送到受支持的 registry 的自定义 redhat-operators 目录镜像。

先决条件

  • 没有网络访问限制的工作站
  • 基于推送到受支持的 registry 的 Package Manifest Format 的自定义 Operator 目录镜像
  • oc 版本 4.3.5+
  • podman 版本 1.9.3+
  • 访问支持 Docker v2-2 的镜像(mirror)registry

    重要

    OpenShift Container Platform 集群的内部 registry 不能用作目标 registry,因为它不支持没有标签的推送(在镜像过程中需要这个功能)。

  • 如果您正在使用私有 registry,请将 REG_CREDS 环境变量设置为到 registry 凭证的文件路径。例如,对于 podman CLI:

    $ REG_CREDS=${XDG_RUNTIME_DIR}/containers/auth.json

流程

  1. oc adm catalog mirror 命令提取自定义 Operator catalog 镜像的内容,以生成镜像(mirror)所需的清单:您可以选择:

    • 允许该命令的默认行为在生成清单后自动将所有镜像内容镜像到您的镜像 registry 中,或者
    • 添加 --manifests-only 标志来只生成镜像所需的清单,但并不实际将镜像内容镜像到 registry。这对检查哪些要镜像(mirror)非常有用。如果您只需要部分内容的话,可以对映射列表做出任何修改。然后,您可以使用该文件与 oc image mirror 命令一起,在以后的步骤中镜像修改的镜像列表。

    在没有网络访问限制的工作站中,运行以下命令:

    $ oc adm catalog mirror \
        <registry_host_name>:<port>/olm/redhat-operators:v1 \ 1
        <registry_host_name>:<port> \ 2
        [-a ${REG_CREDS}] \ 3
        [--insecure] \ 4
        [--index-filter-by-os='<platform>/<arch>'] \ 5
        [--manifests-only] 6
    1
    指定 Operator 目录镜像。
    2
    指定目标 registry 的完全限定域名(FQDN)。
    3
    可选:如果需要,指定 registry 凭证文件的位置。
    4
    可选:如果您不想为目标 registry 配置信任,请添加 --insecure 标志。
    5
    可选:在有多个变体可用时,指定目录镜像的平台和架构。镜像被传递为 '<platform>/<arch>[/<variant>]'。这不适用于目录镜像引用的镜像。有效值是 linux/amd64linux/ppc64lelinux/s390x
    6
    可选:只生成镜像所需的清单,但并不实际将镜像内容镜像到 registry。

    输出示例

    using database path mapping: /:/tmp/190214037
    wrote database to /tmp/190214037
    using database at: /tmp/190214037/bundles.db 1
    ...

    1
    命令生成的临时数据库。

    运行完该命令后,会在当前目录中创建 manifests-<index_image_name>-<random_number>/ 目录并生成以下文件:

    • catalogSource.yaml 文件是 CatalogSource 对象的基本定义,它预先填充目录镜像标签及其他相关元数据。此文件可原样使用,或进行相应修改来在集群中添加目录源。
    • 用来定义 ImageContentSourcePolicy 对象的 imageContentSourcePolicy.yaml,它可以将节点配置为在 Operator 清单中存储的镜像(image)引用和镜像 (mirror) 的 registry 间进行转换。

      注意

      如果您的集群使用 ImageContentSourcePolicy 对象来配置存储库镜像,则只能将全局 pull secret 用于镜像 registry。您不能在项目中添加 pull secret。

    • mapping.txt 文件,在其中包含所有源镜像,并将它们映射到目标 registry。此文件与 oc image mirror 命令兼容,可用于进一步自定义镜像(mirror)配置。
  2. 如果您在上一步中使用 --manifests-only 标志,并只想镜像部分内容:

    1. mapping.txt 文件中的镜像列表改为您的规格。如果您不确定要镜像的镜像子集的名称和版本,请使用以下步骤查找:

      1. oc adm catalog mirror 命令生成的临时数据库运行 sqlite3 工具,以检索与一般搜索查询匹配的镜像列表。输出以后如何编辑 mapping.txt 文件的帮助信息。

        例如,要检索与字符串 clusterlogging.4.3 类似的镜像列表:

        $ echo "select * from related_image \
            where operatorbundle_name like 'clusterlogging.4.3%';" \
            | sqlite3 -line /tmp/190214037/bundles.db 1
        1
        请参阅 oc adm catalog mirror 命令的输出结果来查找数据库文件的路径。

        输出示例

        image = registry.redhat.io/openshift4/ose-logging-kibana5@sha256:aa4a8b2a00836d0e28aa6497ad90a3c116f135f382d8211e3c55f34fb36dfe61
        operatorbundle_name = clusterlogging.4.3.33-202008111029.p0
        
        image = registry.redhat.io/openshift4/ose-oauth-proxy@sha256:6b4db07f6e6c962fc96473d86c44532c93b146bbefe311d0c348117bf759c506
        operatorbundle_name = clusterlogging.4.3.33-202008111029.p0
        ...

      2. 使用上一步的结果来编辑 mapping.txt 文件,使其只包含您要镜像的镜像子集。

        例如,您可以使用前面示例输出中的 image 值来找出您的 mapping.txt 文件中存在以下匹配行:

        mapping.txt 中的匹配镜像映射

        registry.redhat.io/openshift4/ose-logging-kibana5@sha256:aa4a8b2a00836d0e28aa6497ad90a3c116f135f382d8211e3c55f34fb36dfe61=<registry_host_name>:<port>/openshift4-ose-logging-kibana5:a767c8f0
        registry.redhat.io/openshift4/ose-oauth-proxy@sha256:6b4db07f6e6c962fc96473d86c44532c93b146bbefe311d0c348117bf759c506=<registry_host_name>:<port>/openshift4-ose-oauth-proxy:3754ea2b

        在这个示例中,如果您只想镜像这些 image,可以在 mapping.txt 文件中删除所有其他条目,仅保留上述两行。

    2. 在您的没有网络访问限制的工作站中,使用您修改的 mapping.txt 文件,使用 oc image mirror 命令将镜像镜像到 registry:

      $ oc image mirror \
          [-a ${REG_CREDS}] \
          --filter-by-os='.*' \
          -f ./manifests-redhat-operators-<random_number>/mapping.txt
      警告

      如果未设置 --filter-by-os 标志或设置为 .* 以外的任何值,该命令会过滤不同的架构,用来更改清单列表摘要,也称为 多架构镜像。不正确的摘要会导致在断开连接的集群中部署这些镜像和 Operator 失败。

  3. 创建 ImageContentSourcePolicy 对象:

    $ oc create -f ./manifests-redhat-operators-<random_number>/imageContentSourcePolicy.yaml

现在,您可以创建一个 CatalogSource 对象来引用您的镜像内容。