9.2.2. 阻塞特定的 registry

您可以通过编辑 image.config.openshift.io/cluster 自定义资源(CR)来阻塞 registry。OpenShift Container Platform 会将对此 CR 的更改应用到集群中的所有节点。

在拉取或推送镜像时,容器运行时会搜索 image.config.openshift.io/cluster CR 的 registrySources 参数中列出的 registry。如果您在 blockedRegistries 参数下创建了 registry 列表,则容器运行时不会搜索这些 registry。允许所有其他 registry。

警告

为防止 pod 失败,请不要将 registry.redhat.ioquay.io registry 添加到 blockedRegistries 列表中,因为环境中有效负载镜像需要它们。

流程

  1. 编辑 image.config.openshift.io/cluster CR:

    $ oc edit image.config.openshift.io/cluster

    以下是一个带有块列表的 image.config.openshift.io/cluster CR 示例:

    apiVersion: config.openshift.io/v1
    kind: Image
    metadata:
      annotations:
        release.openshift.io/create-only: "true"
      creationTimestamp: "2019-05-17T13:44:26Z"
      generation: 1
      name: cluster
      resourceVersion: "8302"
      selfLink: /apis/config.openshift.io/v1/images/cluster
      uid: e34555da-78a9-11e9-b92b-06d6c7da38dc
    spec:
      registrySources: 1
        blockedRegistries: 2
        - untrusted.com
    status:
      internalRegistryHostname: image-registry.openshift-image-registry.svc:5000
    1
    registrySources:包含用于决定容器运行时在访问构建和 pod 的镜像时应如何处理个别 registry 的配置。它不包含内部集群 registry 的配置。
    2
    指定不用于镜像拉取(pull)和推送(push)操作的 registry。允许所有其他 registry。
    注意

    可以设置 blockedRegistries registry 或 allowedRegistries registry,但不能同时设置这两个 registry。

    Machine Config Operator (MCO) 会监控 image.config.openshift.io/cluster CR 以了解对 registry 的任何更改,并在检测到更改时重启节点。对受阻 registry 的更改会出现在每个节点上的 /etc/containers/registries.conf 文件中。

  2. 要检查 registry 是否已添加到策略文件中,请在节点上使用以下命令:

    $ cat /host/etc/containers/registries.conf

    以下示例显示,在进行镜像拉取和推送时,不使用 untrusted.com

    输出示例

    unqualified-search-registries = ["registry.access.redhat.com", "docker.io"]
    
    [[registry]]
      prefix = ""
      location = "untrusted.com"
      blocked = true