16.3. 使用基于镜像的安装预安装单节点 OpenShift


使用 openshift-install 安装程序创建一个实时安装 ISO,以便在裸机主机上预安装单节点 OpenShift。有关下载安装程序的更多信息,请参阅"添加资源"部分中的"安装进程"。

安装程序使用 seed 镜像 URL 和其他输入,如 seed 镜像的发行版本以及用于安装过程的磁盘,并创建一个实时安装 ISO。然后,您可以使用实时安装 ISO 启动主机以开始安装。完成预安装后,主机已准备好发送到远程站点,以进行最终的特定于具体站点的配置和部署。

以下是使用基于镜像的安装预安装单节点 OpenShift 集群的高级步骤:

  • 生成 seed 镜像。
  • 使用 openshift-install 安装程序创建实时安装 ISO。
  • 使用实时安装 ISO 引导主机以预安装主机。

其他资源

16.3.1. 为单节点 OpenShift 镜像安装创建实时安装 ISO

您可以使用 openshift-install 安装程序将单节点 OpenShift seed 镜像 URL 和其他安装工件嵌入到实时安装 ISO 中。

注意

有关 image-based-installation-config.yaml 清单规格的更多信息,请参阅 image-based-installation-config.yaml 清单的参考规格。

先决条件

  • 您已从单节点 OpenShift seed 集群生成了 seed 镜像。
  • 下载 openshift-install 程序。openshift-install 程序的版本必须与 seed 镜像中的 OpenShift Container Platform 版本匹配。
  • 目标主机具有对 seed 镜像 URL 和所有其他安装工件的网络访问。
  • 如果需要静态网络,您必须在创建实时安装 ISO 的主机上安装 nmstatectl 库。

流程

  1. 创建实时安装 ISO 并嵌入您的单节点 OpenShift seed 镜像 URL 和其他安装工件:

    1. 运行以下命令来创建工作目录:

      $ mkdir ibi-iso-workdir 1
      1
      ibi-iso-workdir 替换为工作目录的名称。
    2. 可选。在配置 ImageBasedInstallationConfig 资源时,创建安装配置模板以用作参考:

      $ openshift-install image-based create image-config-template --dir ibi-iso-workdir 1
      1
      如果没有指定工作目录,命令将使用当前目录。

      输出示例

      INFO Image-Config-Template created in: ibi-iso-workdir

      该命令在目标目录中创建 image-based-installation-config.yaml 安装配置模板:

      #
      # Note: This is a sample ImageBasedInstallationConfig file showing
      # which fields are available to aid you in creating your
      # own image-based-installation-config.yaml file.
      #
      apiVersion: v1beta1
      kind: ImageBasedInstallationConfig
      metadata:
        name: example-image-based-installation-config
      # The following fields are required
      seedImage: quay.io/openshift-kni/seed-image:4.17.0
      seedVersion: 4.17.0
      installationDisk: /dev/vda
      pullSecret: '<your_pull_secret>'
      # networkConfig is optional and contains the network configuration for the host in NMState format.
      # See https://nmstate.io/examples.html for examples.
      # networkConfig:
      #   interfaces:
      #     - name: eth0
      #       type: ethernet
      #       state: up
      #       mac-address: 00:00:00:00:00:00
      #       ipv4:
      #         enabled: true
      #         address:
      #           - ip: 192.168.122.2
      #             prefix-length: 23
      #         dhcp: false
    3. 编辑安装配置文件:

      image-based-installation-config.yaml 示例文件

      apiVersion: v1beta1
      kind: ImageBasedInstallationConfig
      metadata:
        name: example-image-based-installation-config
      seedImage: quay.io/repo-id/seed:latest
      seedVersion: "4.17.0"
      extraPartitionStart: "-240G"
      installationDisk: /dev/disk/by-id/wwn-0x62c...
      sshKey: 'ssh-ed25519 AAAA...'
      pullSecret: '{"auths": ...}'
      networkConfig:
          interfaces:
            - name: ens1f0
              type: ethernet
              state: up
              ipv4:
                enabled: true
                dhcp: false
                auto-dns: false
                address:
                  - ip: 192.168.200.25
                    prefix-length: 24
              ipv6:
                enabled: false
          dns-resolver:
            config:
              server:
                - 192.168.15.47
                - 192.168.15.48
          routes:
            config:
            - destination: 0.0.0.0/0
              metric: 150
              next-hop-address: 192.168.200.254
              next-hop-interface: ens1f0

    4. 运行以下命令来创建实时安装 ISO:

      $ openshift-install image-based create image --dir ibi-iso-workdir

      输出示例

      INFO Consuming Image-based Installation ISO Config from target directory
      INFO Creating Image-based Installation ISO with embedded ignition

