使用 RHEL 镜像模式安装


Red Hat build of MicroShift 4.18

在 bootc 镜像中嵌入 MicroShift

Red Hat OpenShift Documentation Team

摘要

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

您可以使用 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.2. 其他资源

第 2 章 安装 bootc 镜像并发布到 registry

MicroShift 作为镜像模式容器构建并发布。当使用 MicroShift 安装 Red Hat Enterprise Linux (RHEL)可引导的容器镜像时,请使用预构建可引导的容器镜像或构建您自己的自定义可引导容器镜像。

重要

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

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

2.1. 使用 MicroShift 工作流的 RHEL 的镜像模式

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

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

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

  1. 查找并使用预构建的 MicroShift 容器镜像来安装 Red Hat Enterprise Linux (RHEL)。
  2. 如果预构建的 MicroShift 容器镜像需要自定义,则构建自定义 MicroShift 容器镜像。
  3. 运行容器镜像。
重要

在镜像模式中不支持 rpm-ostree 文件系统。不要使用 rpm-ostree 文件系统来修改使用镜像模式的部署。

2.2. 获取或构建 bootc 镜像

获取现有 bootc 镜像或创建一个镜像,然后将该镜像发布到远程 registry 中以供使用。

2.2.1. 为 MicroShift 获取公布的 bootc 镜像

您可以使用 MicroShift 容器镜像为 RHEL 安装镜像模式。

先决条件

  • 您有一个 x86_64 或 AArch64 平台。
  • 您可以访问 registry.redhat.io registry。

流程

  1. 导航到 红帽生态系统目录
  2. 使用 microshift-bootc 关键字搜索 MicroShift 容器镜像。
  3. 打开 MicroShift 容器镜像的容器镜像页面。
  4. 请参阅 OverviewTechnical Information 选项卡,以获取有关镜像的更多详细信息。
  5. 选择 Get this image 选项卡来查看下载镜像的说明。
  6. 使用以下命令登录到 registry,获取 x86_64 和 AArch64 平台上的最新镜像:

    $ sudo podman login registry.redhat.io
    Copy to Clipboard Toggle word wrap
  7. 运行以下命令来下载 bootc 镜像:

    $ podman pull registry.redhat.io/openshift4/microshift-bootc-rhel9:v4.18
    Copy to Clipboard Toggle word wrap

2.2.2. 构建 bootc 镜像

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

重要

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

先决条件

  • 具有有效红帽订阅的 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.18
    RUN dnf config-manager \
            --set-enabled rhocp-${USHIFT_VER}-for-9-$(uname -m)-rpms \
            --set-enabled fast-datapath-for-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. 设置 PULL_SECRET 环境变量:

    $ PULL_SECRET=~/.pull-secret.json
    Copy to Clipboard Toggle word wrap
  3. 配置 USER_PASSWD 环境变量:

    $ USER_PASSWD=<redhat_user_password> 
    1
    Copy to Clipboard Toggle word wrap
    1
    <redhat_user_password& gt; 替换为您的密码。
  4. 配置 IMAGE_NAME 环境变量:

    $ IMAGE_NAME=microshift-4.18-bootc
    Copy to Clipboard Toggle word wrap
  5. 运行以下 image build 命令创建本地 bootc 镜像:

    $ sudo podman build --authfile "${PULL_SECRET}" -t "${IMAGE_NAME}" \
        --build-arg USER_PASSWD="${USER_PASSWD}" \
        -f Containerfile
    Copy to Clipboard Toggle word wrap
    重要

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

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

验证

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

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

    输出示例

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

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

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

先决条件

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

流程

  1. 运行以下命令,为镜像设置 REGISTRY_URL 变量:

    $ REGISTRY_URL=<quay.io> 
    1
    Copy to Clipboard Toggle word wrap
    1
    <quay.io > 替换为镜像 registry 的 URL。
  2. 运行以下命令登录到您的远程 registry:

    $ sudo podman login "${REGISTRY_URL}"
    Copy to Clipboard Toggle word wrap
  3. 运行以下命令,为镜像设置 IMAGE_NAME 变量:

    $ IMAGE_NAME=<microshift-4.18-bootc> 
    1
    Copy to Clipboard Toggle word wrap
    1
    <microshift-4.18-bootc > 替换为您要发布的镜像的名称。
  4. 运行以下命令,为镜像设置 REGISTRY_IMG 变量:

    $ REGISTRY_IMG=<myorg/mypath>/"${IMAGE_NAME}" 
    1
    Copy to Clipboard Toggle word wrap
    1
    <myorg/mypath > 替换为您的远程 registry 机构名称和路径。
  5. 运行以下命令来发布镜像:

    $ sudo podman push localhost/"${IMAGE_NAME}" "${REGISTRY_URL}/${REGISTRY_IMG}"
    Copy to Clipboard Toggle word wrap

验证

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

第 3 章 在虚拟机中运行 bootc 镜像

使用可引导容器镜像作为安装源来设置 Red Hat Enterprise Linux (RHEL)虚拟机。

重要

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

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

3.1. 创建 Kickstart 文件

您必须创建要在安装过程中使用的 Kickstart 文件。

先决条件

  • 您有 root-user 访问权限。
  • 您已登录到物理 hypervisor 主机。

流程

  1. 运行以下命令,设置 AUTH_CONFIG 环境变量来引用 kickstart.ks 文件中的 secret 文件,以验证私有容器 registry 访问:

    $ AUTH_CONFIG=~/.quay-auth.json
    Copy to Clipboard Toggle word wrap
  2. 运行以下命令,设置 PULL_SECRET 环境变量来引用 kickstart.ks 文件中的 secret 文件,以验证 OpenShift Container Platform registry 访问:

    $ PULL_SECRET=~/.pull-secret.json
    Copy to Clipboard Toggle word wrap
  3. 运行以下命令,将 IMAGE_REF 环境变量设置为引用要在安装过程中使用的容器镜像的镜像模式:

    $ IMAGE_REF="quay.io/<myorg>/<mypath>/microshift-4.18-bootc" 
    1
    Copy to Clipboard Toggle word wrap
    1
    <myorg/<mypath > 替换为您的远程 registry 机构名称和路径。
  4. 通过运行以下脚本来创建在安装过程中使用的 kickstart.ks 文件:

    $ cat > kickstart.ks <<EOFKS
    lang en_US.UTF-8
    keyboard us
    timezone UTC
    text
    reboot
    
    # Partition the disk with hardware-specific boot and swap partitions, adding an
    # LVM volume that contains a 10GB+ system root. The remainder of the volume will
    # be used by the CSI driver for storing data.
    zerombr
    clearpart --all --initlabel
    # Create boot and swap partitions as required by the current hardware platform
    reqpart --add-boot
    # Add an LVM volume group and allocate a system root logical volume
    part pv.01 --grow
    volgroup rhel pv.01
    logvol / --vgname=rhel --fstype=xfs --size=10240 --name=root
    
    # Lock root user account
    rootpw --lock
    
    # Configure network to use DHCP and activate on boot
    network --bootproto=dhcp --device=link --activate --onboot=on
    
    %pre-install --log=/dev/console --erroronfail
    
    # Create a 'bootc' image registry authentication file
    mkdir -p /etc/ostree
    cat > /etc/ostree/auth.json <<'EOF'
    $(cat "${AUTH_CONFIG}")
    EOF
    
    %end
    
    # Pull a 'bootc' image from a remote registry
    ostreecontainer --url "${IMAGE_REF}"
    
    %post --log=/dev/console --erroronfail
    
    # Create an OpenShift pull secret file
    cat > /etc/crio/openshift-pull-secret <<'EOF'
    $(cat "${PULL_SECRET}")
    EOF
    chmod 600 /etc/crio/openshift-pull-secret
    
    %end
    EOFKS
    Copy to Clipboard Toggle word wrap

3.2. 创建虚拟机

您可以使用 Red Hat Enterprise Linux (RHEL)引导 ISO 镜像创建虚拟机。

先决条件

  • 您创建了 Kickstart 文件。
  • 已安装 OpenShift CLI(oc)。
  • 您有 redhat 凭据。

流程

  1. Download Red Hat Enterprise Linux 下载 Red Hat Enterprise Linux (RHEL)引导 ISO 镜像。
  2. 将下载的文件复制到 /var/lib/libvirt/images 目录。
  3. 运行以下命令,使用值配置 VMNAME 环境变量:

    $ VMNAME=microshift-4.18-bootc
    Copy to Clipboard Toggle word wrap
  4. 运行以下命令,使用您的值配置 NETNAME 环境变量:

    $ NETNAME=default
    Copy to Clipboard Toggle word wrap
  5. 运行以下命令,创建一个具有 2 个内核、2GB RAM 和 20GB 存储的 Red Hat Enterprise Linux (RHEL)虚拟机:

    $ sudo virt-install \
        --name ${VMNAME} \
        --vcpus 2 \
        --memory 2048 \
        --disk path=/var/lib/libvirt/images/${VMNAME}.qcow2,size=20 \
        --network network=${NETNAME},model=virtio \
        --events on_reboot=restart \
        --location /var/lib/libvirt/images/rhel-9.4-$(uname -m)-boot.iso \
        --initrd-inject kickstart.ks \
        --extra-args "inst.ks=file://kickstart.ks" \
        --wait
    Copy to Clipboard Toggle word wrap
    注意

    sudo virt-install 命令使用 Kickstart 文件从远程 registry 中拉取 bootc 镜像并安装 RHEL 操作系统。

  6. 使用您的 redhat 凭据登录虚拟机。

验证

  1. 输入以下命令验证所有 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
    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

法律通告

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