13.4. 在没有 OpenShift Update Service 的断开连接的环境中更新集群
使用以下步骤在断开连接的环境中更新集群,而无需访问 OpenShift Update Service。
13.4.1. 先决条件
-
您必须安装了
oc命令行界面(CLI)工具。 - 您必须使用容器镜像置备本地容器镜像 registry,如镜像 OpenShift Container Platform 镜像存储库 中所述。
-
您必须可以使用具有
admin权限的用户访问集群。请参阅使用 RBAC 定义和应用权限。 - 您需要具有最新的 etcd 备份,以防因为升级失败需要将集群恢复到以前的状态。
- 确保所有机器配置池 (MCP) 都正在运行且未暂停。在更新过程中跳过与暂停 MCP 关联的节点。如果要执行 canary rollout 更新策略,可以暂停 MCP。
- 如果您的集群使用手动维护的凭证,请更新新发行版本的云供应商资源。如需更多信息,包括如何确定这是集群的要求,请参阅准备使用手动维护的凭证更新集群。
-
如果您运行 Operator 或您已配置了 pod 中断预算,您可能会在升级过程中遇到中断。如果在
PodDisruptionBudget中将minAvailable设置为 1,则节点会排空以应用可能会阻止驱除过程的待处理机器配置。如果重启了几个节点,则所有 pod 只能有一个节点上运行,PodDisruptionBudget字段可能会阻止节点排空。
如果您运行 Operator 或您已配置了 pod 中断预算,您可能会在升级过程中遇到中断。如果在 PodDisruptionBudget 中将 minAvailable 设置为 1,则节点会排空以应用可能会阻止驱除过程的待处理机器配置。如果重启了几个节点,则所有 pod 只能有一个节点上运行,PodDisruptionBudget 字段可能会阻止节点排空。
13.4.2. 暂停 MachineHealthCheck 资源
在升级过程中,集群中的节点可能会临时不可用。对于 worker 节点,机器健康检查可能会认为这样的节点不健康,并重新引导它们。为避免重新引导这样的节点,请在更新集群前暂停所有 MachineHealthCheck 资源。
先决条件
-
安装 OpenShift CLI (
oc) 。
流程
要列出您要暂停的所有可用
MachineHealthCheck资源,请运行以下命令:$ oc get machinehealthcheck -n openshift-machine-api
要暂停机器健康检查,请将
cluster.x-k8s.io/paused=""注解添加到MachineHealthCheck资源。运行以下命令:$ oc -n openshift-machine-api annotate mhc <mhc-name> cluster.x-k8s.io/paused=""
注解的
MachineHealthCheck资源类似以下 YAML 文件:apiVersion: machine.openshift.io/v1beta1 kind: MachineHealthCheck metadata: name: example namespace: openshift-machine-api annotations: cluster.x-k8s.io/paused: "" spec: selector: matchLabels: role: worker unhealthyConditions: - type: "Ready" status: "Unknown" timeout: "300s" - type: "Ready" status: "False" timeout: "300s" maxUnhealthy: "40%" status: currentHealthy: 5 expectedMachines: 5重要更新集群后恢复机器健康检查。要恢复检查,请运行以下命令从
MachineHealthCheck资源中删除暂停注解:$ oc -n openshift-machine-api annotate mhc <mhc-name> cluster.x-k8s.io/paused-
13.4.3. 检索发行镜像摘要
要使用 oc adm upgrade 命令和 --to-image 选项在断开连接的环境中更新集群,您必须引用与目标发行镜像对应的 sha256 摘要。
流程
在连接到互联网的设备中运行以下命令:
$ oc adm release info -o 'jsonpath={.digest}{"\n"}' quay.io/openshift-release-dev/ocp-release:${OCP_RELEASE_VERSION}-${ARCHITECTURE}对于
{OCP_RELEASE_VERSION},请指定您要更新的 OpenShift Container Platform 版本,如4.10.16。对于
{ARCHITECTURE},请指定集群的构架,如x86_64,aarch64,s390x, 或ppc64le。输出示例
sha256:a8bfba3b6dddd1a2fbbead7dac65fe4fb8335089e4e7cae327f3bad334add31d
- 复制在更新集群时要使用的 sha256 摘要。
13.4.4. 更新断开连接的集群
将受限网络集群更新至您下载的发行镜像的 OpenShift Container Platform 版本。
如果您有一个本地 OpenShift Update Service,您可以使用连接的 Web 控制台或 CLI 指令来更新,而不是使用此流程。
先决条件
- 您已将新发行版本的镜像镜像(mirror)到 registry。
您已将发行镜像签名 ConfigMap 在新发行版本中应用到集群。
注意发行镜像签名配置映射允许 Cluster Version Operator (CVO) 通过验证实际镜像签名是否与预期的签名匹配来确保发行镜像的完整性。
- 获取目标发行镜像的 sha256 摘要。
-
已安装 OpenShift CLI(
oc)。 -
您暂停所有
MachineHealthCheck资源。
流程
更新集群:
$ oc adm upgrade --allow-explicit-upgrade --to-image ${LOCAL_REGISTRY}/${LOCAL_REPOSITORY}@<digest> 1- 1
<digest>值是目标发行镜像的 sha256 摘要,例如sha256:81154f5c03294534e1eaf0319bef7a601134f891689ccede5d705ef659aa8c92
如果镜像 registry 使用
ImageContentSourcePolicy,可以使用 Canonical registry 名称而非LOCAL_REGISTRY。注意您只能为具有
ImageContentSourcePolicy对象的集群配置全局 pull secret。您不能在项目中添加 pull secret。
13.4.5. 配置镜像 registry 存储库镜像
通过设置容器 registry 存储库镜像,您可以执行以下任务:
- 配置 OpenShift Container Platform 集群,以便重定向从源镜像 registry 上的存储库拉取(pull)镜像的请求,并通过已镜像 (mirror) 的镜像 registry 上的存储库来解决该请求。
- 为每个目标存储库识别多个已镜像 (mirror)的存储库,以确保如果一个镜像停止运作,仍可使用其他镜像。
OpenShift Container Platform 中的存储库镜像包括以下属性:
- 镜像拉取(pull)可应对 registry 停机的问题。
- 在断开连接的环境中的集群可以从关键位置(如 quay.io)拉取镜像,并让公司防火墙后面的 registry 提供请求的镜像。
- 发出镜像拉取(pull)请求时尝试特定 registry 顺序,通常最后才会尝试持久性 registry。
-
您所输入的镜像信息会添加到 OpenShift Container Platform 集群中每个节点上的
/etc/containers/registries.conf文件中。 - 当节点从源存储库中请求镜像时,它会依次尝试每个已镜像的存储库,直到找到所请求的内容。如果所有镜像均失败,集群则会尝试源存储库。如果成功,则镜像拉取至节点中。
可通过以下方式设置存储库镜像:
在 OpenShift Container Platform 安装中:
通过拉取(pull) OpenShift Container Platform 所需的容器镜像,然后将这些镜像放至公司防火墙后,即可将 OpenShift Container Platform 安装到受限网络中的数据中心。
安装 OpenShift Container Platform 后:
如果您没有在 OpenShift Container Platform 安装过程中配置镜像,您可以在安装后使用以下自定义资源 (CR) 对象之一:
-
ImageDigestMirrorSet.此 CR 允许您使用摘要规格从镜像 registry 中拉取镜像。 -
ImageTagMirrorSet.此 CR 允许您使用镜像标签从已镜像的 registry 中拉取镜像。
重要使用
ImageContentSourcePolicy(ICSP)对象配置存储库镜像是一个已弃用的功能。弃用的功能仍然包含在 OpenShift Container Platform 中,并将继续被支持。但是,这个功能会在以后的发行版本中被删除,且不建议在新的部署中使用。如果您有用于创建ImageContentSourcePolicy对象的 YAML 文件,您可以使用oc adm migrate icsp命令将这些文件转换为ImageDigestMirrorSetYAML 文件。如需更多信息,请参阅以下部分"协调 ImageContentSourcePolicy (ICSP)文件以进行镜像 registry 存储库镜像"。-
这两个自定义资源对象都标识以下信息:
- 您希望镜像 (mirror) 的容器镜像存储库的源。
- 您希望为其提供从源存储库请求的内容的每个镜像存储库的单独条目。
如果您的集群使用 ImageDigestMirrorSet 或 ImageTagMirrorSet 对象来配置存储库镜像,则只能将全局 pull secret 用于镜像 registry。您不能在项目中添加 pull secret。
以下流程创建安装后镜像配置,您可以在其中创建 ImageDigestMirrorSet 对象。
先决条件
-
确保可以使用具有
cluster-admin角色的用户访问集群。 确保集群中没有
ImageContentSourcePolicy对象。例如,您可以使用以下命令:$ oc get ImageContentSourcePolicy
输出示例
No resources found
流程
通过以下方法配置已镜像的存储库:
- 按照 Red Hat Quay 存储库镜像中所述,使用 Red Hat Quay 来设置已镜像的存储库。使用 Red Hat Quay 有助于您将镜像从一个存储库复制到另一存储库,并可随着时间的推移重复自动同步这些存储库。
使用
skopeo等工具手动将镜像从源目录复制到已镜像的存储库。例如:在 Red Hat Enterprise Linux(RHEL 7 或 RHEL 8)系统上安装 skopeo RPM 软件包后,使用
skopeo命令,如下例所示:$ skopeo copy \ docker://registry.access.redhat.com/ubi9/ubi-minimal:latest@sha256:5cf... \ docker://example.io/example/ubi-minimal
在本例中,您有一个名为
example.io的容器镜像 registry,其中包含一个名为example的镜像存储库,您要将ubi9/ubi-minimal镜像从registry.access.redhat.com复制到其中。创建该 registry 后,您可将 OpenShift Container Platform 集群配置为将源存储库的请求重定向到已镜像的存储库。
- 登录您的 OpenShift Container Platform 集群。
根据需要,创建一个
ImageDigestMirrorSet或ImageTagMirrorSetCR,将源和镜像(mirror)替换为您自己的 registry、存储库对和镜像: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.redhat.io/openshift4 8 mirrorSourcePolicy: AllowContactingSource - mirrors: - mirror.example.com source: registry.redhat.io 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
- 根据 pull 类型指示对象类型:
-
ImageDigestMirrorSet:提取摘要引用镜像。 -
ImageTagMirrorSet:提取标签引用镜像。
-
- 3
- 表示镜像拉取方法的类型,请执行以下任一方法:
-
imageDigestMirrors:用于ImageDigestMirrorSetCR。 -
imageTagMirrors:用于ImageTagMirrorSetCR。
-
- 4
- 指明镜像 registry 和存储库的名称。
- 5
- 可选:指定每个目标仓库的二级镜像存储库。如果一个镜像停机,则目标仓库可以使用另一个镜像。
- 6
- 指明 registry 和存储库源,这是在镜像拉取规格中引用的存储库。
- 7
- 可选:如果镜像拉取失败,则指示回退策略:
-
AllowContactingSource:允许继续尝试从源存储库拉取镜像。这是默认值。 -
NeverContactSource: 防止继续尝试从源存储库拉取镜像。
-
- 8
- 可选:指示 registry 中的命名空间,它允许您使用该命名空间中的任何镜像。如果您使用 registry 域作为源,则对象将应用到 registry 中的所有存储库。
- 9
- 可选:指示一个 registry,它允许您使用该 registry 中的任何镜像。如果指定了 registry 名称,对象将应用到源 registry 中的所有存储库到镜像 registry。
- 10
- 从 mirror
mirror.example.net/image@sha256:..拉取镜像registry.example.com/example/myimage@sha256:…。 - 11
- 从 mirror
mirror.example.net/image@sha256:…的源 registry 命名空间中拉取镜像registry.example.com/example/image@sha256:…。 - 12
- 从 mirror registry
example.net/registry-example-com/myimage@sha256:…中拉取镜像registry.example.com/myimage@sha256。ImageContentSourcePolicy资源会应用到源 registry 中的所有仓库到到 mirror registrymirror.example.net/registry-example-com。
创建新对象:
$ oc create -f registryrepomirror.yaml
创建对象后,Machine Config Operator (MCO) 会限制节点,因为新的设置被部署到每个节点。MCO 只为
ImageTagMirrorSet对象重启节点。MCO 不会为ImageDigestMirrorSet对象重启节点。当节点被取消封锁时,集群开始使用已镜像的存储库向源存储库发出请求。要检查是否应用了镜像的配置设置,请在其中一个节点上执行以下操作。
列出您的节点:
$ oc get node
输出示例
NAME STATUS ROLES AGE VERSION ip-10-0-137-44.ec2.internal Ready worker 7m v1.26.0 ip-10-0-138-148.ec2.internal Ready master 11m v1.26.0 ip-10-0-139-122.ec2.internal Ready master 11m v1.26.0 ip-10-0-147-35.ec2.internal Ready worker 7m v1.26.0 ip-10-0-153-12.ec2.internal Ready worker 7m v1.26.0 ip-10-0-154-10.ec2.internal Ready master 11m v1.26.0
启动调试过程以访问节点:
$ 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
以下输出代表了一个
registry.conf文件,其中应用了ImageDigestMirrorSet对象和一个ImageTagMirrorSet对象。最后的两个条目分别标记为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.redhat.io" [[registry.mirror]] location = "mirror.example.com" pull-from-mirror = "digest-only" [[registry]] prefix = "" location = "registry.redhat.io/openshift4" [[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
从源拉取镜像到节点,并检查是否通过 mirror 解析。
sh-4.2# podman pull --log-level=debug registry.access.redhat.com/ubi9/ubi-minimal@sha256:5cf...
存储库镜像故障排除
如果存储库镜像流程未按规定工作,请使用以下有关存储库镜像如何工作的信息协助排查问题。
- 首个工作镜像用于提供拉取(pull)的镜像。
- 只有在无其他镜像工作时,才会使用主 registry。
-
从系统上下文,
Insecure标志用作回退。 -
最近更改了
/etc/containers/registries.conf文件的格式。现在它是第 2 版,采用 TOML 格式。 -
您不能将同一存储库添加到
ImageDigestMirrorSet和ImageTagMirrorSet对象中。
13.4.5.1. 为镜像 registry 存储库镜像转换 ImageContentSourcePolicy (ICSP) 文件
使用 ImageContentSourcePolicy (ICSP)对象配置存储库镜像是一个已弃用的功能。此功能仍然包含在 OpenShift Container Platform 中,并将继续被支持。但是,这个功能会在以后的发行版本中被删除,且不建议在新的部署中使用。
ICSP 对象被 ImageDigestMirrorSet 和 ImageTagMirrorSet 对象替代,以配置存储库镜像。如果您有用于创建 ImageContentSourcePolicy 对象的 YAML 文件,您可以使用 oc adm migrate icsp 命令将这些文件转换为 ImageDigestMirrorSet YAML 文件。命令将 API 更新至当前版本,将 kind 值更改为 ImageDigestMirrorSet,并将 spec.repositoryDigestMirrors 更改为 spec.imageDigestMirrors。文件的其余部分不会改变。
有关 ImageDigestMirrorSet 或 ImageTagMirrorSet 对象的更多信息,请参阅上一节中的"配置镜像 registry 存储库镜像"。
先决条件
-
确保可以使用具有
cluster-admin角色的用户访问集群。 -
确保集群中具有
ImageContentSourcePolicy对象。
流程
使用以下命令,将一个或多个
ImageContentSourcePolicyYAML 文件转换为ImageDigestMirrorSetYAML 文件:$ oc adm migrate icsp <file_name>.yaml <file_name>.yaml <file_name>.yaml --dest-dir <path_to_the_directory>
其中:
<file_name>-
指定源
ImageContentSourcePolicyYAML 的名称。您可以列出多个文件名。 --dest-dir-
可选:指定输出
ImageDigestMirrorSetYAML 的目录。如果未设置,则会将该文件写入当前目录中。
例如,以下命令可将
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>-
指定
ImageDigestMirrorSetYAML 的名称。
13.4.6. 镜像镜像目录的范围,以减少集群节点重启的频率
您可以在存储库级别或更广泛的 registry 级别限定镜像目录。一个范围广泛的 ImageContentSourcePolicy 资源可减少节点在响应资源更改时需要重启的次数。
要强化 ImageContentSourcePolicy 资源中镜像目录的范围,请执行以下步骤。
先决条件
-
安装 OpenShift Container Platform CLI
oc。 -
以具有
cluster-admin特权的用户身份登录。 - 配置镜像镜像目录,以便在断开连接的集群中使用。
流程
运行以下命令,为
<local_registry>、<pull_spec>和<pull_secret_file>指定值:$ oc adm catalog mirror <local_registry>/<pull_spec> <local_registry> -a <pull_secret_file> --icsp-scope=registry
其中:
- <local_registry>
-
您为断开连接的集群配置的本地 registry,如
local.registry:5000。 - <pull_spec>
-
是断开连接的 registry 中配置的 pull 规格,如
redhat/redhat-operator-index:v4.13 - <pull_secret_file>
-
是
.json文件格式的registry.redhat.iopull secret。您可以从 Red Hat OpenShift Cluster Manager 下载 pull secret。
oc adm catalog mirror命令创建/redhat-operator-index-manifests目录,并生成imageContentSourcePolicy.yaml、catalogSource.yaml和mapping.txt文件。将新的
ImageContentSourcePolicy资源应用到集群:$ oc apply -f imageContentSourcePolicy.yaml
验证
验证
oc apply是否成功将更改应用到ImageContentSourcePolicy:$ oc get ImageContentSourcePolicy -o yaml
输出示例
apiVersion: v1 items: - apiVersion: operator.openshift.io/v1alpha1 kind: ImageContentSourcePolicy metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"operator.openshift.io/v1alpha1","kind":"ImageContentSourcePolicy","metadata":{"annotations":{},"name":"redhat-operator-index"},"spec":{"repositoryDigestMirrors":[{"mirrors":["local.registry:5000"],"source":"registry.redhat.io"}]}} ...
更新 ImageContentSourcePolicy 资源后,OpenShift Container Platform 会将新设置部署到每个节点,集群开始使用已镜像的存储库向源存储库发出请求。