allowedRegistriesForImport
image.config.openshift.io/cluster
资源保存关于如何处理镜像的集群范围信息。规范的且唯一有效的名称是 cluster
。其 spec
提供以下配置参数。
诸如 |
参数 | 描述 |
---|---|
|
限制普通用户可以从中导入镜像的容器镜像注册表。将此列表设置为您信任包含有效镜像并希望应用程序能够从中导入镜像的注册表。拥有权限从 API 创建镜像或 此列表的每个元素都包含由注册表域名指定的注册表位置。
|
|
对包含在 此配置映射的命名空间为 |
|
提供默认外部镜像注册表的主机名。只有当镜像注册表在外部公开时,才应设置外部主机名。第一个值用于镜像流中的 |
|
包含确定容器运行时在访问构建和 Pod 的镜像时如何处理各个注册表的配置。例如,是否允许不安全访问。它不包含内部集群注册表的配置。
可以设置 |
当定义 |
image.config.openshift.io/cluster
资源的status
字段保存来自集群的观察值。
参数 | 描述 |
---|---|
|
由镜像注册表操作符设置,它控制 |
|
由镜像注册表操作符设置,当镜像注册表在外部公开时,提供其外部主机名。第一个值用于镜像流中的 |
您可以通过编辑image.config.openshift.io/cluster
自定义资源 (CR) 来配置镜像注册表设置。当对注册表的更改应用于image.config.openshift.io/cluster
CR 时,机器配置操作符 (MCO) 会执行以下顺序操作:
隔离节点
通过重启 CRI-O 来应用更改
取消隔离节点
MCO 在检测到更改时不会重启节点。 |
编辑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 (1)
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: (2)
- domainName: quay.io
insecure: false
additionalTrustedCA: (3)
name: myconfigmap
registrySources: (4)
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
1 | Image :保存关于如何处理镜像的集群范围信息。规范且唯一有效的名称是cluster 。 |
2 | allowedRegistriesForImport :限制普通用户可以从中导入镜像的容器镜像注册表。将此列表设置为您信任的包含有效镜像并希望应用程序能够从中导入镜像的注册表。具有权限从 API 创建镜像或ImageStreamMappings 的用户不受此策略的影响。通常只有集群管理员具有相应的权限。 |
3 | additionalTrustedCA :对包含在镜像流导入、Pod 镜像拉取、openshift-image-registry 拉取和构建期间受信任的额外证书颁发机构 (CA) 的配置映射的引用。此配置映射的命名空间为openshift-config 。配置映射的格式是:对于每个需要信任的额外注册表 CA,使用注册表主机名作为键,使用 PEM 证书作为值。 |
4 | registrySources :包含确定容器运行时在访问构建和 Pod 的镜像时是否允许或阻止各个注册表的配置。可以设置allowedRegistries 参数或blockedRegistries 参数,但不能同时设置两者。您还可以定义是否允许访问不安全的注册表或使用镜像短名称的注册表。此示例使用allowedRegistries 参数,该参数定义允许使用的注册表。不安全的注册表insecure.com 也被允许。registrySources 参数不包含内部集群注册表的配置。 |
当定义 使用 应避免使用不安全的外部注册表,以减少可能的安全风险。 |
要检查更改是否已应用,请列出您的节点
$ oc get nodes
NAME STATUS ROLES AGE VERSION
ip-10-0-137-182.us-east-2.compute.internal Ready,SchedulingDisabled worker 65m v1.30.3
ip-10-0-139-120.us-east-2.compute.internal Ready,SchedulingDisabled control-plane 74m v1.30.3
ip-10-0-176-102.us-east-2.compute.internal Ready control-plane 75m v1.30.3
ip-10-0-188-96.us-east-2.compute.internal Ready worker 65m v1.30.3
ip-10-0-200-59.us-east-2.compute.internal Ready worker 63m v1.30.3
ip-10-0-223-123.us-east-2.compute.internal Ready control-plane 73m v1.30.3
您可以添加一个注册表列表(以及可选的注册表中的单个资源库),这些注册表允许进行镜像拉取和推送操作,方法是编辑image.config.openshift.io/cluster
自定义资源 (CR)。OpenShift Container Platform 将此 CR 的更改应用于集群中的所有节点。
拉取或推送镜像时,容器运行时会在image.config.openshift.io/cluster
CR 中的registrySources
参数下列出的注册表中搜索。如果您在allowedRegistries
参数下创建了一个注册表列表,则容器运行时将只搜索这些注册表。列表中不存在的注册表将被阻止。
当定义 |
编辑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: (1)
allowedRegistries: (2)
- 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
1 | 包含决定容器运行时在访问构建和 Pod 的镜像时如何处理各个镜像仓库的配置。它不包含内部集群镜像仓库的配置。 |
2 | 指定用于镜像拉取和推送操作的镜像仓库,以及可选地指定该仓库中的镜像库。所有其他镜像仓库都会被阻止。 |
可以设置 |
机器配置操作符 (MCO) 监视image.config.openshift.io/cluster
资源中注册表的任何更改。当 MCO 检测到更改时,它会将节点 drain,应用更改,然后取消 cordon 节点。节点返回到Ready
状态后,将使用允许的注册表列表更新每个节点上的/etc/containers/policy.json
文件中的镜像签名策略。
输入以下命令以获取节点列表
$ oc get nodes
示例输出
NAME STATUS ROLES AGE VERSION
<node_name> Ready control-plane,master 37m v1.27.8+4fab27b
运行以下命令以在节点上进入调试模式
$ oc debug node/<node_name>
出现提示时,在终端中输入chroot /host
sh-4.4# chroot /host
输入以下命令以检查是否已将镜像仓库添加到策略文件中
sh-5.1# cat /etc/containers/policy.json | jq '.'
以下策略指示仅允许从 example.com、quay.io 和 registry.redhat.io 镜像仓库拉取和推送镜像
{
"default":[
{
"type":"reject"
}
],
"transports":{
"atomic":{
"example.com":[
{
"type":"insecureAcceptAnything"
}
],
"image-registry.openshift-image-registry.svc:5000":[
{
"type":"insecureAcceptAnything"
}
],
"insecure.com":[
{
"type":"insecureAcceptAnything"
}
],
"quay.io":[
{
"type":"insecureAcceptAnything"
}
],
"reg4.io/myrepo/myapp:latest":[
{
"type":"insecureAcceptAnything"
}
],
"registry.redhat.io":[
{
"type":"insecureAcceptAnything"
}
]
},
"docker":{
"example.com":[
{
"type":"insecureAcceptAnything"
}
],
"image-registry.openshift-image-registry.svc:5000":[
{
"type":"insecureAcceptAnything"
}
],
"insecure.com":[
{
"type":"insecureAcceptAnything"
}
],
"quay.io":[
{
"type":"insecureAcceptAnything"
}
],
"reg4.io/myrepo/myapp:latest":[
{
"type":"insecureAcceptAnything"
}
],
"registry.redhat.io":[
{
"type":"insecureAcceptAnything"
}
]
},
"docker-daemon":{
"":[
{
"type":"insecureAcceptAnything"
}
]
}
}
}
如果您的集群使用 例如
|
您可以通过编辑image.config.openshift.io/cluster
自定义资源 (CR) 来阻止任何镜像仓库,以及可选地阻止镜像仓库中的单个镜像库。OpenShift Container Platform 会将对该 CR 的更改应用于集群中的所有节点。
拉取或推送镜像时,容器运行时会在image.config.openshift.io/cluster
CR 的registrySources
参数下列出的镜像仓库中搜索。如果您在blockedRegistries
参数下创建了镜像仓库列表,则容器运行时不会搜索这些镜像仓库。所有其他镜像仓库都是允许的。
为避免 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: (1)
blockedRegistries: (2)
- untrusted.com
- reg1.io/myrepo/myapp:latest
status:
internalRegistryHostname: image-registry.openshift-image-registry.svc:5000
1 | 包含决定容器运行时在访问构建和 Pod 的镜像时如何处理各个镜像仓库的配置。它不包含内部集群镜像仓库的配置。 |
2 | 指定不应用于镜像拉取和推送操作的镜像仓库,以及可选地指定该仓库中的镜像库。所有其他镜像仓库都是允许的。 |
可以设置 |
机器配置操作符 (MCO) 监视image.config.openshift.io/cluster
资源中注册表的任何更改。当 MCO 检测到更改时,它会将节点 drain,应用更改,然后取消 cordon 节点。节点返回到Ready
状态后,对阻止的注册表的更改将显示在每个节点上的/etc/containers/registries.conf
文件中。
输入以下命令以获取节点列表
$ oc get nodes
示例输出
NAME STATUS ROLES AGE VERSION
<node_name> Ready control-plane,master 37m v1.27.8+4fab27b
运行以下命令以在节点上进入调试模式
$ oc debug node/<node_name>
出现提示时,在终端中输入chroot /host
sh-4.4# chroot /host
输入以下命令以检查是否已将镜像仓库添加到策略文件中
sh-5.1# cat etc/containers/registries.conf
以下示例表明阻止从untrusted.com
镜像仓库拉取和推送镜像
unqualified-search-registries = ["registry.access.redhat.com", "docker.io"]
[[registry]]
prefix = ""
location = "untrusted.com"
blocked = true
在镜像配置中,您可以使用ImageContentSourcePolicy
(ICSP) 对象在断开连接的环境中阻止上游有效负载镜像仓库。以下示例过程演示了如何阻止quay.io/openshift-payload
有效负载镜像仓库。
使用ImageContentSourcePolicy
(ICSP) 对象创建镜像配置以将有效负载镜像到实例中的镜像仓库。以下 ICSP 文件示例将有效负载镜像到internal-mirror.io/openshift-payload
apiVersion: operator.openshift.io/v1alpha1
kind: ImageContentSourcePolicy
metadata:
name: my-icsp
spec:
repositoryDigestMirrors:
- mirrors:
- internal-mirror.io/openshift-payload
source: quay.io/openshift-payload
对象部署到节点后,通过检查/etc/containers/registries.conf
文件来验证是否已设置镜像配置
[[registry]]
prefix = ""
location = "quay.io/openshift-payload"
mirror-by-digest-only = true
[[registry.mirror]]
location = "internal-mirror.io/openshift-payload"
使用以下命令编辑image.config.openshift.io
自定义资源文件
$ oc edit image.config.openshift.io cluster
要阻止有效负载镜像仓库,请将以下配置添加到image.config.openshift.io
自定义资源文件中
spec:
registrySources:
blockedRegistries:
- quay.io/openshift-payload
通过检查节点上的/etc/containers/registries.conf
文件,验证上游有效负载镜像仓库是否被阻止。
[[registry]]
prefix = ""
location = "quay.io/openshift-payload"
blocked = true
mirror-by-digest-only = true
[[registry.mirror]]
location = "internal-mirror.io/openshift-payload"
您可以通过编辑image.config.openshift.io/cluster
自定义资源 (CR) 来添加不安全的镜像仓库,以及可选地添加镜像仓库中的单个镜像库。OpenShift Container Platform 会将对该 CR 的更改应用于集群中的所有节点。
不使用有效 SSL 证书或不需要 HTTPS 连接的镜像仓库被认为是不安全的。
应避免使用不安全的外部注册表,以减少可能的安全风险。 |
编辑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: (1)
insecureRegistries: (2)
- insecure.com
- reg4.io/myrepo/myapp:latest
allowedRegistries:
- example.com
- quay.io
- registry.redhat.io
- insecure.com (3)
- reg4.io/myrepo/myapp:latest
- image-registry.openshift-image-registry.svc:5000
status:
internalRegistryHostname: image-registry.openshift-image-registry.svc:5000
1 | 包含决定容器运行时在访问构建和 Pod 的镜像时如何处理各个镜像仓库的配置。它不包含内部集群镜像仓库的配置。 |
2 | 指定一个不安全的镜像仓库。您可以在该镜像仓库中指定一个镜像库。 |
3 | 确保allowedRegistries 列表中包含任何不安全的镜像仓库。 |
当定义 |
机器配置操作符 (MCO) 监视image.config.openshift.io/cluster
CR 中注册表的任何更改,然后在检测到更改时 drain 和取消 cordon 节点。节点返回到Ready
状态后,对不安全和被阻止的注册表的更改将显示在每个节点上的/etc/containers/registries.conf
文件中。
要检查是否已将镜像仓库添加到策略文件中,请在节点上使用以下命令
$ cat /etc/containers/registries.conf
以下示例表明insecure.com
镜像仓库是不安全的,并且允许拉取和推送镜像。
unqualified-search-registries = ["registry.access.redhat.com", "docker.io"]
[[registry]]
prefix = ""
location = "insecure.com"
insecure = true
您可以通过编辑image.config.openshift.io/cluster
自定义资源 (CR) 来添加要搜索镜像短名称的镜像仓库。OpenShift Container Platform 会将对该 CR 的更改应用于集群中的所有节点。
镜像短名称使您可以搜索镜像,而无需在拉取规范中包含完全限定域名。例如,您可以使用rhel7/etcd
而不是registry.access.redhat.com/rhe7/etcd
。
在使用完整路径不切实际的情况下,您可能会使用短名称。例如,如果您的集群引用多个内部镜像仓库,其 DNS 频繁更改,则需要在每次更改时更新拉取规范中的完全限定域名。在这种情况下,使用镜像短名称可能会有益。
拉取或推送镜像时,容器运行时会在image.config.openshift.io/cluster
CR 的registrySources
参数下列出的镜像仓库中搜索。如果您在containerRuntimeSearchRegistries
参数下创建了镜像仓库列表,则在使用短名称拉取镜像时,容器运行时会搜索这些镜像仓库。
强烈建议不要将镜像短名称与公共镜像仓库一起使用,因为如果公共镜像仓库需要身份验证,则镜像可能无法部署。对公共镜像仓库使用完全限定的镜像名称。 Red Hat 内部或专用镜像仓库通常支持使用镜像短名称。 如果您在 如果每个公共镜像仓库都需要不同的凭据,并且集群未在全局拉取密钥中列出公共镜像仓库,则不能在 对于需要身份验证的公共镜像仓库,只有在镜像仓库的凭据存储在全局拉取密钥中时,才能使用镜像短名称。 |
机器配置操作符 (MCO) 监控image.config.openshift.io/cluster
资源中的任何注册表更改。当 MCO 检测到更改时,它会将节点 drain(排干),应用更改,然后取消 cordon(隔离)节点。节点恢复到Ready
状态后,如果添加了containerRuntimeSearchRegistries
参数,MCO 就会在每个节点的/etc/containers/registries.conf.d
目录中创建一个包含列出注册表的文件。该文件会覆盖/etc/containers/registries.conf
文件中未限定搜索注册表的默认列表。无法回退到未限定搜索注册表的默认列表。
containerRuntimeSearchRegistries
参数仅适用于 Podman 和 CRI-O 容器引擎。列表中的注册表只能用于 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:
allowedRegistriesForImport:
- domainName: quay.io
insecure: false
additionalTrustedCA:
name: myconfigmap
registrySources:
containerRuntimeSearchRegistries: (1)
- reg1.io
- reg2.io
- reg3.io
allowedRegistries: (2)
- example.com
- quay.io
- registry.redhat.io
- reg1.io
- reg2.io
- reg3.io
- image-registry.openshift-image-registry.svc:5000
...
status:
internalRegistryHostname: image-registry.openshift-image-registry.svc:5000
1 | 指定用于镜像短名称的注册表。您应该仅对内部或私有注册表使用镜像短名称,以降低可能的安全风险。 |
2 | 确保containerRuntimeSearchRegistries 下列出的任何注册表都包含在allowedRegistries 列表中。 |
当定义 |
输入以下命令以获取节点列表
$ oc get nodes
示例输出
NAME STATUS ROLES AGE VERSION
<node_name> Ready control-plane,master 37m v1.27.8+4fab27b
运行以下命令以在节点上进入调试模式
$ oc debug node/<node_name>
出现提示时,在终端中输入chroot /host
sh-4.4# chroot /host
输入以下命令以检查是否已将镜像仓库添加到策略文件中
sh-5.1# cat /etc/containers/registries.conf.d/01-image-searchRegistries.conf
unqualified-search-registries = ['reg1.io', 'reg2.io', 'reg3.io']
image.config.openshift.io/cluster
自定义资源可以包含对包含其他证书颁发机构(用于在访问镜像注册表时受信任)的配置映射的引用。
证书颁发机构 (CA) 必须是 PEM 编码的。
您可以在openshift-config
命名空间中创建一个配置映射,并在image.config.openshift.io
自定义资源中的AdditionalTrustedCA
中使用其名称,以提供在联系外部注册表时应受信任的其他 CA。
配置映射键是具有端口的注册表的 hostname,为此 CA 应受信任,而 PEM 证书内容是每个其他注册表 CA 的值。
apiVersion: v1
kind: ConfigMap
metadata:
name: my-registry-ca
data:
registry.example.com: |
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
registry-with-port.example.com..5000: | (1)
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
1 | 如果注册表具有端口,例如registry-with-port.example.com:5000 ,则应将: 替换为.. 。 |
您可以按照以下步骤配置其他 CA。
配置其他 CA
$ oc create configmap registry-config --from-file=<external_registry_address>=ca.crt -n openshift-config
$ oc edit image.config.openshift.io cluster
spec:
additionalTrustedCA:
name: registry-config
设置容器注册表仓库镜像使您可以执行以下任务
配置您的 OpenShift Container Platform 集群以重定向请求,从源镜像注册表上的仓库拉取镜像,并使其由镜像镜像注册表上的仓库解析。
为每个目标仓库识别多个镜像仓库,以确保如果一个镜像不可用,则可以使用另一个镜像。
OpenShift Container Platform 中的仓库镜像包括以下属性
镜像拉取能够抵抗注册表停机。
断开连接的环境中的集群可以从关键位置(例如 quay.io)拉取镜像,并让公司防火墙后的注册表提供请求的镜像。
发出镜像拉取请求时,会尝试特定的注册表顺序,永久注册表通常是最后尝试的一个。
您输入的镜像信息将添加到 OpenShift Container Platform 集群中每个节点上的/etc/containers/registries.conf
文件中。
当节点从源仓库请求镜像时,它会依次尝试每个镜像仓库,直到找到请求的内容。如果所有镜像都失败,集群将尝试源仓库。如果成功,则将镜像拉取到节点。
设置仓库镜像可以通过以下方式完成
在 OpenShift Container Platform 安装时
通过拉取 OpenShift Container Platform 所需的容器镜像,然后将这些镜像置于公司防火墙之后,您可以将 OpenShift Container Platform 安装到处于断开连接环境的数据中心中。
OpenShift Container Platform 安装后
如果您在 OpenShift Container Platform 安装期间未配置镜像,则可以在安装后使用以下任何自定义资源 (CR) 对象进行配置
ImageDigestMirrorSet
(IDMS)。此对象允许您使用摘要规范从镜像注册表拉取镜像。IDMS CR 使您可以设置回退策略,如果镜像拉取失败,则允许或停止继续尝试从源注册表拉取。
ImageTagMirrorSet
(ITMS)。此对象允许您使用镜像标签从镜像注册表拉取镜像。ITMS CR 使您可以设置回退策略,如果镜像拉取失败,则允许或停止继续尝试从源注册表拉取。
ImageContentSourcePolicy
(ICSP)。此对象允许您使用摘要规范从镜像注册表拉取镜像。如果镜像不可用,ICSP CR 将始终回退到源注册表。
使用 |
每个自定义资源对象都标识以下信息
要镜像的容器镜像仓库的来源。
您要为从源仓库请求的内容提供的每个镜像仓库的单独条目。
对于新的集群,您可以根据需要使用 IDMS、ITMS 和 ICSP CR 对象。但是,建议使用 IDMS 和 ITMS。
如果您升级了集群,任何现有的 ICSP 对象都保持稳定,并且 IDMS 和 ICSP 对象都受支持。使用 ICSP 对象的工作负载将继续按预期运行。但是,如果您想利用 IDMS CR 中引入的回退策略,您可以使用oc adm migrate icsp
命令将当前工作负载迁移到 IDMS 对象,如下面的**转换用于镜像注册表镜像的 ImageContentSourcePolicy (ICSP) 文件**部分所示。迁移到 IDMS 对象不需要重新启动集群。
如果您的集群使用 |
有关全局拉取密钥的更多信息,请参阅更新全局集群拉取密钥。
您可以创建安装后镜像配置自定义资源 (CR) 以将镜像拉取请求从源镜像注册表重定向到镜像镜像注册表。
以具有cluster-admin
角色的用户身份访问集群。
配置镜像仓库,方法如下:
设置使用 Red Hat Quay 的镜像仓库,如Red Hat Quay 仓库镜像中所述。使用 Red Hat Quay,您可以将镜像从一个仓库复制到另一个仓库,并随着时间的推移自动重复同步这些仓库。
使用skopeo
等工具手动将镜像从源仓库复制到镜像仓库。
例如,在 Red Hat Enterprise Linux (RHEL) 7 或 RHEL 8 系统上安装 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
的容器镜像注册表,其中有一个名为example
的镜像仓库,您希望将ubi9/ubi-minimal
镜像从registry.access.redhat.com
复制到该仓库。创建镜像注册表后,您可以配置 OpenShift Container Platform 集群以将对源仓库的请求重定向到镜像仓库。
创建安装后镜像配置 CR,方法是使用以下示例之一
根据需要创建ImageDigestMirrorSet
或ImageTagMirrorSet
CR,将源和镜像替换为您自己的注册表和仓库对以及镜像
apiVersion: config.openshift.io/v1 (1)
kind: ImageDigestMirrorSet (2)
metadata:
name: ubi9repo
spec:
imageDigestMirrors: (3)
- mirrors:
- example.io/example/ubi-minimal (4)
- example.com/example/ubi-minimal (5)
source: registry.access.redhat.com/ubi9/ubi-minimal (6)
mirrorSourcePolicy: AllowContactingSource (7)
- mirrors:
- mirror.example.com/redhat
source: registry.example.com/redhat (8)
mirrorSourcePolicy: AllowContactingSource
- mirrors:
- mirror.example.com
source: registry.example.com (9)
mirrorSourcePolicy: AllowContactingSource
- mirrors:
- mirror.example.net/image
source: registry.example.com/example/myimage (10)
mirrorSourcePolicy: AllowContactingSource
- mirrors:
- mirror.example.net
source: registry.example.com/example (11)
mirrorSourcePolicy: AllowContactingSource
- mirrors:
- mirror.example.net/registry-example-com
source: registry.example.com (12)
mirrorSourcePolicy: AllowContactingSource
1 | 指示要与此 CR 一起使用的 API。这必须是config.openshift.io/v1 。 |
2 | 根据拉取类型指示对象的类型
|
3 | 指示镜像拉取方法的类型,即:
|
4 | 指示镜像镜像注册表和仓库的名称。 |
5 | 可选:为每个目标仓库指示辅助镜像仓库。如果一个镜像不可用,目标仓库可以使用辅助镜像。 |
6 | 指示注册表和仓库源,即镜像拉取规范中引用的仓库。 |
7 | 可选:指示如果镜像拉取失败的回退策略
|
8 | 可选:指示注册表内的命名空间,允许您使用该命名空间中的任何镜像。如果您使用注册表域名作为源,则该对象将应用于该注册表中的所有仓库。 |
9 | 可选:指示注册表,允许您使用该注册表中的任何镜像。如果您指定注册表名称,则该对象将应用于从源注册表到镜像注册表的所有仓库。 |
10 | 从镜像mirror.example.net/image@sha256:.. 拉取镜像registry.example.com/example/myimage@sha256:… 。 |
11 | 从镜像mirror.example.net/image@sha256:… 拉取源注册表命名空间中的镜像registry.example.com/example/image@sha256:… 。 |
12 | 从镜像注册表example.net/registry-example-com/myimage@sha256:… 拉取镜像registry.example.com/myimage@sha256 。 |
创建一个ImageContentSourcePolicy
自定义资源,将源和镜像替换为您自己的注册表和仓库对以及镜像
apiVersion: operator.openshift.io/v1alpha1
kind: ImageContentSourcePolicy
metadata:
name: mirror-ocp
spec:
repositoryDigestMirrors:
- mirrors:
- mirror.registry.com:443/ocp/release (1)
source: quay.io/openshift-release-dev/ocp-release (2)
- mirrors:
- mirror.registry.com:443/ocp/release
source: quay.io/openshift-release-dev/ocp-v4.0-art-dev
1 | 指定镜像镜像注册表和仓库的名称。 |
2 | 指定包含要镜像的内容的在线注册表和仓库。 |
创建新对象
$ oc create -f registryrepomirror.yaml
创建对象后,机器配置操作员 (MCO) 只会为ImageTagMirrorSet
对象清空节点。MCO 不会为ImageDigestMirrorSet
和ImageContentSourcePolicy
对象清空节点。
要检查是否应用了镜像配置设置,请在其中一个节点上执行以下操作。
列出您的节点
$ oc get node
NAME STATUS ROLES AGE VERSION
ip-10-0-137-44.ec2.internal Ready worker 7m v1.30.3
ip-10-0-138-148.ec2.internal Ready master 11m v1.30.3
ip-10-0-139-122.ec2.internal Ready master 11m v1.30.3
ip-10-0-147-35.ec2.internal Ready worker 7m v1.30.3
ip-10-0-153-12.ec2.internal Ready worker 7m v1.30.3
ip-10-0-154-10.ec2.internal Ready master 11m v1.30.3
启动调试过程以访问节点
$ 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`
将根目录更改为/host
sh-4.2# chroot /host
检查/etc/containers/registries.conf
文件,确保已进行更改
sh-4.2# cat /etc/containers/registries.conf
以下输出表示应用了安装后镜像配置 CR 的registries.conf
文件。最后两个条目分别标记为digest-only
和tag-only
。
unqualified-search-registries = ["registry.access.redhat.com", "docker.io"]
short-name-mode = ""
[[registry]]
prefix = ""
location = "registry.access.redhat.com/ubi9/ubi-minimal" (1)
[[registry.mirror]]
location = "example.io/example/ubi-minimal" (2)
pull-from-mirror = "digest-only" (3)
[[registry.mirror]]
location = "example.com/example/ubi-minimal"
pull-from-mirror = "digest-only"
[[registry]]
prefix = ""
location = "registry.example.com"
[[registry.mirror]]
location = "mirror.example.net/registry-example-com"
pull-from-mirror = "digest-only"
[[registry]]
prefix = ""
location = "registry.example.com/example"
[[registry.mirror]]
location = "mirror.example.net"
pull-from-mirror = "digest-only"
[[registry]]
prefix = ""
location = "registry.example.com/example/myimage"
[[registry.mirror]]
location = "mirror.example.net/image"
pull-from-mirror = "digest-only"
[[registry]]
prefix = ""
location = "registry.example.com"
[[registry.mirror]]
location = "mirror.example.com"
pull-from-mirror = "digest-only"
[[registry]]
prefix = ""
location = "registry.example.com/redhat"
[[registry.mirror]]
location = "mirror.example.com/redhat"
pull-from-mirror = "digest-only"
[[registry]]
prefix = ""
location = "registry.access.redhat.com/ubi9/ubi-minimal"
blocked = true (4)
[[registry.mirror]]
location = "example.io/example/ubi-minimal-tag"
pull-from-mirror = "tag-only" (5)
1 | 指示在拉取规范中引用的仓库。 |
2 | 指示该仓库的镜像。 |
3 | 指示从镜像的镜像拉取是摘要引用镜像。 |
4 | 指示为此仓库设置了NeverContactSource 参数。 |
5 | 指示从镜像的镜像拉取是标签引用镜像。 |
将镜像从源拉取到节点,并检查它是否由镜像解析。
sh-4.2# podman pull --log-level=debug registry.access.redhat.com/ubi9/ubi-minimal@sha256:5cf...
如果仓库镜像过程未按描述进行,请使用以下有关仓库镜像工作原理的信息来帮助解决问题。
第一个可用的镜像用于提供拉取的镜像。
只有在没有其他镜像可用时,才使用主注册表。
从系统上下文来看,Insecure
标志用作回退。
/etc/containers/registries.conf
文件的格式最近已更改。它现在是版本 2,采用 TOML 格式。
使用ImageContentSourcePolicy
(ICSP) 对象配置仓库镜像是一个已弃用的功能。此功能仍包含在 OpenShift Container Platform 中并继续受支持;但是,它将在该产品的未来版本中删除,不推荐用于新部署。
ICSP 对象正在被ImageDigestMirrorSet
和ImageTagMirrorSet
对象替换以配置仓库镜像。如果您有用于创建ImageContentSourcePolicy
对象的现有 YAML 文件,则可以使用oc adm migrate icsp
命令将这些文件转换为ImageDigestMirrorSet
YAML 文件。该命令会将 API 更新到当前版本,将kind
值更改为ImageDigestMirrorSet
,并将spec.repositoryDigestMirrors
更改为spec.imageDigestMirrors
。文件的其余部分不会更改。
由于迁移不会更改registries.conf
文件,因此集群不需要重新启动。
有关ImageDigestMirrorSet
或ImageTagMirrorSet
对象的更多信息,请参阅上一节中的“配置镜像注册表仓库镜像”。
以具有cluster-admin
角色的用户身份访问集群。
确保您的集群上有ImageContentSourcePolicy
对象。
使用以下命令将一个或多个ImageContentSourcePolicy
YAML 文件转换为ImageDigestMirrorSet
YAML 文件
$ oc adm migrate icsp <file_name>.yaml <file_name>.yaml <file_name>.yaml --dest-dir <path_to_the_directory>
其中
<file_name>
指定源ImageContentSourcePolicy
YAML 文件的名称。您可以列出多个文件名。
--dest-dir
可选:指定输出ImageDigestMirrorSet
YAML 文件的目录。如果未设置,则文件将写入当前目录。
例如,以下命令转换icsp.yaml
和icsp-2.yaml
文件并将新的YAML文件保存到idms-files
目录。
$ oc adm migrate icsp icsp.yaml icsp-2.yaml --dest-dir idms-files
wrote ImageDigestMirrorSet to idms-files/imagedigestmirrorset_ubi8repo.5911620242173376087.yaml
wrote ImageDigestMirrorSet to idms-files/imagedigestmirrorset_ubi9repo.6456931852378115011.yaml
运行以下命令创建 CR 对象
$ oc create -f <path_to_the_directory>/<file-name>.yaml
其中
<path_to_the_directory>
如果您使用了--dest-dir
标志,则指定目录的路径。
<file_name>
指定ImageDigestMirrorSet
YAML 文件的名称。
在 IDMS 对象推出后,移除 ICSP 对象。