9.3. 配置镜像 registry 设置


您可以通过编辑 image.config.openshift.io/cluster 自定义资源(CR)来配置镜像 registry 设置。

流程

  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:
      allowedRegistriesForImport:
        - domainName: quay.io
          insecure: false
      additionalTrustedCA:
        name: myconfigmap
      registrySources:
        allowedRegistries:
        - example.com
        - quay.io
        - registry.redhat.io
        - image-registry.openshift-image-registry.svc:5000
        - reg1.io/myrepo/myapp:latest
        insecureRegistries:
        - insecure.com
    status:
      internalRegistryHostname: image-registry.openshift-image-registry.svc:5000
    注意

    当使用 allowedRegistriesblockedRegistriesinsecureRegistries 参数时,您可以在 registry 中指定单独的存储库。例如: reg1.io/myrepo/myapp:latest

    避免不安全的外部 registry,以减少可能的安全风险。

验证

  1. 要验证您的更改,请运行以下命令列出节点:

    $ oc get nodes

    输出示例

    NAME                                         STATUS                     ROLES                  AGE   VERSION
    ip-10-0-137-182.us-east-2.compute.internal   Ready,SchedulingDisabled   worker                 65m   v1.33.4
    ip-10-0-139-120.us-east-2.compute.internal   Ready,SchedulingDisabled   control-plane          74m   v1.33.4
    ip-10-0-176-102.us-east-2.compute.internal   Ready                      control-plane          75m   v1.33.4
    ip-10-0-188-96.us-east-2.compute.internal    Ready                      worker                 65m   v1.33.4
    ip-10-0-200-59.us-east-2.compute.internal    Ready                      worker                 63m   v1.33.4
    ip-10-0-223-123.us-east-2.compute.internal   Ready                      control-plane          73m   v1.33.4

9.3.1. 在允许列表中添加特定的 registry

您可以通过编辑 image.config.openshift.io/cluster 自定义资源(CR)在 registry 中为镜像拉取和推送(push)添加允许 registry 或单独的存储库。

Red Hat OpenShift Service on AWS 经典架构将对此 CR 的更改应用到集群中的所有节点。

在拉取或推送镜像时,容器运行时会搜索 image.config.openshift.io/cluster CR 的 registrySources 参数中列出的 registry。如果您在 allowedRegistries 参数下创建了 registry 列表,则容器运行时仅搜索这些 registry。allowlist 中没有的 registry 会被阻止。

警告

当您定义 allowedRegistries 参数时,除非明确列出,否则所有 registry (包括 registry.redhat.ioquay.io 和默认的 OpenShift 镜像 registry)都会被阻断。您必须将有效负载镜像所需的所有 registry 添加到 allowedRegistries 列表中。例如,列出 registry.redhat.ioquay.iointernalRegistryHostname registry。对于断开连接的集群,还必须添加镜像 registry。否则,您面临 pod 失败。

流程

  • 运行以下命令来编辑 image.config.openshift.io/cluster 自定义资源:

    $ 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:
        allowedRegistries:
        - example.com
        - quay.io
        - registry.redhat.io
        - reg1.io/myrepo/myapp:latest
        - image-registry.openshift-image-registry.svc:5000
    status:
      internalRegistryHostname: image-registry.openshift-image-registry.svc:5000
    注意

    如果您的集群使用 registrySources.insecureRegistries 参数,请确保将任何不安全的 registry 包含在允许的列表中。

    例如:

    spec:
      registrySources:
        insecureRegistries:
        - insecure.com
        allowedRegistries:
        - example.com
        - quay.io
        - registry.redhat.io
        - insecure.com
        - image-registry.openshift-image-registry.svc:5000

9.3.2. 阻塞特定的 registry

您可以通过编辑 image.config.openshift.io/cluster 自定义资源(CR)来阻止 registry 中的任何 registry 或单独的存储库。

Red Hat OpenShift Service on AWS 经典架构将对此 CR 的更改应用到集群中的所有节点。

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

警告

要防止 pod 失败,请不要将 registry.redhat.ioquay.io registry 添加到 blockedRegistries 列表中。环境中的有效负载镜像需要访问这些 registry。

流程

  • 运行以下命令来编辑 image.config.openshift.io/cluster 自定义资源:

    $ 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:
        blockedRegistries:
        - untrusted.com
        - reg1.io/myrepo/myapp:latest
    status:
      internalRegistryHostname: image-registry.openshift-image-registry.svc:5000

    您不能同时设置 blockedRegistriesallowedRegistries 参数。您必须选择一个或另一个。

9.3.3. 允许不安全的 registry

您可以通过编辑 image.config.openshift.io/cluster 自定义资源(CR) 在 registry 中添加不安全的 registry 或单独的存储库。

Red Hat OpenShift Service on AWS 经典架构将对此 CR 的更改应用到集群中的所有节点。没有使用有效 SSL 证书或不需要 HTTPS 连接的 registry 被视为是不安全的 registry。

重要

避免不安全的外部 registry,以减少可能的安全风险。

+ :leveloffset: +1

警告

当您定义 allowedRegistries 参数时,除非明确列出,否则所有 registry (包括 registry.redhat.ioquay.io 和默认的 OpenShift 镜像 registry)都会被阻断。您必须将有效负载镜像所需的所有 registry 添加到 allowedRegistries 列表中。例如,列出 registry.redhat.ioquay.iointernalRegistryHostname registry。对于断开连接的集群,还必须添加镜像 registry。否则,您面临 pod 失败。

流程

  • 运行以下命令来编辑 image.config.openshift.io/cluster 自定义资源(CR):

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

    以下是一个带有不安全 registry 列表的 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:
        insecureRegistries:
        - insecure.com
        - reg4.io/myrepo/myapp:latest
        allowedRegistries:
        - example.com
        - quay.io
        - registry.redhat.io
        - insecure.com
        - reg4.io/myrepo/myapp:latest
        - image-registry.openshift-image-registry.svc:5000
    status:
      internalRegistryHostname: image-registry.openshift-image-registry.svc:5000
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2026 Red Hat
返回顶部