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) 。

流程

  1. 要列出您要暂停的所有可用 MachineHealthCheck 资源,请运行以下命令:

    $ oc get machinehealthcheck -n openshift-machine-api
  2. 要暂停机器健康检查,请将 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 摘要。

流程

  1. 在连接到互联网的设备中运行以下命令:

    $ 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

  2. 复制在更新集群时要使用的 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 <defined_registry>/<defined_repository>@<digest>

    其中:

    <defined_registry>
    指定 mirror 到的镜像 registry 的名称。
    <defined_repository>
    指定要在镜像 registry 中使用的镜像存储库的名称。
    <digest>
    指定目标发行镜像的 sha256 摘要,例如 sha256:81154f5c03294534e1eaf0319bef7a601134f891689ccede5d705ef659aa8c92
    注意
    • 请参阅"镜像 OpenShift Container Platform 镜像"以查看如何定义您的镜像 registry 和存储库名称。
    • 如果您使用 ImageContentSourcePolicyImageDigestMirrorSet,您可以使用规范 registry 和存储库名称,而不是您定义的名称。规范 registry 名称为 quay.io,规范存储库名称为 openshift-release-dev/ocp-release
    • 您只能为具有 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 安装期间配置镜像 (mirror),之后您仍可使用 ImageContentSourcePolicy 对象进行配置。

以下流程提供安装后镜像配置,您可在此处创建 ImageContentSourcePolicy 对象来识别:

  • 您希望镜像 (mirror) 的容器镜像存储库的源。
  • 您希望为其提供从源存储库请求的内容的每个镜像存储库的单独条目。
注意

您只能为具有 ImageContentSourcePolicy 对象的集群配置全局 pull secret。您不能在项目中添加 pull secret。

先决条件

  • 使用具有 cluster-admin 角色的用户访问集群。

