This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.9.2. 配置镜像 registry 设置
您可以通过编辑 image.config.openshift.io/cluster
自定义资源(CR)来配置镜像 registry 设置。Machine Config Operator(MCO)会监控 image.config.openshift.io/cluster
CR 是否有对 registry 的更改,并在检测到更改时重启节点。
流程
编辑
image.config.openshift.io/cluster
自定义资源:oc edit image.config.openshift.io/cluster
$ oc edit image.config.openshift.io/cluster
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 以下是
image.config.openshift.io/cluster
CR 示例:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
Image
:包含有关如何处理镜像的集群范围信息。规范且唯一有效的名称是cluster
。- 2
allowedRegistriesForImport
:限制普通用户可从中导入镜像的容器镜像 registry。将此列表设置为您信任包含有效镜像且希望应用程序能够从中导入的 registry。有权从 API 创建镜像或ImageStreamMappings
的用户不受此策略的影响。通常只有集群管理员具有适当权限。- 3
additionalTrustedCA
:引用包含镜像流导入、Pod 镜像拉取、openshift-image-registry
pullthrough 和构建期间受信任的额外证书颁发机构(CA)的配置映射。此配置映射的命名空间为openshift-config
。ConfigMap 的格式是使用 registry 主机名作为键,使用 PEM 证书作为值,用于每个要信任的额外 registry CA。- 4
registrySources
:包含用于决定容器运行时在访问构建和 pod 的镜像时是否允许或阻止个别 registry 的配置。可以设置allowedRegistries
参数或blockedRegistries
参数,但不能同时设置这两个参数。您还可以定义是否允许访问允许使用镜像短名称的不安全的 registry。本例使用allowedRegistries
参数,该参数定义允许使用的 registry。不安全 registryinsecure.com
也被允许。registrySources
参数不包含内部集群 registry 的配置。
注意当定义
allowedRegistries
参数时,除非明确列出,否则所有 registry(包括 registry.redhat.io 和 quay.io registry 和默认的内部镜像 registry)都会被阻断。如果使用参数,为了避免 pod 失败,您必须将registry.redhat.io
和quay.io
registry 和internalRegistryHostname
添加到allowedRegistries
列表中,因为环境中有效负载镜像需要它们。不要将registry.redhat.io
和quay.io
registry 添加到blockedRegistries
列表中。应避免使用不安全的外部 registry,以减少可能的安全性风险。
要检查是否应用了更改,请列出您的节点:
oc get nodes
$ oc get nodes
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 输出示例
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
9.2.1. 添加特定的 registry 复制链接链接已复制到粘贴板!
您可以通过编辑 image.config.openshift.io/cluster
自定义资源(CR)来添加允许镜像拉取(pull)和推送(push)操作的 registry 列表。OpenShift Container Platform 会将对此 CR 的更改应用到集群中的所有节点。
在拉取或推送镜像时,容器运行时会搜索 image.config.openshift.io/cluster
CR 的 registrySources
参数中列出的 registry。如果您在 allowedRegistries
参数下创建了 registry 列表,则容器运行时仅搜索这些 registry。不在列表中的 registry 会被阻断。
当定义 allowedRegistries
参数时,除非明确列出,否则所有 registry(包括 registry.redhat.io
和 quay.io registry
和默认的内部镜像 registry)都会被阻断。如果使用参数,为了避免 pod 失败,您必须将 registry.redhat.io
和 quay.io
registry 以及 internalRegistryHostname
添加到 allowedRegistries
列表中,因为环境中有效负载镜像需要它们。对于断开连接的集群,还应添加镜像的 registry。
流程
编辑
image.config.openshift.io/cluster
CR:oc edit image.config.openshift.io/cluster
$ oc edit image.config.openshift.io/cluster
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 以下是一个带有允许列表的
image.config.openshift.io/cluster
CR 示例:Copy to Clipboard Copied! Toggle word wrap Toggle overflow 注意可以设置
allowedRegistries
参数或blockedRegistries
参数,但不能同时设置这两个参数。Machine Config Operator(MCO)会监控
image.config.openshift.io/cluster
资源以了解对 registry 的任何更改。当 MCO 检测到更改时,它会排空节点,应用更改,并对节点进行 uncordon 处理。节点返回Ready
状态后,允许的 registry 列表用于更新每个节点上的/host/etc/containers/policy.json
文件中的镜像签名策略。要检查 registry 是否已添加到策略文件中,请在节点上使用以下命令:
cat /host/etc/containers/policy.json
$ cat /host/etc/containers/policy.json
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 以下策略表示,仅允许来自 example.com、quay.io 和 registry.redhat.io registry 中的镜像拉取和推送镜像:
例 9.1. 镜像签名策略文件示例
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
如果您的集群使用 registrySources.insecureRegistries
参数,请确保将任何不安全的 registry 包含在允许的列表中。
例如: