搜索

1.8. 使用策略升级断开连接的集群

download PDF

您可以将 Red Hat OpenShift Update Service 与 Red Hat Advanced Cluster Management for Kubernetes 策略搭配使用,以便在断开连接的环境中升级多个集群。

在某些情况下,安全性考虑会阻止集群直接连接到互联网。这使得您很难知道什么时候可以使用升级,以及如何处理这些升级。配置 OpenShift Update Service 可能会有所帮助。

OpenShift Update Service 是一个独立的操作对象,它监控受管集群在断开连接的环境中的可用版本,并使其可用于在断开连接的环境中升级集群。配置 OpenShift Update Service 后,它可以执行以下操作:

1.8.1. 先决条件

您必须满足以下先决条件,才能使用 OpenShift Update Service 升级断开连接的集群:

  • 部署在 Red Hat OpenShift Container Platform 版本 4.6 或更高版本上运行的 hub 集群,并配置了受限 OLM。如需了解如何配置受限 OLM 的详细信息,请参阅在受限网络中使用 Operator Lifecycle Manager

    提示: 配置受限 OLM 时请记录目录源镜像。

  • 由 hub 集群管理的 OpenShift Container Platform 集群
  • 访问您可以镜像集群镜像的本地存储库的凭证。如需有关如何创建此存储库的更多信息,请参阅断开连接的安装镜像

    注: 您升级的集群当前版本的镜像必须始终作为镜像的一个镜像可用。如果升级失败,集群会在试图升级时恢复到集群的版本。

1.8.2. 准备断开连接的镜像 registry

您必须镜像要升级到的镜像,以及您要从本地镜像 registry 升级到的当前镜像。完成以下步骤以镜像镜像:

  1. 创建一个包含类似以下示例内容的脚本文件:

    UPSTREAM_REGISTRY=quay.io
    PRODUCT_REPO=openshift-release-dev
    RELEASE_NAME=ocp-release
    OCP_RELEASE=4.12.2-x86_64
    LOCAL_REGISTRY=$(hostname):5000
    LOCAL_SECRET_JSON=/path/to/pull/secret
    
    oc adm -a ${LOCAL_SECRET_JSON} release mirror \
    --from=${UPSTREAM_REGISTRY}/${PRODUCT_REPO}/${RELEASE_NAME}:${OCP_RELEASE} \
    --to=${LOCAL_REGISTRY}/ocp4 \
    --to-release-image=${LOCAL_REGISTRY}/ocp4/release:${OCP_RELEASE}

    /path/to/pull/secret 替换为 OpenShift Container Platform pull secret 的路径。

  2. 运行该脚本来对镜像进行镜像、配置设置并将发行镜像与发行内容分开。

提示: 在创建 ImageContentSourcePolicy 时,您可以使用此脚本最后一行的输出。

1.8.3. 为 OpenShift Update Service 部署 Operator

要在 OpenShift Container Platform 环境中为 OpenShift Update Service 部署 Operator,请完成以下步骤:

  1. 在 hub 集群中,访问 OpenShift Container Platform operator hub。
  2. 选择 Red Hat OpenShift Update Service Operator 来部署 Operator。如果需要,更新默认值。Operator 的部署会创建一个名为 openshift-cincinnati 的新项目。
  3. 等待 Operator 的安装完成。

    提示: 您可以通过在 OpenShift Container Platform 命令行中输入 oc get pods 命令来检查安装的状态。验证 Operator 是否处于 running 状态。

1.8.4. 构建图形数据 init 容器

OpenShift Update Service 使用图形数据信息来决定可用的升级。在连接的环境中,OpenShift Update Service 会直接从 Cincinnati 图形数据GitHub 仓库中提取可用于升级的图形数据信息。由于要配置断开连接的环境,所以必须使用 init 容器使图形数据在本地存储库中可用。完成以下步骤以创建图形数据 init 容器:

  1. 输入以下命令克隆 graph data Git 存储库:

    git clone https://github.com/openshift/cincinnati-graph-data
  2. 创建一个包含您的图形数据 init 信息的文件。您可以在 cincinnati-operator GitHub 仓库中找到此 Dockerfile 示例。该文件的内容在以下示例中显示:

    FROM registry.access.redhat.com/ubi8/ubi:8.1
    
    RUN curl -L -o cincinnati-graph-data.tar.gz https://github.com/openshift/cincinnati-graph-data/archive/master.tar.gz
    
    RUN mkdir -p /var/lib/cincinnati/graph-data/
    
    CMD exec /bin/bash -c "tar xvzf cincinnati-graph-data.tar.gz -C /var/lib/
    cincinnati/graph-data/ --strip-components=1"

    在本例中:

    • FROM 值是 OpenShift Update Service 查找镜像的外部 registry。
    • RUN 命令创建目录并打包升级文件。
    • CMD 命令将软件包文件复制到本地库并提取文件进行升级。
  3. 运行以下命令来构建 图形数据 init 容器:

    podman build -f <path_to_Dockerfile> -t ${DISCONNECTED_REGISTRY}/cincinnati/cincinnati-graph-data-container:latest
    podman push ${DISCONNECTED_REGISTRY}/cincinnati/cincinnati-graph-data-container:latest --authfile=/path/to/pull_secret.json

    path_to_Dockerfile 替换为您在上一步中创建文件的路径。

    ${DISCONNECTED_REGISTRY}/cincinnati/cincinnati-graph-data-container 替换为 graph data init 容器的路径。

    /path/to/pull_secret 替换为 pull secret 文件的路径。

    注: 如果没有安装 podman,您也可以将命令中的 podman 替换为 docker

1.8.5. 为已镜像的 registry 配置证书

如果您使用安全的外部容器 registry 来存储已镜像的 OpenShift Container Platform 发行镜像,OpenShift Update Service 需要访问此 registry 来构建升级图。完成以下步骤以配置您的 CA 证书以用于 OpenShift Update Service Pod:

  1. 查找位于 image.config.openshift.io 的 OpenShift Container Platform 外部 registry API。这是存储外部 registry CA 证书的位置。

    如需更多信息,请参阅 OpenShift Container Platform 文档中的为镜像 registry 访问配置额外的信任存储

  2. openshift-config 命名空间中创建 ConfigMap。
  3. 在密钥 updateservice-registry 中添加您的 CA 证书。OpenShift Update Service 使用此设置来定位您的证书:

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: trusted-ca
    data:
      updateservice-registry: |
        -----BEGIN CERTIFICATE-----
        ...
        -----END CERTIFICATE-----
  4. 编辑 image.config.openshift.io API 中的 cluster 资源,将 additionalTrustedCA 字段设置为您创建的 ConfigMap 的名称。

    oc patch image.config.openshift.io cluster -p '{"spec":{"additionalTrustedCA":{"name":"trusted-ca"}}}' --type merge

    trusted-ca 替换为新 ConfigMap 的路径。

OpenShift Update Service Operator 会监视 image.config.openshift.io API 和您在 openshift-config 命名空间中创建的 ConfigMap 以获取更改,然后在 CA 证书已更改时重启部署。

1.8.6. 部署 OpenShift Update Service 实例