流程

  1. 通过以下方法配置已镜像的存储库:

    • 按照 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/ubi8/ubi-minimal@sha256:5cfbaf45ca96806917830c183e9f37df2e913b187adb32e89fd83fa455ebaa6 \
      docker://example.io/example/ubi-minimal

      在本例中,您有一个名为 example.io 的容器镜像 registry,其中包含一个名为 example 的镜像存储库,您希望将 ubi8/ubi-minimal 镜像从 registry.access.redhat.com 复制到此镜像存储库。创建该 registry 后,您可将 OpenShift Container Platform 集群配置为将源存储库的请求重定向到已镜像的存储库。

  2. 登录您的 OpenShift Container Platform 集群。
  3. 创建 ImageContentSourcePolicy 文件(如:registryrepomirror.yaml),将源和镜像 (mirror) 替换为您自己的 registry、存储库对和镜像中的源和镜像:

    apiVersion: operator.openshift.io/v1alpha1
    kind: ImageContentSourcePolicy
    metadata:
      name: ubi8repo
    spec:
      repositoryDigestMirrors:
      - mirrors:
        - example.io/example/ubi-minimal 1
        - example.com/example/ubi-minimal 2
        source: registry.access.redhat.com/ubi8/ubi-minimal 3
      - mirrors:
        - mirror.example.com/redhat
        source: registry.redhat.io/openshift4 4
      - mirrors:
        - mirror.example.com
        source: registry.redhat.io 5
      - mirrors:
        - mirror.example.net/image
        source: registry.example.com/example/myimage 6
      - mirrors:
        - mirror.example.net
        source: registry.example.com/example 7
      - mirrors:
        - mirror.example.net/registry-example-com
        source: registry.example.com 8
    1
    指明镜像 registry 和存储库的名称。
    2
    表示每个目标仓库的多个镜像仓库。如果一个镜像停机,则目标仓库可以使用另一个镜像。
    3
    指明包含所镜像内容的 registry 和存储库。
    4
    您可以在 registry 中配置命名空间以使用该命名空间中的任何镜像。如果您使用 registry 域作为源,ImageContentSourcePolicy 资源将应用到 registry 中的所有存储库。
    5
    如果配置 registry 名称,则 ImageContentSourcePolicy 资源将应用到源 registry 中的所有软件仓库。
    6
    拉取镜像 mirror.example.net/image@sha256:…​
    7
    从 mirror mirror.example.net/myimage@sha256:…​ 的源 registry 命名空间中拉取镜像 myimage
    8
    从 mirror registry mirror.example.net/registry-example-com/example/myimage@sha256:…​ 拉取镜像 registry.example.com/example/myimageImageContentSourcePolicy 资源会应用到源 registry 中的所有仓库到到 mirror registry mirror.example.net/registry-example-com
  4. 创建新的 ImageContentSourcePolicy 对象:

    $ oc create -f registryrepomirror.yaml

    创建 ImageContentSourcePolicy 对象后,新的设置将部署到每个节点,集群开始使用已镜像的存储库来响应源存储库请求。

  5. 要检查是否应用了已镜像的配置设置,在其中一个节点上执行以下内容。

    1. 列出您的节点:

      $ oc get node

      输出示例

      NAME                           STATUS                     ROLES    AGE  VERSION
      ip-10-0-137-44.ec2.internal    Ready                      worker   7m   v1.25.0
      ip-10-0-138-148.ec2.internal   Ready                      master   11m  v1.25.0
      ip-10-0-139-122.ec2.internal   Ready                      master   11m  v1.25.0
      ip-10-0-147-35.ec2.internal    Ready                      worker   7m   v1.25.0
      ip-10-0-153-12.ec2.internal    Ready                      worker   7m   v1.25.0
      ip-10-0-154-10.ec2.internal    Ready                      master   11m  v1.25.0

      Imagecontentsourcepolicy 资源不会重启节点。

    2. 启动调试过程以访问节点:

      $ 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`

    3. 将您的根目录改为 /host

      sh-4.2# chroot /host
    4. 检查 /etc/containers/registries.conf 文件,确保已完成更改:

      sh-4.2# cat /etc/containers/registries.conf

      输出示例

      unqualified-search-registries = ["registry.access.redhat.com", "docker.io"]
      short-name-mode = ""
      
      [[registry]]
        prefix = ""
        location = "registry.access.redhat.com/ubi8/ubi-minimal"
        mirror-by-digest-only = true
      
        [[registry.mirror]]
          location = "example.io/example/ubi-minimal"
      
        [[registry.mirror]]
          location = "example.com/example/ubi-minimal"
      
      [[registry]]
        prefix = ""
        location = "registry.example.com"
        mirror-by-digest-only = true
      
        [[registry.mirror]]
          location = "mirror.example.net/registry-example-com"
      
      [[registry]]
        prefix = ""
        location = "registry.example.com/example"
        mirror-by-digest-only = true
      
        [[registry.mirror]]
          location = "mirror.example.net"
      
      [[registry]]
        prefix = ""
        location = "registry.example.com/example/myimage"
        mirror-by-digest-only = true
      
        [[registry.mirror]]
          location = "mirror.example.net/image"
      
      [[registry]]
        prefix = ""
        location = "registry.redhat.io"
        mirror-by-digest-only = true
      
        [[registry.mirror]]
          location = "mirror.example.com"
      
      [[registry]]
        prefix = ""
        location = "registry.redhat.io/openshift4"
        mirror-by-digest-only = true
      
        [[registry.mirror]]
          location = "mirror.example.com/redhat"

    5. 将镜像摘要从源拉取到节点,并检查是否通过镜像解析。ImageContentSourcePolicy 对象仅支持镜像摘要,不支持镜像标签。

      sh-4.2# podman pull --log-level=debug registry.access.redhat.com/ubi8/ubi-minimal@sha256:5cfbaf45ca96806917830c183e9f37df2e913b187adb32e89fd83fa455ebaa6

存储库镜像故障排除

如果存储库镜像流程未按规定工作,请使用以下有关存储库镜像如何工作的信息协助排查问题。

  • 首个工作镜像用于提供拉取(pull)的镜像。
  • 只有在无其他镜像工作时,才会使用主 registry。
  • 从系统上下文,Insecure 标志用作回退。
  • 最近更改了 /etc/containers/registries.conf 文件的格式。现在它是第 2 版,采用 TOML 格式。

13.4.6. 镜像镜像目录的范围,以减少集群节点重启的频率

您可以在存储库级别或更广泛的 registry 级别限定镜像目录。一个范围广泛的 ImageContentSourcePolicy 资源可减少节点在响应资源更改时需要重启的次数。

要强化 ImageContentSourcePolicy 资源中镜像目录的范围,请执行以下步骤。

先决条件

  • 安装 OpenShift Container Platform CLI oc
  • 以具有 cluster-admin 特权的用户身份登录。
  • 配置镜像镜像目录,以便在断开连接的集群中使用。

流程

  1. 运行以下命令,为 <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.12
    <pull_secret_file>
    .json 文件格式的 registry.redhat.io pull secret。您可以从 Red Hat OpenShift Cluster Manager 下载 pull secret

    oc adm catalog mirror 命令创建 /redhat-operator-index-manifests 目录,并生成 imageContentSourcePolicy.yamlcatalogSource.yamlmapping.txt 文件。

  2. 将新的 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 会将新设置部署到每个节点,集群开始使用已镜像的存储库向源存储库发出请求。

13.4.7. 其他资源