$ oc get machinehealthcheck -n openshift-machine-api
使用以下步骤在无法访问OpenShift更新服务的断开连接的环境中更新集群。
您必须安装oc
命令行界面 (CLI) 工具。
您必须使用容器镜像为您更新配置本地容器镜像注册表,如镜像OpenShift Container Platform镜像中所述。
您必须以具有admin
权限的用户身份访问集群。请参阅使用RBAC定义和应用权限。
万一更新失败并且您必须将集群恢复到以前的状态,您必须拥有最新的etcd备份。
您已将之前通过Operator Lifecycle Manager (OLM) 安装的所有Operator更新到与目标版本兼容的版本。更新Operator可确保在集群更新期间默认OperatorHub目录从当前次要版本切换到下一个版本时,它们具有有效的更新路径。有关如何检查兼容性以及必要时更新已安装的Operator的更多信息,请参阅更新已安装的Operator。
您必须确保所有机器配置池 (MCP) 都正在运行且未暂停。在更新过程中,将跳过与已暂停MCP关联的节点。如果您正在执行金丝雀推出更新策略,则可以暂停MCP。
如果您的集群使用手动维护的凭据,请更新新版本的云提供商资源。有关更多信息,包括如何确定这是否是您集群的要求,请参阅准备更新使用手动维护的凭据的集群。
如果您运行Operator或使用Pod中断预算配置任何应用程序,则在更新过程中可能会遇到中断。如果在PodDisruptionBudget
中将minAvailable
设置为1,则会清空节点以应用挂起的机器配置,这可能会阻止逐出过程。如果重新启动多个节点,所有Pod都可能仅在一个节点上运行,并且PodDisruptionBudget
字段可以阻止节点清空。
如果您运行Operator或使用Pod中断预算配置任何应用程序,则在更新过程中可能会遇到中断。如果在 |
在更新过程中,集群中的节点可能会暂时不可用。对于工作节点,机器健康检查可能会将此类节点识别为不健康并重新启动它们。为了避免重新启动此类节点,请在更新集群之前暂停所有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
更新集群后恢复机器健康检查。要恢复检查,请通过运行以下命令从
|
为了使用带有--to-image
选项的oc adm upgrade
命令在断开连接的环境中更新集群,您必须引用与目标发行版镜像对应的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 校验和,以便在更新集群时使用。
将断开连接的集群更新到您已下载其发行版镜像的 OpenShift Container Platform 版本。
如果您有本地 OpenShift 更新服务,则可以使用连接的 Web 控制台或 CLI 指令进行更新,而无需执行此过程。 |
您已将新版本的镜像镜像到您的注册表。
您已将新版本的发行版镜像签名 ConfigMap 应用到您的集群。
发行版镜像签名配置映射允许集群版本操作符 (CVO) 通过验证实际镜像签名是否与预期签名匹配来确保发行版镜像的完整性。 |
您已获取目标发行版镜像的 sha256 校验和。
您已安装 OpenShift CLI (oc
)。
您已暂停所有MachineHealthCheck
资源。
更新集群
$ oc adm upgrade --allow-explicit-upgrade --to-image <defined_registry>/<defined_repository>@<digest>
其中
<defined_registry>
指定您已将镜像镜像到的镜像注册表名称。
<defined_repository>
指定您要在镜像注册表上使用的镜像仓库名称。
<digest>
指定目标发行版镜像的 sha256 校验和,例如,sha256:81154f5c03294534e1eaf0319bef7a601134f891689ccede5d705ef659aa8c92
。
|
设置容器注册表仓库镜像使您可以执行以下任务:
配置您的 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
的镜像仓库,您希望将registry.access.redhat.com
中的ubi9/ubi-minimal
镜像复制到该仓库。创建镜像注册表后,您可以配置您的 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 对象。
您可以将镜像镜像目录的范围限定在仓库级别或更广泛的注册表级别。范围广泛的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:5000
。
是在断开连接的注册表中配置的拉取规范,例如,redhat/redhat-operator-index:v4.17
。
是.json
文件格式的registry.redhat.io
拉取密钥。您可以从Red Hat OpenShift 集群管理器下载拉取密钥。
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 会将新设置部署到每个节点,并且集群开始使用镜像仓库来处理对源仓库的请求。