当在 hub 集群上完成 OpenShift Update Service 实例部署时,此实例就位于集群升级的镜像镜像位置,并可供断开连接的受管集群使用。完成以下步骤以部署实例:

  1. 如果您不想使用 Operator 的默认命名空间(openshift-cincinnati), 为 OpenShift Update Service 实例创建一个命名空间:

    1. 在 OpenShift Container Platform hub 集群控制台导航菜单中,选择 Administration > Namespaces
    2. Create Namespace
    3. 添加命名空间的名称以及您的命名空间的任何其他信息。
    4. 选择 Create 来创建命名空间。
  2. 在 OpenShift Container Platform 控制台的 Installed Operators 部分中,选择 Red Hat OpenShift Update Service Operator
  3. 在菜单中选择 Create Instance
  4. 粘贴 OpenShift Update Service 实例中的内容。您的 YAML 实例可能类似以下清单:

    apiVersion: cincinnati.openshift.io/v1beta2
    kind: Cincinnati
    metadata:
      name: openshift-update-service-instance
      namespace: openshift-cincinnati
    spec:
      registry: <registry_host_name>:<port> 1
      replicas: 1
      repository: ${LOCAL_REGISTRY}/ocp4/release
      graphDataImage: '<host_name>:<port>/cincinnati-graph-data-container' 2
    1
    spec.registry 值替换为镜像的本地断开连接 registry 的路径。
    2
    spec.graphDataImage 值替换为图形数据 init 容器的路径。这与运行 podman push 命令来推送图形数据 init 容器时使用的值相同。
  5. 选择 Create 来创建实例。
  6. 在 hub 集群 CLI 中输入 oc get pods 命令来查看实例创建的状态。它可能需要一段时间,但当命令结果显示实例和运算符正在运行时,进程就会完成。

1.8.7. 部署策略以覆盖默认 registry(可选)

注: 本节中的步骤只在将发行版本镜像到您的镜像 registry 时才应用。

OpenShift Container Platform 具有一个默认的镜像 registry 值,用于指定它找到升级软件包的位置。在断开连接的环境中,您可以创建一个策略来替换该值,并将该值替换为您对发行版本镜像进行镜像的本地镜像 registry 的路径。

对于这些步骤,策略名为 policy-mirror。完成以下步骤以创建策略:

  1. 登录到 hub 集群的 OpenShift Container Platform 环境。
  2. 在控制台中,选择 Governance > Create policy
  3. YAML 开关设置为 On 以查看策略的 YAML 版本。
  4. 删除 YAML 代码中的所有内容。
  5. 将以下 YAML 内容粘贴到窗口以创建自定义策略:

    apiVersion: policy.open-cluster-management.io/v1
    kind: Policy
    metadata:
      name: policy-mirror
      namespace: default
    spec:
      disabled: false
      remediationAction: enforce
      policy-templates:
        - objectDefinition:
            apiVersion: policy.open-cluster-management.io/v1
            kind: ConfigurationPolicy
            metadata:
              name: policy-image-content-source-policy
            spec:
              object-templates:
                - complianceType: musthave
                  objectDefinition:
                    apiVersion: operator.openshift.io/v1alpha1
                    kind: ImageContentSourcePolicy
                    metadata:
                      name: <your-local-mirror-name>
                    spec:
                      repositoryDigestMirrors:
                        - mirrors:
                            - <your-registry> 1
                          source: registry.redhat.io
    ---
    apiVersion: policy.open-cluster-management.io/v1
    kind: PlacementBinding
    metadata:
      name: binding-policy-mirror
      namespace: default
    placementRef:
      name: placement-policy-mirror
      kind: PlacementRule
      apiGroup: apps.open-cluster-management.io
    subjects:
    - name: policy-mirror
      kind: Policy
      apiGroup: policy.open-cluster-management.io
    ---
    apiVersion: apps.open-cluster-management.io/v1
    kind: PlacementRule
    metadata:
      name: placement-policy-mirror
      namespace: default
    spec:
      clusterConditions:
      - status: "True"
        type: ManagedClusterConditionAvailable
      clusterSelector:
        matchExpressions:
          []  # selects all clusters if not specified
    1
    your-registry 替换为本地镜像存储库的路径。您可以通过输入 oc adm release mirror 命令来查找到本地镜像的路径。
  6. 选择 Enforce if supported
  7. 选择 Create 来创建策略。

1.8.8. 部署策略来部署断开连接的目录源

Catalogsource 策略推送到受管集群,将默认位置从连接的位置更改为您断开连接的本地 registry。

  1. 在控制台菜单中选择 Governance > Create policy
  2. YAML 切换设置为 On 以查看策略的 YAML 版本。
  3. 删除 YAML 代码中的所有内容。
  4. 将以下 YAML 内容粘贴到窗口以创建自定义策略:

    apiVersion: policy.open-cluster-management.io/v1
    kind: Policy
    metadata:
      name: policy-catalog
      namespace: default
    spec:
      disabled: false
      remediationAction: enforce
      policy-templates:
        - objectDefinition:
            apiVersion: policy.open-cluster-management.io/v1
            kind: ConfigurationPolicy
            metadata:
              name: policy-catalog
            spec:
              object-templates:
                - complianceType: musthave
                  objectDefinition:
                    apiVersion: config.openshift.io/v1
                    kind: OperatorHub
                    metadata:
                      name: cluster
                    spec:
                      disableAllDefaultSources: true
                - complianceType: musthave
                  objectDefinition:
                    apiVersion: operators.coreos.com/v1alpha1
                    kind: CatalogSource
                    metadata:
                      name: my-operator-catalog
                      namespace: openshift-marketplace
                    spec:
                      sourceType: grpc
                      image: '<registry_host_name>:<port>/olm/redhat-operators:v1' 1
                      displayName: My Operator Catalog
                      publisher: grpc
    ---
    apiVersion: policy.open-cluster-management.io/v1
    kind: PlacementBinding
    metadata:
      name: binding-policy-catalog
      namespace: default
    placementRef:
      name: placement-policy-catalog
      kind: PlacementRule
      apiGroup: apps.open-cluster-management.io
    subjects:
    - name: policy-catalog
      kind: Policy
      apiGroup: policy.open-cluster-management.io
    ---
    apiVersion: apps.open-cluster-management.io/v1
    kind: PlacementRule
    metadata:
      name: placement-policy-catalog
      namespace: default
    spec:
      clusterConditions:
      - status: "True"
        type: ManagedClusterConditionAvailable
      clusterSelector:
        matchExpressions:
          []  # selects all clusters if not specified
    1
    spec.image 值替换为本地受限目录源镜像的路径。
  5. 选择 Enforce if supported
  6. 选择 Create 来创建策略。

1.8.9. 部署策略以更改受管集群参数