验证

  • 查看工作目录中的输出:

    ibi-iso-workdir/
      └── rhcos-ibi.iso

16.3.1.1. 在目标主机上配置附加分区

安装 ISO 为 /var/lib/containers 目录创建一个分区,作为基于镜像的安装过程的一部分。

您可以使用 coreosInstallerArgs 规格创建额外的分区。例如,在具有适当存储的硬盘中,您可能需要额外的存储选项分区,如逻辑卷管理器(LVM)存储。

注意

/var/lib/containers 分区至少需要 500 GB,以确保为 precached 镜像有足够的磁盘空间。您必须创建额外的分区,其起始位置大于 /var/lib/containers 的分区。

流程

  1. 编辑 image-based-installation-config.yaml 文件来配置额外的分区:

    image-based-installation-config.yaml 示例文件

    apiVersion: v1beta1
    kind: ImageBasedInstallationConfig
    metadata:
      name: example-extra-partition
    seedImage: quay.io/repo-id/seed:latest
    seedVersion: "4.17.0"
    installationDisk: /dev/sda
    pullSecret: '{"auths": ...}'
    # ...
    skipDiskCleanup: true 1
    coreosInstallerArgs:
       - "--save-partindex" 2
       - "6" 3
    ignitionConfigOverride: |
      {
        "ignition": {
          "version": "3.2.0"
        },
        "storage": {
          "disks": [
            {
              "device": "/dev/sda", 4
              "partitions": [
                {
                  "label": "storage", 5
                  "number": 6, 6
                  "sizeMiB": 380000, 7
                  "startMiB": 500000 8
                }
              ]
            }
          ]
        }
      }

    1
    指定 true 在安装过程中跳过磁盘格式。
    2
    指定这个参数来保留分区。
    3
    实时安装 ISO 需要五个分区。指定一个大于五的数字来识别要保留的额外分区。
    4
    指定目标主机上的安装磁盘。
    5
    指定分区的标签。
    6
    指定分区的数量。
    7
    指定分区大小(以 MiB 为单位)。
    8
    为额外分区指定磁盘上的起始位置(以 MiB 为单位)。您必须为 var/lib/containers 指定一个大于分区的起点。

验证

  • 使用实时安装 ISO 完成主机的预安装后,登录到目标主机,并运行以下命令来查看分区:

    $ lsblk

    输出示例

    sda    8:0    0  140G  0 disk
    ├─sda1 8:1    0    1M  0 part
    ├─sda2 8:2    0  127M  0 part
    ├─sda3 8:3    0  384M  0 part /var/mnt/boot
    ├─sda4 8:4    0  120G  0 part /var/mnt
    ├─sda5 8:5    0  500G  0 part /var/lib/containers
    └─sda6 8:6    0  380G  0 part

16.3.2. 将实时安装 ISO 调配到主机

使用您首选的方法,从 rhcos-ibi.iso 实时安装 ISO 引导目标裸机主机,以预安装单节点 OpenShift。

验证

  1. 登录到目标主机。
  2. 运行以下命令来查看系统日志:

    $ journalctl -b

    输出示例

    Aug 13 17:01:44 10.46.26.129 install-rhcos-and-restore-seed.sh[2876]: time="2024-08-13T17:01:44Z" level=info msg="All the precaching threads have finished."
    Aug 13 17:01:44 10.46.26.129 install-rhcos-and-restore-seed.sh[2876]: time="2024-08-13T17:01:44Z" level=info msg="Total Images: 125"
    Aug 13 17:01:44 10.46.26.129 install-rhcos-and-restore-seed.sh[2876]: time="2024-08-13T17:01:44Z" level=info msg="Images Pulled Successfully: 125"
    Aug 13 17:01:44 10.46.26.129 install-rhcos-and-restore-seed.sh[2876]: time="2024-08-13T17:01:44Z" level=info msg="Images Failed to Pull: 0"
    Aug 13 17:01:44 10.46.26.129 install-rhcos-and-restore-seed.sh[2876]: time="2024-08-13T17:01:44Z" level=info msg="Completed executing pre-caching"
    Aug 13 17:01:44 10.46.26.129 install-rhcos-and-restore-seed.sh[2876]: time="2024-08-13T17:01:44Z" level=info msg="Pre-cached images successfully."
    Aug 13 17:01:44 10.46.26.129 install-rhcos-and-restore-seed.sh[2876]: time="2024-08-13 17:01:44" level=info msg="Skipping shutdown"
    Aug 13 17:01:44 10.46.26.129 install-rhcos-and-restore-seed.sh[2876]: time="2024-08-13 17:01:44" level=info msg="IBI preparation process finished successfully!"
    Aug 13 17:01:44 10.46.26.129 systemd[1]: var-lib-containers-storage-overlay.mount: Deactivated successfully.
    Aug 13 17:01:44 10.46.26.129 systemd[1]: Finished SNO Image-based Installation.
    Aug 13 17:01:44 10.46.26.129 systemd[1]: Reached target Multi-User System.
    Aug 13 17:01:44 10.46.26.129 systemd[1]: Reached target Graphical Interface.

