5.5. 使用带有镜像 registry 的 Windows 容器


Windows Machine Config Operator (WMCO)可以使用 ImageDigestMirrorSet (IDMS) 或 ImageTagMirrorSet (ITMS) 对象从 registry 镜像拉取镜像,而不是从公共 registry 中拉取镜像。

镜像 registry 具有以下优点:

  • 避免公共 registry 中断
  • 加速节点和 pod 创建
  • 从机构的防火墙后拉取镜像

镜像 registry 也可以在断开连接的环境中的 OpenShift Container Platform 集群中使用,或 air-gapped 网络。断开连接的网络是一个受限网络,没有直接互联网连接。由于集群无法访问互联网,所以无法引用任何外部容器镜像。

使用镜像 registry 需要以下常规步骤:

  • 使用 Red Hat Quay 等工具创建镜像 registry。
  • 创建容器镜像 registry 凭据文件。
  • 将镜像从在线镜像存储库复制到您的镜像 registry。

有关这些步骤的详情,请参考"关于断开连接的安装镜像"。

在创建镜像 registry 并镜像镜像后,您可以使用 ImageDigestMirrorSet (IDMS)或 ImageTagMirrorSet (ITMS)对象将集群配置为从镜像 registry 拉取镜像,而无需更新每个 pod 规格。IDMS 和 ITMS 对象重定向从源镜像 registry 上的存储库拉取镜像并通过镜像存储库解析的请求。

如果对 IDMS 或 ITMS 对象进行了更改,WMCO 将使用新信息自动更新 Windows 节点上的相应 hosts.toml 文件。请注意,WMCO 在镜像设置更改时按顺序更新每个 Windows 节点。因此,随着集群中的 Windows 节点数量增加这些更新所需的时间。

因为 WMCO 配置的 Windows 节点依赖于容器运行时,WMCO 可确保容器的配置文件与 registry 设置保持同步。对于新节点,这些文件在创建时复制到实例。对于现有节点,在激活镜像 registry 后,registry 控制器使用 SSH 访问每个节点并复制生成的配置文件,替换任何现有文件。

您可以使用带有机器集或 Bring-Your-Own-Host (BYOH) Windows 节点的 mirror registry。

当使用 IDMS 或 ITMS 对象在 Windows 节点上镜像容器镜像时,请注意以下与 Linux 节点不同的行为:

  • Windows 节点上的镜像在 registry 级别上工作,而不是在 Linux 节点使用的镜像级别上工作。因此,使用 IDMS 或 ITMS 对象进行镜像的 Windows 镜像具有特定的命名要求。

    命名空间和镜像镜像的镜像名称的最终部分必须与正在镜像的镜像匹配。例如,当镜像 mcr.microsoft.com/oss/kubernetes/pause:3.9 镜像时,镜像必须采用 $mirrorRegistry/<organization>/oss/kubernetes/pause:3.9 格式,其中 $org 可以是任何机构名称或命名空间。有些有效值有 $mirrorRegistry/oss/kubernetes/pause:3.9,$mirrorRegistry/custom/oss/kubernetes/pause:3.9, 和 $mirrorRegistry/x/y/z/oss/kubernetes/pause:3.9

  • Windows 节点使用 ITMS 对象,并使用它来配置 registry 范围镜像。在以下示例中,将 quay.io/remote-org/image 配置为镜像到 quay.io/my-org/image 会导致 Windows 节点使用来自 quay.io/remote-org 的所有镜像。因此,quay.io/remote-org/image:tag 使用 quay.io/my-org/image:tag 镜像,但使用 quay.io/remote-org/different-image:tag 镜像的另一个容器也会尝试使用 quay.io/remote-org/different-image:tag mirror。如果没有考虑意外的行为,这可能会导致意外的行为。

    因此,使用 IDMS 对象而不是 ITMS 对象使用摘要来指定容器镜像。使用摘要可以防止使用错误的容器镜像,确保容器指定的镜像以及拉取的镜像具有相同的摘要。

5.5.1. 了解镜像 registry 仓库镜像

通过设置容器 registry 存储库镜像,您可以执行以下任务:

  • 配置 OpenShift Container Platform 集群,以便重定向从源镜像 registry 上的存储库拉取(pull)镜像的请求,并通过已镜像 (mirror) 的镜像 registry 上的存储库来解决该请求。
  • 为每个目标存储库识别多个已镜像 (mirror)的存储库,以确保如果一个镜像停止运作,仍可使用其他镜像。