ClusterVersion 策略推送到受管集群,以更改其检索升级的默认位置。

  1. 在受管集群中,输入以下命令确认 ClusterVersion upstream 参数目前是默认公共 OpenShift Update Service 操作对象:

    oc get clusterversion -o yaml

    返回的内容可能类似以下内容:

    apiVersion: v1
    items:
    - apiVersion: config.openshift.io/v1
      kind: ClusterVersion
    [..]
      spec:
        channel: stable-4.4
        upstream: https://api.openshift.com/api/upgrades_info/v1/graph
  2. 在 hub 集群中,输入以下命令来识别到 OpenShift Update Service 操作对象:oc get routes。记录下这个值以便在以后的步骤中使用。
  3. 在 hub 集群控制台菜单中,选择 Governance > Create a policy
  4. YAML 切换设置为 On 以查看策略的 YAML 版本。
  5. 删除 YAML 代码中的所有内容。
  6. 将以下 YAML 内容粘贴到窗口以创建自定义策略:

    apiVersion: policy.open-cluster-management.io/v1
    kind: Policy
    metadata:
      name: policy-cluster-version
      namespace: default
      annotations:
        policy.open-cluster-management.io/standards: null
        policy.open-cluster-management.io/categories: null
        policy.open-cluster-management.io/controls: null
    spec:
      disabled: false
      remediationAction: enforce
      policy-templates:
        - objectDefinition:
            apiVersion: policy.open-cluster-management.io/v1
            kind: ConfigurationPolicy
            metadata:
              name: policy-cluster-version
            spec:
              object-templates:
                - complianceType: musthave
                  objectDefinition:
                    apiVersion: config.openshift.io/v1
                    kind: ClusterVersion
                    metadata:
                      name: version
                    spec:
                      channel: stable-4.4
                      upstream: >-
                        https://example-cincinnati-policy-engine-uri/api/upgrades_info/v1/graph 1
    
    ---
    apiVersion: policy.open-cluster-management.io/v1
    kind: PlacementBinding
    metadata:
      name: binding-policy-cluster-version
      namespace: default
    placementRef:
      name: placement-policy-cluster-version
      kind: PlacementRule
      apiGroup: apps.open-cluster-management.io
    subjects:
    - name: policy-cluster-version
      kind: Policy
      apiGroup: policy.open-cluster-management.io
    ---
    apiVersion: apps.open-cluster-management.io/v1
    kind: PlacementRule
    metadata:
      name: placement-policy-cluster-version
      namespace: default
    spec:
      clusterConditions:
      - status: "True"
        type: ManagedClusterConditionAvailable
      clusterSelector:
        matchExpressions:
          []  # selects all clusters if not specified
    1
    objectDefinition.spec.upstream 的值替换为 hub 集群 OpenShift Update Service 操作对象的路径。

    您可以完成以下步骤来确定操作对象的路径:

    1. 在 hub 集群上运行 oc get get routes -A 命令。
    2. 找到到 cincinnati 的路由。+ 到操作对象的路径是 HOST/PORT 字段的值。
  7. 选择 Enforce if supported
  8. 选择 Create 来创建策略。
  9. 在受管集群 CLI 中,使用以下命令确认 ClusterVersion 中的上游参数已使用本地 hub 集群 OpenShift Update Service URL 更新:

    oc get clusterversion -o yaml

    结果应该类似以下内容:

    apiVersion: v1
    items:
    - apiVersion: config.openshift.io/v1
      kind: ClusterVersion
    [..]
      spec:
        channel: stable-4.4
        upstream: https://<hub-cincinnati-uri>/api/upgrades_info/v1/graph

1.8.10. 查看可用升级

您可以通过完成以下步骤来查看受管集群可用升级列表:

  1. 登录到 Kubernetes operator 控制台的多集群引擎。
  2. 在导航菜单中选择 Infrastructure > Clusters
  3. 选择处于 Ready 状态的一个集群。
  4. Actions 菜单中选择 Upgrade cluster
  5. 验证可选的升级路径是否可用。

    注: 如果当前版本没有镜像到本地镜像存储库,则不会显示可用的升级版本。

1.8.11. 选择一个频道

您可以使用 Red Hat Advanced Cluster Management 控制台为 OpenShift Container Platform 版本 4.6 或更高版本上的集群升级选择一个频道。这些版本必须在镜像 registry 上可用。完成选择频道中的步骤为您的升级指定频道。

1.8.12. 升级集群

配置断开连接的 registry 后,Red Hat Advanced Cluster Management 和 OpenShift Update Service 使用断开连接的 registry 来确定升级是否可用。如果没有可用的升级,请确保您有集群当前级别的发行镜像,且至少有一个后续级别的镜像位于本地存储库中。如果集群当前版本的发行镜像不可用,则没有可用的升级。

完成以下步骤进行升级:

  1. 在控制台中,选择 Infrastructure > Clusters
  2. 查找您要确定是否有可用的升级的集群。
  3. 如果有可用的升级,集群的 Distribution version 栏表示有可用的升级可用。
  4. 选择集群的 Options 菜单,然后选择 Upgrade cluster
  5. 为升级选择目标版本,然后选择 Upgrade

受管集群已更新至所选版本。

如果集群升级失败,Operator 通常会重试升级,停止并报告故障组件的状态。在某些情况下,升级过程会一直通过尝试完成此过程进行循环。不支持在失败的升级后将集群还原到以前的版本。如果您的集群升级失败,请联系红帽支持以寻求帮助。

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.