使用 RHEL 镜像模式安装


Red Hat build of MicroShift 4.17

在 bootc 镜像中嵌入 MicroShift

Red Hat OpenShift Documentation Team

摘要

您可以使用 Red Hat Enterprise Linux (RHEL)的镜像模式将 MicroShift 嵌入到 bootc 镜像中。Bootc 代表可引导容器,镜像包括内核、引导装载程序和其他通常排除在应用程序容器的项目。

第 1 章 在 MicroShift 中使用 RHEL 的镜像模式

您可以使用 Red Hat Enterprise Linux (RHEL)的镜像模式将 MicroShift 嵌入到操作系统镜像中。

重要

RHEL 的镜像模式只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

1.1. Red Hat Enterprise Linux (RHEL)的镜像模式

Red Hat Enterprise Linux (RHEL)的镜像模式是一个技术预览部署方法,它使用容器原生虚拟化方法构建、部署和管理操作系统作为引导镜像。通过使用 bootc,您可以构建、部署和管理操作系统,就像任何其他容器一样。

  • 此容器镜像使用标准 OCI 或 Docker 容器作为基础操作系统更新的传输和交付格式。
  • bootc 镜像包括用于启动操作系统的 Linux 内核。
  • 通过使用 bootc 容器,开发人员、操作管理员和解决方案提供商都可以使用相同的容器原生工具和技术。

镜像模式会将软件的创建和安装分成两个步骤:一个构建系统上的一个,另一个在正在运行的目标系统中。

  • 在构建系统步骤中,Podman 构建会检查可用于安装的 RPM 文件,确定任何依赖项,并创建了需要完成的链步骤的有序列表,最终结果是可安装的新的操作系统。
  • 在 running-target-system 步骤中,bootc 更新下载、解包,并使新操作系统与当前运行的系统一起启动。本地配置更改将转发到新操作系统,但在重启系统并新操作系统镜像替换正在运行的镜像之前,才会生效。

1.1.1. 在 MicroShift 中使用 RHEL 的镜像模式

要将镜像模式用于 RHEL,请确保以下资源可用:

  • 具有有效红帽订阅的 RHEL 9.4 主机,用于构建 MicroShift bootc 镜像。
  • 用于存储和访问 bootc 镜像的远程 registry。
  • 您可以在 AArch64 或 x86_64 系统架构上使用带有 MicroShift 集群的 RHEL 的镜像模式。

在 MicroShift 中使用镜像模式的工作流包括以下步骤:

  1. 构建 MicroShift bootc 镜像。
  2. 发布镜像。
  3. 运行镜像。此步骤包括配置 MicroShift 网络和存储。
重要

在镜像模式中不支持 rpm-ostree 文件系统,且不得用于更改使用镜像模式的部署。

1.2. 构建 bootc 镜像

使用 Containerfile 构建包含 MicroShift 的 Red Hat Enterprise Linux (RHEL)。

重要

RHEL 的镜像模式是技术预览。不支持在生产环境中使用 bootc 镜像。

先决条件

  • 一个 Red Hat Enterprise Linux (RHEL) 9.4 主机,具有有效的红帽订阅,用于构建 MicroShift bootc 镜像和运行容器。
  • 您使用具有 sudo 权限的用户凭证登录到 RHEL 9.4 主机。
  • rhocpfast-datapath 存储库可在主机订阅中访问。存储库不一定需要在主机上启用。
  • 您有一个远程 registry,如 Red Hat quay,用于存储和访问 bootc 镜像。

流程

  1. 创建一个包含以下指令的 Containerfile :

    RHEL 镜像模式的 Containerfile 示例

    FROM registry.redhat.io/rhel9/rhel-bootc:9.4
    
    ARG USHIFT_VER=4.17
    RUN dnf config-manager \
            --set-enabled rhocp-${USHIFT_VER}-for-rhel-9-$(uname -m)-rpms \
            --set-enabled fast-datapath-for-rhel-9-$(uname -m)-rpms
    RUN dnf install -y firewalld microshift && \
        systemctl enable microshift && \
        dnf clean all
    
    # Create a default 'redhat' user with the specified password.
    # Add it to the 'wheel' group to allow for running sudo commands.
    ARG USER_PASSWD
    RUN if [ -z "${USER_PASSWD}" ] ; then \
            echo USER_PASSWD is a mandatory build argument && exit 1 ; \
        fi
    RUN useradd -m -d /var/home/redhat -G wheel redhat && \
        echo "redhat:${USER_PASSWD}" | chpasswd
    
    # Mandatory firewall configuration
    RUN firewall-offline-cmd --zone=public --add-port=22/tcp && \
        firewall-offline-cmd --zone=trusted --add-source=10.42.0.0/16 && \
        firewall-offline-cmd --zone=trusted --add-source=169.254.169.1
    
    # Create a systemd unit to recursively make the root filesystem subtree
    # shared as required by OVN images
    RUN cat > /etc/systemd/system/microshift-make-rshared.service <<'EOF'
    [Unit]
    Description=Make root filesystem shared
    Before=microshift.service
    ConditionVirtualization=container
    [Service]
    Type=oneshot
    ExecStart=/usr/bin/mount --make-rshared /
    [Install]
    WantedBy=multi-user.target
    EOF
    RUN systemctl enable microshift-make-rshared.service
    Copy to Clipboard Toggle word wrap

    重要

    在构建容器镜像时,Podman 使用容器内的主机订阅信息和存储库。如果主机上没有 rhocpfast-datapath 存储库,则构建会失败。

  2. 运行以下 image build 命令创建本地 bootc 镜像:

    PULL_SECRET=~/.pull-secret.json
    USER_PASSWD=<your_redhat_user_password> 
    1
    
    IMAGE_NAME=microshift-4.17-bootc
    
    $ sudo podman build --authfile "${PULL_SECRET}" -t "${IMAGE_NAME}" \
        --build-arg USER_PASSWD="${USER_PASSWD}" \
        -f Containerfile
    Copy to Clipboard Toggle word wrap
    1
    <your_redhat_user_password& gt; 替换为您的密码。
    注意

    在镜像构建过程中如何使用 secret:

    • 需要 podman-- authfile 参数从 registry.redhat.io registry 中拉取基础 rhel-bootc:9.4 镜像。
    • build USER_PASSWD 参数用于为 redhat 用户设置密码。

验证

  1. 运行以下命令验证本地 bootc 镜像是否已创建:

    $ sudo podman images "${IMAGE_NAME}"
    Copy to Clipboard Toggle word wrap

    输出示例

    REPOSITORY                       TAG         IMAGE ID      CREATED        SIZE
    localhost/microshift-4.17-bootc  latest      193425283c00  2 minutes ago  2.31 GB
    Copy to Clipboard Toggle word wrap

1.3. 将 bootc 镜像发布到远程 registry

将您的 bootc 镜像发布到远程注册表,以便镜像可用于在另一主机上运行容器,或者当您要使用 bootc 镜像层安装新操作系统时。

先决条件

  • 您已登录到使用具有 sudo 权限的用户凭证构建镜像的 RHEL 9.4 主机。
  • 您有一个远程 registry,如 Red Hat quay,用于存储和访问 bootc 镜像。
  • 您创建了 Containerfile 并构建镜像。

流程

  1. 运行以下命令登录到您的远程 registry:

    REGISTRY_URL=quay.io
    
    $ sudo podman login "${REGISTRY_URL}" 
    1
    Copy to Clipboard Toggle word wrap
    1
    REGISTRY_URL 替换为您的 registry 的 URL。
  2. 运行以下命令来发布镜像:

    REGISTRY_IMG=<myorg/mypath>/"${IMAGE_NAME}" 
    1
     
    2
    
    IMAGE_NAME=<microshift-4.17-bootc> 
    3
    
    
    $ sudo podman push localhost/"${IMAGE_NAME}" "${REGISTRY_URL}/${REGISTRY_IMG}"
    Copy to Clipboard Toggle word wrap
    1
    <myorg/mypath > 替换为您的远程 registry 机构名称和路径。
    2
    <microshift-4.17-bootc > 替换为您要发布的镜像的名称。

验证

  1. 使用推送到 registry 的镜像运行容器,如 "Running the MicroShift bootc container" 部分所述。

1.4.1. 为 CNI 配置 MicroShift bootc 镜像

为内核不匹配配置临时解决方案,以启用 MicroShift OVN-Kubernetes (OVN-K) Container Network Interface (CNI)。

重要

MicroShift OVN-K CNI 需要 openvswitch 内核模块在 bootc 镜像中可用。bootc 镜像作为使用主机内核的容器启动。主机内核可能与构建镜像的不同,从而导致不匹配。内核版本与 /lib/modules 目录中的模块不匹配,这意味着无法在容器中加载 openvswitch 模块,容器无法运行。您可以通过在主机上预加载 openvswitch 模块来解决这个问题。

先决条件

  • 一个 Red Hat Enterprise Linux (RHEL) 9.4 主机,具有有效的红帽订阅,用于构建 MicroShift bootc 镜像和运行容器。
  • 您使用具有 sudo 权限的用户凭证登录到 RHEL 9.4 主机。

流程

  1. 运行以下命令,检查 openvswitch 模块可用于当前主机内核版本:

    $ find /lib/modules/$(uname -r) -name "openvswitch*"
    Copy to Clipboard Toggle word wrap

    输出示例

    /lib/modules/5.14.0-427.28.1.el9_4.x86_64/kernel/net/openvswitch
    /lib/modules/5.14.0-427.28.1.el9_4.x86_64/kernel/net/openvswitch/openvswitch.ko.xz
    Copy to Clipboard Toggle word wrap

  2. 运行以下命令设置 IMAGE_NAME 环境变量:

    $ IMAGE_NAME=microshift-4.17-bootc
    Copy to Clipboard Toggle word wrap
  3. 运行以下命令,检查 bootc 镜像中使用的 kernel-core 软件包版本

    $ sudo podman inspect "${IMAGE_NAME}" | grep kernel-core
    Copy to Clipboard Toggle word wrap

    输出示例

    "created_by": "kernel-core-5.14.0-427.26.1.el9_4.x86_64" 
    1
    Copy to Clipboard Toggle word wrap

    1
    内核版本与 /lib/modules 目录的输出不匹配。
  4. 运行以下命令,在主机上预安装 openvswitch 模块作为临时解决方案:

    $ sudo modprobe openvswitch
    Copy to Clipboard Toggle word wrap

1.4.2. 检查 MicroShift CSI 的主机配置

如果主机已配置为具有可用空间的卷组(VG),则该配置由容器继承。MicroShift 逻辑卷管理器(LVM)容器存储接口(CSI)可以使用 VG 来分配存储。

先决条件

  • 一个 Red Hat Enterprise Linux (RHEL) 9.4 主机,具有有效的红帽订阅,用于构建 MicroShift bootc 镜像和运行容器。
  • 您使用具有 sudo 权限的用户凭证登录到 RHEL 9.4 主机。

流程

  1. 运行以下命令确定卷组是否存在,并具有所需的可用空间:

    $ sudo vgs
    Copy to Clipboard Toggle word wrap

    现有卷组的输出示例

      VG   #PV #LV #SN Attr   VSize   VFree 
    1
    
      rhel   1   1   0 wz--n- <91.02g <2.02g
    Copy to Clipboard Toggle word wrap

    1
    如果没有可用的卷组,输出为空,或者 VFree 值为 0。
    注意

    如果主机有一个有可用存储的卷组,您可以立即运行容器。您不需要进一步配置 MicroShift CSI。

    重要

    如果您没有卷组,则必须为 LVM CSI 设置一个,以便在 bootc MicroShift 容器中分配存储。如需更多信息,请参阅其他资源。

当主机上没有带有所需存储的卷组时,请使用这个步骤。创建并分配要与容器共享的额外 LVM 卷组循环设备,并由 MicroShift 逻辑卷管理器(LVM)容器存储接口(CSI)使用。

注意

如果您在检查 MicroShift CSI 的主机配置时找到一个有足够空间的卷组,则不需要完成此步骤。继续运行 bootc 镜像。

先决条件

  • 一个 Red Hat Enterprise Linux (RHEL) 9.4 主机,具有有效的红帽订阅,用于构建 MicroShift bootc 镜像和运行容器。
  • 您使用具有 sudo 权限的用户凭证登录到 RHEL 9.4 主机。

流程

  1. 运行以下命令,创建一个用于 LVM 分区的文件:

    VGFILE=/var/lib/microshift-lvm-storage.img
    
    sudo losetup -f "${VGFILE}"
    Copy to Clipboard Toggle word wrap
  2. 运行以下命令,将文件调整为指定的大小:

    VGSIZE=1G 
    1
    
    
    $ sudo truncate --size="${VGSIZE}" "${VGFILE}"
    Copy to Clipboard Toggle word wrap
    1
    指定文件的大小。
  3. 运行以下命令来查询 loop 设备名称:

    $ VGLOOP=$(losetup -j ${VGFILE} | cut -d: -f1)
    Copy to Clipboard Toggle word wrap
  4. 运行以下命令,在 loop 设备中创建空闲卷组:

    $ sudo vgcreate -f -y <my-volume-group> "${VGLOOP}" 
    1
    Copy to Clipboard Toggle word wrap
    1
    将 < my-volume-group > 替换为您要创建的卷组的名称。

1.5. 运行 MicroShift bootc 容器

运行 MicroShift bootc 容器,以探索其复杂性并试验新的功能和依赖项。

先决条件

  • 一个 Red Hat Enterprise Linux (RHEL) 9.4 主机,具有有效的红帽订阅,用于构建 MicroShift bootc 镜像和运行容器。
  • 您使用具有 sudo 权限的用户凭证登录到 RHEL 9.4 主机。
  • 您有一个 pull secret 文件,用于下载所需的 MicroShift 容器镜像。

流程

  1. 输入以下命令为 MicroShift 服务运行容器:

    PULL_SECRET=~/.pull-secret.json
    IMAGE_NAME=microshift-4.17-bootc
    
    $ sudo podman run --rm -it --privileged \
        -v "${PULL_SECRET}":/etc/crio/openshift-pull-secret:ro \
        -v /var/lib/containers/storage:/var/lib/containers/storage \
        --name "${IMAGE_NAME}" \
        "${IMAGE_NAME}"
    Copy to Clipboard Toggle word wrap
    注意

    如果主机内核版本与 bootc 镜像内核版本不同,systemd-modules-load 服务将无法在容器中启动。可以安全地忽略此故障,因为主机已加载了所有必要的内核模块。

  2. MicroShift 启动后,终端会显示登录提示。
  3. 使用您的用户凭据登录正在运行的容器。
  4. 运行以下命令,验证所有 MicroShift pod 是否正在运行,且没有错误:

    $ watch sudo oc get pods -A \
        --kubeconfig /var/lib/microshift/resources/kubeadmin/kubeconfig
    Copy to Clipboard Toggle word wrap

    输出示例

    NAMESPACE                  NAME                                       READY   STATUS    RESTARTS      AGE
    kube-system                csi-snapshot-controller-7cfb9df49c-kc9dx   1/1     Running   0             31s
    kube-system                csi-snapshot-webhook-5c6b978878-jzk5r      1/1     Running   0             28s
    openshift-dns              dns-default-rpnlt                          2/2     Running   0             14s
    openshift-dns              node-resolver-rxvdk                        1/1     Running   0             31s
    openshift-ingress          router-default-69cd7b5545-7zcw7            1/1     Running   0             29s
    openshift-ovn-kubernetes   ovnkube-master-c7hlh                       4/4     Running   1 (16s ago)   31s
    openshift-ovn-kubernetes   ovnkube-node-mkpht                         1/1     Running   1 (17s ago)   31s
    openshift-service-ca       service-ca-5d5d96459d-5pd5s                1/1     Running   0             28s
    openshift-storage          topolvm-controller-677cbfcdb9-28dqr        5/5     Running   0             31s
    openshift-storage          topolvm-node-6fzbl                         3/3     Running   0             14s
    Copy to Clipboard Toggle word wrap

  5. 现在,您可以使用在容器中运行的 MicroShift,与使用任何其他 MicroShift 集群一样。

1.5.1. 远程访问 MicroShift 集群

使用以下步骤,使用 kubeconfig 文件从远程位置访问 MicroShift 集群。

user@workstation 登录用于远程访问主机计算机。该流程中的 <user> 值是 user@workstation 登录到 MicroShift 主机所使用的用户名。

先决条件

  • 已安装 oc 二进制文件。
  • user@microshift 已打开来自本地主机的防火墙。

流程

  1. user@workstation 的身份,如果 Red Hat Enterprise Linux (RHEL)机器没有,使用以下命令创建一个 ~/.kube/ 文件夹:

    [user@workstation]$ mkdir -p ~/.kube/
    Copy to Clipboard Toggle word wrap
  2. user@workstation 的身份,运行以下命令来为您的 MicroShift 主机的主机名设置变量:

    [user@workstation]$ MICROSHIFT_MACHINE=<name or IP address of MicroShift machine>
    Copy to Clipboard Toggle word wrap
  3. user@workstation 的身份,运行以下命令来复制生成的 kubeconfig 文件,该文件包含您要从运行 MicroShift 的 RHEL 机器连接到本地机器的主机名或 IP 地址:

    [user@workstation]$ ssh <user>@$MICROSHIFT_MACHINE "sudo cat /var/lib/microshift/resources/kubeadmin/$MICROSHIFT_MACHINE/kubeconfig" > ~/.kube/config
    Copy to Clipboard Toggle word wrap
    注意

    要为此步骤生成 kubeconfig 文件,请参阅为远程访问生成额外的 kubeconfig 文件

  4. user@workstation 的身份,运行以下命令来更新 ~/.kube/config 文件的权限:

    $ chmod go-r ~/.kube/config
    Copy to Clipboard Toggle word wrap

验证

  • user@workstation 的身份,输入以下命令验证 MicroShift 是否正在运行:

    [user@workstation]$ oc get all -A
    Copy to Clipboard Toggle word wrap

1.6. 为 bootc 镜像和 MicroShift CSI 清理容器存储

您可以删除与容器共享的额外 LVM 卷组循环设备,并由 MicroShift 逻辑卷管理器(LVM)容器存储接口(CSI)使用。

先决条件

  • 一个 Red Hat Enterprise Linux (RHEL) 9.4 主机,具有有效的红帽订阅,用于构建 MicroShift bootc 镜像和运行容器。
  • 您使用具有 sudo 权限的用户凭证登录到 RHEL 9.4 主机。

流程

  1. 使用以下命令清理 loop 设备和其他卷组:

    1. 输入以下命令分离 loop 设备:

      $ sudo losetup -d "${VGLOOP}"
      Copy to Clipboard Toggle word wrap
    2. 输入以下命令删除 LVM 卷组文件:

      $ sudo rm -f "${VGFILE}"
      Copy to Clipboard Toggle word wrap

1.7. 其他资源

法律通告

Copyright © 2025 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2025 Red Hat