OpenShift Container Platform 中的存储库镜像包括以下属性:

  • 镜像拉取(pull)可应对 registry 停机的问题。
  • 在断开连接的环境中的集群可以从关键位置(如 quay.io )拉取镜像,并让公司防火墙后面的 registry 提供请求的镜像。
  • 发出镜像拉取(pull)请求时尝试特定 registry 顺序,通常最后才会尝试持久性 registry。
  • 您输入的镜像信息会添加到 OpenShift Container Platform 集群中每个 Windows 节点上的适当的 hosts.toml 容器配置文件中。
  • 当节点从源存储库中请求镜像时,它会依次尝试每个已镜像的存储库,直到找到所请求的内容。如果所有镜像均失败,集群则会尝试源存储库。如果成功,则镜像拉取至节点中。

您可以使用以下方法设置存储库镜像:

  • 在 OpenShift Container Platform 安装中:

    通过拉取(pull) OpenShift Container Platform 所需的容器镜像,然后将这些镜像放至公司防火墙后,即可将 OpenShift Container Platform 安装到受限网络中的数据中心。

  • 安装 OpenShift Container Platform 后:

    如果您没有在 OpenShift Container Platform 安装过程中配置镜像,您可以在安装后使用以下自定义资源 (CR) 对象之一进行配置:

    • ImageDigestMirrorSet (IDMS).此对象允许您使用摘要规格从镜像 registry 中拉取镜像。IDMS CR 可让您设置回退策略,在镜像拉取失败时继续尝试从源 registry 中拉取。
    • ImageTagMirrorSet (ITMS)。此对象允许您使用镜像标签从已镜像的 registry 中拉取镜像。ITMS CR 可让您设置回退策略,在镜像拉取失败时继续尝试从源 registry 中拉取。

每个自定义资源对象都标识以下信息:

  • 您希望镜像 (mirror) 的容器镜像存储库的源。
  • 您要提供内容的每个镜像存储库的独立条目

请注意以下操作以及它们对节点排空行为的影响:

  • 如果您创建一个 IDMS 或 ICSP CR 对象,MCO 不会排空或重启节点。
  • 如果创建一个 ITMS CR 对象,MCO 会排空并重启节点。
  • 如果您删除 ITMS 或 IDMS CR 对象,MCO 会排空并重启节点。
  • 如果您修改 ITMS 或 IDMS CR 对象,MCO 会排空并重启节点。

Windows Machine Config Operator (WMCO)会监视 IDMS 和 ITMS 资源的更改,并生成一组 host.toml 容器配置文件,每个源 registry 有一个文件,以及这些更改。然后,WMCO 会更新任何现有 Windows 节点以使用新的 registry 配置。

注意

在使用镜像 registry 添加 Windows 节点前,必须创建 IDMS 和 ITMS 对象。

5.5.2. 配置镜像 registry 存储库镜像

您可以创建安装后镜像配置自定义资源 (CR),将源镜像 registry 中的镜像拉取请求重定向到镜像 registry。

重要

通过 ImageDigestMirrorSetImageTagMirrorSet 对象镜像的 Windows 镜像具有特定的命名要求,如"使用带有镜像 registry 的 Windows 容器"中所述。

先决条件

  • 使用具有 cluster-admin 角色的用户访问集群。