16.3.3. 基于 image-installation-config.yaml 清单的参考规格

以下内容描述了 image-based-installation-config.yaml 清单的规格。

openshift-install 程序使用 image-based-installation-config.yaml 清单,为基于镜像的单节点 OpenShift 安装创建一个实时安装 ISO。

表 16.4. 所需的规格
规格类型描述

seedImage

string

指定要在 ISO 生成过程中使用的 seed 镜像。

seedVersion

string

指定 seed 镜像的 OpenShift Container Platform 发行版本。seed 镜像中的发行版本必须与您在 seedVersion 字段中指定的发行版本匹配。

installationDisk

string

指定用于安装过程的磁盘。

由于磁盘发现顺序无法保证,因此磁盘的内核名称可以在具有多个磁盘的机器的引导选项之间更改。例如: /dev/sda 变为 /dev/sdb,反之亦然。要避免这个问题,您必须使用持久性磁盘属性,如磁盘 World Wide Name (WWN),例如: /dev/disk/by-id/wwn-<disk-id>

pullSecret

string

指定在 precache 过程中使用的 pull secret。pull secret 包含从容器 registry 中拉取发行版本有效负载镜像的身份验证凭据。

如果 seed 镜像需要单独的私有 registry 身份验证,请将身份验证详情添加到 pull secret 中。

表 16.5. 可选规格
规格类型描述

shutdown

布尔值

指定主机在安装过程完成后是否关闭。默认值为 false

extraPartitionStart

string

指定用于 /var/lib/containers 的额外分区的开头。默认值为 -40Gb,这意味着分区的大小为 40Gb,并使用磁盘末尾处的 40Gb 空间。如果您指定了正值,分区将在磁盘的那个位置开始,并扩展到磁盘的末尾。

extraPartitionLabel

string

用于 /var/lib/containers 的额外分区标签。默认分区标签是 var-lib-containers

注意

您必须确保安装 ISO 中的分区标签与 seed 镜像的机器配置中设置的分区标签匹配。如果分区标签不同,则分区挂载在主机上安装过程中会失败。如需更多信息,请参阅"在 ostree stateroot 之间配置共享容器分区"。

extraPartitionNumber

无符号整数

用于 /var/lib/containers 的额外分区数量。默认为 5

skipDiskCleanup

布尔值

安装过程会格式化主机上的磁盘。将此规格设置为 'true' 以跳过此步骤。默认值为 false

networkConfig

string

指定主机的网络配置,例如:

networkConfig:
    interfaces:
      - name: ens1f0
        type: ethernet
        state: up
        ...

如果需要静态网络,您必须在创建实时安装 ISO 的主机上安装 nmstatectl 库。有关使用 nmstate 定义网络配置的详情,请参考 nmstate.io

重要

接口的名称必须与操作系统中显示的实际 NIC 名称匹配。

proxy

string

指定在安装 ISO 生成过程中使用的代理设置,例如:

proxy:
  httpProxy: "http://proxy.example.com:8080"
  httpsProxy: "http://proxy.example.com:8080"
  noProxy: "no_proxy.example.com"

imageDigestSources

string

指定 release-image 内容的源或软件仓库,例如:

imageDigestSources:
  - mirrors:
      - "registry.example.com:5000/ocp4/openshift4"
    source: "quay.io/openshift-release-dev/ocp-release"

additionalTrustBundle

string

指定 PEM 编码的 X.509 证书捆绑包。安装程序将其添加到安装 ISO 的 /etc/pki/ca-trust/source/anchors/ 目录中。

additionalTrustBundle: |
  -----BEGIN CERTIFICATE-----
  MTICLDCCAdKgAwfBAgIBAGAKBggqhkjOPQRDAjB9MQswCQYRVEQGE
  ...
  l2wOuDwKQa+upc4GftXE7C//4mKBNBC6Ty01gUaTIpo=
  -----END CERTIFICATE-----

sshKey

string

指定验证主机访问权限的 SSH 密钥。

ignitionConfigOverride

string

指定包含 Ignition 配置的用户覆盖的 JSON 字符串。配置与安装程序生成的 Ignition 配置文件合并。此功能需要 Ignition 版本为 3.2 或更高版本。

coreosInstallerArgs

string

coreos-install 命令指定自定义参数,可用于配置内核参数和磁盘分区选项。

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

© 2024 Red Hat, Inc.