流程

  1. 通过以下方法配置已镜像的存储库:

    • 使用 Red Hat Quay 设置已镜像的存储库。您可以将镜像从一个存储库复制到另一个存储库,也可以使用 Red Hat Quay 随着时间的推移自动重复同步这些存储库。

    • 使用 skopeo 等工具手动将镜像从源存储库复制到已镜像的存储库。

      例如,在 {op-system-base-full system} 上安装 skopeo RPM 软件包后,使用 skopeo 命令,如下例所示:

      $ skopeo copy --all \
      docker://registry.access.redhat.com/ubi9/ubi-minimal:latest@sha256:5cf... \
      docker://example.io/example/ubi-minimal

      在本例中,有一个名为 example.io 的容器镜像 registry,以及名为 example 的容器镜像 registry。您需要将 ubi9/ubi-minimal 镜像从 registry.access.redhat.com 复制到 example.io。创建已镜像的 registry 后,您可以将 OpenShift Container Platform 集群配置为将向源存储库发出的请求重定向到已镜像的存储库。

    重要

    您必须镜像 mcr.microsoft.com/oss/kubernetes/pause:3.9 镜像。例如,您可以使用以下 skopeo 命令镜像镜像:

    $ skopeo copy \
    docker://mcr.microsoft.com/oss/kubernetes/pause:3.9\
    docker://example.io/oss/kubernetes/pause:3.9
  2. 登录您的 OpenShift Container Platform 集群。
  3. 根据需要,创建一个 ImageDigestMirrorSetImageTagMirrorSet CR,将源和镜像(mirror)替换为您自己的 registry、存储库对和镜像:

    apiVersion: config.openshift.io/v1
    kind: ImageDigestMirrorSet
    metadata:
      name: ubi9repo
    spec:
      imageDigestMirrors:
      - mirrors:
        - example.io/example/ubi-minimal
        - example.com/example2/ubi-minimal
        source: registry.access.redhat.com/ubi9/ubi-minimal
        mirrorSourcePolicy: AllowContactingSource
      - mirrors:
        - mirror.example.com
        source: registry.redhat.io
        mirrorSourcePolicy: NeverContactSource
      - mirrors:
        - docker.io
        source: docker-mirror.internal
        mirrorSourcePolicy: AllowContactingSource
  4. 运行以下命令来创建新对象:

    $ oc create -f registryrepomirror.yaml
  5. 要检查是否应用了镜像的配置设置,请在其中一个节点上执行以下操作。

    1. 列出您的节点:

      $ oc get node

      输出示例

      NAME                           STATUS                     ROLES    AGE  VERSION
      ip-10-0-137-44.ec2.internal    Ready                      worker   7m   v1.29.4
      ip-10-0-138-148.ec2.internal   Ready                      master   11m  v1.29.4
      ip-10-0-139-122.ec2.internal   Ready                      master   11m  v1.29.4
      ip-10-0-147-35.ec2.internal    Ready                      worker   7m   v1.29.4
      ip-10-0-153-12.ec2.internal    Ready                      worker   7m   v1.29.4
      ip-10-0-154-10.ec2.internal    Ready                      master   11m  v1.29.4

    2. 启动调试过程以访问节点:

      $ oc debug node/ip-10-0-147-35.ec2.internal

      输出示例

      Starting pod/ip-10-0-147-35ec2internal-debug ...
      To use host binaries, run `chroot /host`

    3. 将您的根目录改为 /host

      sh-4.2# chroot /host
    4. 检查 WMCO 是否为每个 Windows 实例上的每个 registry 生成 hosts.toml 文件。对于上例 IDMS 对象,文件结构中应该有三个文件:

      $ tree $config_path

      输出示例

      C:/k/containerd/registries/
      |── registry.access.redhat.com
      |   └── hosts.toml
      |── mirror.example.com
      |   └── hosts.toml
      └── docker.io
          └── hosts.toml:

      以下输出代表了应用了前面的 IDMS 对象的 hosts.toml 容器配置文件。

      host.toml 文件示例

      $ cat "$config_path"/registry.access.redhat.com/host.toml
      server = "https://registry.access.redhat.com" # default fallback server since "AllowContactingSource" mirrorSourcePolicy is set
      
      [host."https://example.io/example/ubi-minimal"]
       capabilities = ["pull"]
      
      [host."https://example.com/example2/ubi-minimal"] # secondary mirror
       capabilities = ["pull"]
      
      
      $ cat "$config_path"/registry.redhat.io/host.toml
      # "server" omitted since "NeverContactSource" mirrorSourcePolicy is set
      
      [host."https://mirror.example.com"]
       capabilities = ["pull"]
      
      
      $ cat "$config_path"/docker.io/host.toml
      server = "https://docker.io"
      
      [host."https://docker-mirror.internal"]
       capabilities = ["pull", "resolve"] # resolve tags

    5. 从源拉取镜像到节点,并检查是否通过 mirror 解析。

      sh-4.2# podman pull --log-level=debug registry.access.redhat.com/ubi9/ubi-minimal@sha256:5cf...

故障排除

如果存储库镜像过程无法正常工作,请使用以下有关存储库镜像如何工作的信息来帮助排除此问题:

  • 首个工作镜像用于提供拉取(pull)的镜像。
  • 只有在无其他镜像工作时,才会使用主 registry。
  • 从系统上下文,Insecure 标志用作回退。
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部