1
2
3
4
5
作者:李晓辉

微信:Lxh_Chat

邮箱:xiaohui_li@foxmail.com
角色IP主机名CPU内存操作系统OpenShift 版本
DHCP、NTP、DNS、HAProxy、TFTP、HTTPD192.168.8.200content.cluster1.xiaohui.cn4-8核心8GRHEL9.64.18.15
bootstrap192.168.8.201bootstrap.cluster1.xiaohui.cn4-8核心16Grhcos4.18.15
master192.168.8.202master0.cluster1.xiaohui.cn4-8核心16Grhcos4.18.15
master192.168.8.203master1.cluster1.xiaohui.cn4-8核心16Grhcos4.18.15
master192.168.8.204master2.cluster1.xiaohui.cn4-8核心16Grhcos4.18.15
compute0192.168.8.205compute0.cluster1.xiaohui.cn4-8核心16Grhcos4.18.15
compute1192.168.8.206compute1.cluster1.xiaohui.cn4-8核心16Grhcos4.18.15

请务必确保辅助节点的DNS指向自己,不然有可能节点安装期间会报告找不到api-int域名,无法安装

这篇文章介绍了UPI的方式来部署OpenShift 4.18.15,其中涉及到DHCP、TFTP、DNS、HTTP、HAProxy等基础服务的部署和配置,过程较为复杂,每个服务在部署后,都尽量检查一下是否正常工作,再进行下一步的服务部署,避免中间有遗漏造成效果达不到的情况。

部署DHCP服务

本次 OpenShift UPI 部署采用了 DHCP 自动分配 IP 的方式来初始化 Bootstrap、Master 和 Worker 节点,这不仅省去了手动输入复杂的网络信息,还简化了 CoreOS 的安装参数配置。通过 DHCP 绑定固定 IP,再结合 PXE 配置文件,整个过程变得更加 高效、精准,不仅减少了人为错误,还使得后续重用配置变得更加轻松。

DHCP 配置概览

  • 子网范围:DHCP 运行在 192.168.8.0/24 网络中

  • IP 分配:动态范围为 192.168.8.201 - 192.168.8.250

  • DNS 服务器192.168.8.200 提供域名解析

  • 网关:默认网关设定为 192.168.8.2

  • 识别引导方式:根据 DHCP 客户端发送的厂商识别代码,决定使用 BIOS 或 UEFI 进行 PXE 引导

  • PXE 服务器:客户端接收到网络参数后,会通过 TFTP 连接 192.168.8.200,获取 pxelinux.0grubx64.efi 进行系统启动

在此之前,我配置好了软件仓库,你可以考虑从RHEL9.6的ISO安装软件,这需要你配置yum仓库

1
dnf install dhcp-server -y
  1. 配置文件这里要注意subnet下面的几行,这是我们的工作子网信息与分发地址的信息

  2. 下面我为节点做了dhcp地址的预留,这里要注意mac地址必须要和将来的机器保持一致

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
cat > /etc/dhcp/dhcpd.conf <<EOF
option space PXE;
option arch code 93 = unsigned integer 16; # RFC4578

subnet 192.168.8.0 netmask 255.255.255.0 {
range 192.168.8.201 192.168.8.250;
option routers 192.168.8.2;
option domain-name-servers 192.168.8.200;
default-lease-time 600;
max-lease-time 7200;

class "pxeclients" {
match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
next-server 192.168.8.200;

# 针对不同架构提供正确的引导文件
if option arch = 00:06 {
filename "grubia32.efi"; # UEFI 32-bit (IA32)
} else if option arch = 00:07 {
filename "grubx64.efi"; # UEFI 64-bit (x64)
} else if option arch = 00:08 {
filename "grubx64.efi"; # UEFI 64-bit (x64)
} else if option arch = 00:09 {
filename "grubx64.efi"; # UEFI 64-bit (x64)
} else {
filename "pxelinux.0"; # BIOS 客户端
}
}
}

# 定义静态主机
host bootstrap {
hardware ethernet 00:50:56:94:8a:21;
fixed-address 192.168.8.201;
server-name "bootstrap.cluster1.xiaohui.cn";
}
host master0 {
hardware ethernet 00:50:56:94:07:6d;
fixed-address 192.168.8.202;
server-name "master0.cluster1.xiaohui.cn";
}
host master1 {
hardware ethernet 00:50:56:94:5c:7d;
fixed-address 192.168.8.203;
server-name "master1.cluster1.xiaohui.cn";
}
host master2 {
hardware ethernet 00:50:56:94:b6:21;
fixed-address 192.168.8.204;
server-name "master2.cluster1.xiaohui.cn";
}
host compute0 {
hardware ethernet 00:50:56:94:ce:83;
fixed-address 192.168.8.205;
server-name "compute0.cluster1.xiaohui.cn";
}
host compute1 {
hardware ethernet 00:50:56:94:fd:5a;
fixed-address 192.168.8.206;
server-name "compute1.cluster1.xiaohui.cn";
}
EOF

不要忘记启动dhcpd服务以及开通dhcp防火墙

1
2
3
systemctl enable dhcpd --now
firewall-cmd --add-service=dhcp --permanent
firewall-cmd --reload

配置NTP

在 OpenShift UPI 部署中,时间同步 是至关重要的一环,确保所有节点的日志时间一致,避免因时间漂移导致的调度、认证或日志对齐问题。

本次配置采用 ntp.aliyun.com 作为 content.cluster1.xiaohui.cn 的上游时间源,并将 content 机器作为 NTP 服务器,向 192.168.8.0/24 网段内的所有节点提供时间同步服务。这样,每个 OpenShift 节点都能准确获取统一的时间,提高集群的稳定性和一致性。

这种方式的好处:

  • 减少外网依赖:所有内网节点都从 content 服务器获取时间,不直接访问公网 NTP,降低安全风险。

  • 时间同步统一性:确保 Master、Worker 以及辅助节点的时间完全一致,防止日志时间错乱。

  • 稳定性与可扩展性:可以轻松扩展更多节点,而无需额外的时间同步配置。

接下来,可以在 content 机器上配置 ChronyNTP 服务,并确保所有 OpenShift 节点都指向它作为时间源。

1
2
3
4
5
6
dnf install chrony -y
sed -i '/^pool/a\pool ntp.aliyun.com iburst' /etc/chrony.conf
sed -i '/^# allow/a\allow 192.168.8.0/24' /etc/chrony.conf
systemctl enable chronyd --now
firewall-cmd --add-service=ntp --permanent
firewall-cmd --reload

配置HTTPD

在 PXE 过程中,节点需要通过网络下载 rootfs 以及各个节点的 Ignition 配置文件,所以我们需要一个 HTTP 服务器 来托管这些内容。本次部署选择 httpd 作为 Web 服务器,并使用 2000 端口 提供相关文件,以避免端口冲突。

为什么使用 2000 端口?

  • 避免与 OpenShift Ingress 冲突:后续 HAProxy 需要占用 80 端口 以处理 OpenShift 的 Ingress 流量,因此 PXE 相关的 HTTP 服务最好另选端口。

  • 灵活扩展:如果你规划了其他 HTTP 服务,比如私有镜像仓库、API 服务器等,可以继续使用 80 端口 以保持兼容性。

这样配置的好处

自动化 PXE 部署 —— 节点启动后,自动从 HTTP 服务器获取 rootfs 和 Ignition 配置,无需手动操作。
端口规划合理 —— HTTP 服务器不占用 80 端口,避免和 OpenShift 的 Ingress 服务冲突。
易于重用 —— 未来扩展其他节点时,只需调整 Ignition 文件,无需手动更改 PXE 配置。

1
2
3
4
dnf install httpd policycoreutils-python-utils -y
semanage port -m -t http_port_t -p tcp 2000
mkdir /content
sed -i 's/Listen 80/Listen 2000/g' /etc/httpd/conf/httpd.conf

我这里启用了2000端口,并将内容指向/content

1
2
3
4
5
6
7
8
9
10
11
cat > /etc/httpd/conf.d/customsite.conf << 'EOF'
<VirtualHost *:2000>
ServerName content.cluster.xiaohui.cn
DocumentRoot "/content"
</VirtualHost>
<Directory "/content">
<RequireAll>
Require all granted
</RequireAll>
</Directory>
EOF

启用防火墙

1
2
3
firewall-cmd --add-port=2000/tcp --permanent
firewall-cmd --reload
systemctl enable httpd --now

配置DNS

在 OpenShift UPI 部署中,DNS 配置 影响着整个集群的稳定性和可用性,特别是在 Master API 访问、节点解析以及 Ingress 负载均衡方面。

本次集群的 DNS 规划使用 xiaohui.cn 作为根域,集群名称设定为 cluster1。由于 DHCP 绑定已经提供了主机名分配,PTR 记录仍然至关重要,它能直接设定主机名,而不依赖 DHCP 解析,确保在一些关键场景(如 IPI 安装)时,主机名称能正确识别。

DNS角色功能
content.cluster1.xiaohui.cnmaterial提供DHCP、HTTP、NTP、HTTP、DNS、TFTP、HAProxy
api.cluster1.xiaohui.cnmaster api提供openshift master api接口,通常指向负载均衡
api-int.cluster1.xiaohui.cnmaster api提供api的内部通信,通常指向负载均衡
*.apps.cluster1.xiaohui.cnAPP应用程序通配符,用于后期集群内的应用暴露,通常指向负载均衡
bootstrap.cluster1.xiaohui.cnbootstrap用于准备集群,集群就绪后可删除
masterX.cluster1.xiaohui.cnmasteropenshift master服务
computeX.cluster1.xiaohui.cnworkeropenshift 计算节点服务

关键 DNS 配置点

  • PTR 记录的重要性:即使 DHCP 绑定了 IP 地址,PTR 记录仍能确保正确的主机名解析,特别是 OpenShift 组件需要 hostname 进行通信。

  • 负载均衡角色api.cluster1.xiaohui.cnapi-int.cluster1.xiaohui.cn 需要指向负载均衡,以保证 OpenShift API 的高可用性。

  • 应用域名规则*.apps.cluster1.xiaohui.cn 允许未来所有 OpenShift 部署的应用暴露到外部,而不需要单独设置每个应用的 DNS 记录。

优化建议

保证 API 解析稳定性——建议 api.cluster1.xiaohui.cnapi-int.cluster1.xiaohui.cn 采用 A 记录 指向负载均衡或使用 CNAME 以提高灵活性。
应用域通配符管理——通过 *.apps.cluster1.xiaohui.cn 处理所有应用访问,简化配置,支持动态应用扩展。
反向解析(PTR 记录)——提前设定各个节点的 PTR 记录,让日志、认证、集群组件能够正确识别主机名,减少解析错误。

在DNS的配置文件中,我们工作在本机的所有IP地址上,并允许所有人来查询DNS记录,同时开启了转发器,有其他查询时,发给114.114.114.114,关闭了dnssec验证

1
dnf install bind bind-utils -y
1
2
3
4
sed -i 's/listen-on port 53 { 127.0.0.1; }/listen-on port 53 { any; }/g' /etc/named.conf
sed -i 's/allow-query { localhost; };/allow-query { any; };/g' /etc/named.conf
sed -i '/recursion yes;/a\ forward first;\n forwarders { 114.114.114.114; };' /etc/named.conf
sed -i 's/dnssec-validation yes;/dnssec-validation no;/' /etc/named.conf

这里我们为cluster1.xiaohui.cn域名提供了正向和反向解析

1
2
3
4
5
6
7
8
9
10
11
cat >> /etc/named.rfc1912.zones <<EOF
zone "cluster1.xiaohui.cn" IN {
type master;
file "cluster1.xiaohui.cn.zone";
};

zone "8.168.192.in-addr.arpa" IN {
type master;
file "cluster1.xiaohui.cn.ptr";
};
EOF

以下是区域文件中具体的解析内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
cat > /var/named/cluster1.xiaohui.cn.zone <<'EOF'
$TTL 1W
@ IN SOA ns1.cluster1.xiaohui.cn. root.cluster1.xiaohui.cn (
1 ; serial
3H ; refresh (3 hours)
30M ; retry (30 minutes)
2W ; expiry (2 weeks)
1W ) ; minimum (1 week)
IN NS ns1.cluster1.xiaohui.cn.
ns1.cluster1.xiaohui.cn. IN A 192.168.8.200
content.cluster1.xiaohui.cn. IN A 192.168.8.200
api.cluster1.xiaohui.cn. IN A 192.168.8.200
api-int.cluster1.xiaohui.cn. IN A 192.168.8.200
*.apps.cluster1.xiaohui.cn. IN A 192.168.8.200
bootstrap.cluster1.xiaohui.cn. IN A 192.168.8.201
master0.cluster1.xiaohui.cn. IN A 192.168.8.202
master1.cluster1.xiaohui.cn. IN A 192.168.8.203
master2.cluster1.xiaohui.cn. IN A 192.168.8.204
compute0.cluster1.xiaohui.cn. IN A 192.168.8.205
compute1.cluster1.xiaohui.cn. IN A 192.168.8.206
EOF


cat > /var/named/cluster1.xiaohui.cn.ptr <<'EOF'
$TTL 1W
@ IN SOA ns1.cluster1.xiaohui.cn. root.cluster1.xiaohui.cn (
1 ; serial
3H ; refresh (3 hours)
30M ; retry (30 minutes)
2W ; expiry (2 weeks)
1W ) ; minimum (1 week)
IN NS ns1.cluster1.xiaohui.cn.


200.8.168.192.in-addr.arpa. IN PTR ns1.cluster1.xiaohui.cn.
200.8.168.192.in-addr.arpa. IN PTR content.cluster1.xiaohui.cn.
200.8.168.192.in-addr.arpa. IN PTR api.cluster1.xiaohui.cn.
200.8.168.192.in-addr.arpa. IN PTR api-int.cluster1.xiaohui.cn.
201.8.168.192.in-addr.arpa. IN PTR bootstrap.cluster1.xiaohui.cn.
202.8.168.192.in-addr.arpa. IN PTR master0.cluster1.xiaohui.cn.
203.8.168.192.in-addr.arpa. IN PTR master1.cluster1.xiaohui.cn.
204.8.168.192.in-addr.arpa. IN PTR master2.cluster1.xiaohui.cn.
205.8.168.192.in-addr.arpa. IN PTR compute0.cluster1.xiaohui.cn.
206.8.168.192.in-addr.arpa. IN PTR compute1.cluster1.xiaohui.cn.
EOF

这里要注意把区域文件的owner和group设置为named

1
2
3
4
chown named:named /var/named -R
systemctl enable named --now
firewall-cmd --add-service=dns --permanent
firewall-cmd --reload

配置TFTP

在 OpenShift UPI 部署中,TFTP 服务是 PXE 启动 的关键环节之一,它负责让客户端在 获取 DHCP IP 后,能够从指定的 next-server 下载所需的 内核、驱动PXE 配置文件,确保节点能正确引导系统。

TFTP 作用

  • 提供 PXE 启动所需的文件,如 pxelinux.0grubx64.efiinitramfs.imgvmlinuz

  • 让客户端能够从网络启动,避免手动引导

  • 与 DHCP 结合,自动化服务器引导过程,提高集群部署效率

为了确保 PXE 启动的顺利进行,我们在 content.cluster1.xiaohui.cn 机器上安装 TFTP 服务:

1
2
3
4
5
dnf install tftp-server -y
systemctl enable tftp.service --now
systemctl enable tftp.socket --now
firewall-cmd --add-service=tftp --permanent
firewall-cmd --reload

下载安装资料

以下连接可以确保你下载到最新版本的openshift安装资料

1
2
3
4
5
6
wget -O /content/openshift-client-linux.tar.gz https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/stable/openshift-client-linux.tar.gz
tar Cxvf /usr/local/bin/ /content/openshift-client-linux.tar.gz
wget -O /content/rhcos-live.x86_64.iso https://mirror.openshift.com/pub/openshift-v4/x86_64/dependencies/rhcos/latest/rhcos-live.x86_64.iso
wget -O /var/lib/tftpboot/rhcos-live-kernel-x86_64 https://mirror.openshift.com/pub/openshift-v4/x86_64/dependencies/rhcos/latest/rhcos-live-kernel-x86_64
wget -O /var/lib/tftpboot/rhcos-live-initramfs.x86_64.img https://mirror.openshift.com/pub/openshift-v4/x86_64/dependencies/rhcos/latest/rhcos-live-initramfs.x86_64.img
wget -O /content/rhcos-live-rootfs.x86_64.img https://mirror.openshift.com/pub/openshift-v4/x86_64/dependencies/rhcos/latest/rhcos-live-rootfs.x86_64.img

准备PXE文件

将pxelinux.0、grubx64.efi、kernel、initramfs等资料复制到tftp供客户端拿取,以及创建pxe所需的引导配置文件和目录

1
2
3
4
5
6
mkdir /var/lib/tftpboot/pxelinux.cfg
dnf install syslinux -y
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
mount /content/rhcos-live.x86_64.iso /opt
cp /opt/isolinux/* /var/lib/tftpboot
cp /boot/efi/EFI/redhat/grubx64.efi /var/lib/tftpboot/

BIOS 启动:

文件里的ip=后面的内容可以直接改成ip=dhcp,省的写那么多,你还猜不到对方网卡名叫啥,不过能按照这个写是最好的,实在不行你就安装一个虚拟机,进去看看它在你电脑上跑起来,硬盘名和网卡名叫啥也可以的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
cat > /var/lib/tftpboot/pxelinux.cfg/default <<EOF
UI vesamenu.c32
TIMEOUT 20
PROMPT 0
LABEL bootstrap
menu label bootstrap
KERNEL rhcos-live-kernel-x86_64
APPEND initrd=rhcos-live-initramfs.x86_64.img coreos.live.rootfs_url=http://192.168.8.200:2000/rhcos-live-rootfs.x86_64.img coreos.inst.install_dev=/dev/sda coreos.inst.ignition_url=http://192.168.8.200:2000/bootstrap.ign ip=192.168.8.201::192.168.8.2:255.255.255.0:bootstrap.cluster1.xiaohui.cn:ens192:none nameserver=192.168.8.200
LABEL master0
menu label master0
KERNEL rhcos-live-kernel-x86_64
APPEND initrd=rhcos-live-initramfs.x86_64.img coreos.live.rootfs_url=http://192.168.8.200:2000/rhcos-live-rootfs.x86_64.img coreos.inst.install_dev=/dev/sda coreos.inst.ignition_url=http://192.168.8.200:2000/master.ign ip=192.168.8.202::192.168.8.2:255.255.255.0:master0.cluster1.xiaohui.cn:ens192:none nameserver=192.168.8.200
LABEL master1
menu label master1
KERNEL rhcos-live-kernel-x86_64
APPEND initrd=rhcos-live-initramfs.x86_64.img coreos.live.rootfs_url=http://192.168.8.200:2000/rhcos-live-rootfs.x86_64.img coreos.inst.install_dev=/dev/sda coreos.inst.ignition_url=http://192.168.8.200:2000/master.ign ip=192.168.8.203::192.168.8.2:255.255.255.0:master1.cluster1.xiaohui.cn:ens192:none nameserver=192.168.8.200
LABEL master2
menu label master2
KERNEL rhcos-live-kernel-x86_64
APPEND initrd=rhcos-live-initramfs.x86_64.img coreos.live.rootfs_url=http://192.168.8.200:2000/rhcos-live-rootfs.x86_64.img coreos.inst.install_dev=/dev/sda coreos.inst.ignition_url=http://192.168.8.200:2000/master.ign ip=192.168.8.204::192.168.8.2:255.255.255.0:master2.cluster1.xiaohui.cn:ens192:none nameserver=192.168.8.200
LABEL compute0
menu label compute0
KERNEL rhcos-live-kernel-x86_64
APPEND initrd=rhcos-live-initramfs.x86_64.img coreos.live.rootfs_url=http://192.168.8.200:2000/rhcos-live-rootfs.x86_64.img coreos.inst.install_dev=/dev/sda coreos.inst.ignition_url=http://192.168.8.200:2000/worker.ign ip=192.168.8.205::192.168.8.2:255.255.255.0:compute0.cluster1.xiaohui.cn:ens192:none nameserver=192.168.8.200
LABEL compute1
menu label compute1
KERNEL rhcos-live-kernel-x86_64
APPEND initrd=rhcos-live-initramfs.x86_64.img coreos.live.rootfs_url=http://192.168.8.200:2000/rhcos-live-rootfs.x86_64.img coreos.inst.install_dev=/dev/sda coreos.inst.ignition_url=http://192.168.8.200:2000/worker.ign ip=192.168.8.206::192.168.8.2:255.255.255.0:compute1.cluster1.xiaohui.cn:ens192:none nameserver=192.168.8.200
EOF
1
2
restorecon -RvF /var/lib/tftpboot/
chmod a+rx /var/lib/tftpboot -R

UEFI 启动:

文件里的ip=后面的内容可以直接改成ip=dhcp,省的写那么多,你还猜不到对方网卡名叫啥,不过能按照这个写是最好的,实在不行你就安装一个虚拟机,进去看看它在你电脑上跑起来,硬盘名和网卡名叫啥也可以的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
cat > /var/lib/tftpboot/grub.cfg <<EOF
set timeout=10
menuentry 'bootstrap' {
linuxefi rhcos-live-kernel-x86_64 coreos.live.rootfs_url=http://192.168.8.200:2000/rhcos-live-rootfs.x86_64.img coreos.inst.install_dev=/dev/sda coreos.inst.ignition_url=http://192.168.8.200:2000/bootstrap.ign ip=192.168.8.201::192.168.8.2:255.255.255.0:bootstrap.cluster1.xiaohui.cn:ens192:none nameserver=192.168.8.200
initrdefi rhcos-live-initramfs.x86_64.img
}
menuentry 'master0' {
linuxefi rhcos-live-kernel-x86_64 coreos.live.rootfs_url=http://192.168.8.200:2000/rhcos-live-rootfs.x86_64.img coreos.inst.install_dev=/dev/sda coreos.inst.ignition_url=http://192.168.8.200:2000/master.ign ip=192.168.8.202::192.168.8.2:255.255.255.0:master0.cluster1.xiaohui.cn:ens192:none nameserver=192.168.8.200
initrdefi rhcos-live-initramfs.x86_64.img
}
menuentry 'master1' {
linuxefi rhcos-live-kernel-x86_64 coreos.live.rootfs_url=http://192.168.8.200:2000/rhcos-live-rootfs.x86_64.img coreos.inst.install_dev=/dev/sda coreos.inst.ignition_url=http://192.168.8.200:2000/master.ign ip=192.168.8.203::192.168.8.2:255.255.255.0:master1.cluster1.xiaohui.cn:ens192:none nameserver=192.168.8.200
initrdefi rhcos-live-initramfs.x86_64.img
}
menuentry 'master2' {
linuxefi rhcos-live-kernel-x86_64 coreos.live.rootfs_url=http://192.168.8.200:2000/rhcos-live-rootfs.x86_64.img coreos.inst.install_dev=/dev/sda coreos.inst.ignition_url=http://192.168.8.200:2000/master.ign ip=192.168.8.204::192.168.8.2:255.255.255.0:master2.cluster1.xiaohui.cn:ens192:none nameserver=192.168.8.200
initrdefi rhcos-live-initramfs.x86_64.img
}
menuentry 'compute0' {
linuxefi rhcos-live-kernel-x86_64 coreos.live.rootfs_url=http://192.168.8.200:2000/rhcos-live-rootfs.x86_64.img coreos.inst.install_dev=/dev/sda coreos.inst.ignition_url=http://192.168.8.200:2000/worker.ign ip=192.168.8.205::192.168.8.2:255.255.255.0:compute0.cluster1.xiaohui.cn:ens192:none nameserver=192.168.8.200
initrdefi rhcos-live-initramfs.x86_64.img
}
menuentry 'compute1' {
linuxefi rhcos-live-kernel-x86_64 coreos.live.rootfs_url=http://192.168.8.200:2000/rhcos-live-rootfs.x86_64.img coreos.inst.install_dev=/dev/sda coreos.inst.ignition_url=http://192.168.8.200:2000/bootstrap.ign ip=192.168.8.206::192.168.8.2:255.255.255.0:compute1.cluster1.xiaohui.cn:ens192:none nameserver=192.168.8.200
initrdefi rhcos-live-initramfs.x86_64.img
}

EOF
1
2
chmod a+rx /var/lib/tftpboot -R
restorecon -RvF /var/lib/tftpboot/

配置HAProxy

在 OpenShift 的多节点环境中,负载均衡 扮演着至关重要的角色,确保集群的各个组件能够稳定、高效地进行通信。根据前面的 DNS 配置,我们可以看到 API 和 Ingress 需要一个 可靠的负载均衡器 来处理流量,而本次部署选择 HAProxy 作为前端负载均衡机制。

为什么选择 HAProxy?

高可用性 —— HAProxy 能够自动分发请求,避免单点故障,提高系统稳定性。
流量管理能力强 —— 通过细粒度的配置,可以针对不同类型的流量(API、Ingress)进行优化。
简单且灵活 —— 与 OpenShift 配合良好,支持 TLS 终止、健康检查等企业级功能。

负载均衡的关键点

  • API 流量 (api.cluster1.xiaohui.cn / api-int.cluster1.xiaohui.cn) —— 负责 OpenShift Master API 负载均衡,确保集群管理的高可用性。

  • 应用访问 (*.apps.cluster1.xiaohui.cn) —— 用于 Ingress 路由,将 OpenShift 内的应用暴露给外部用户。

ok,那我们来完成安装和配置

1
dnf install haproxy -y

端口规划在 OpenShift 部署中至关重要,确保各个组件能够顺利通信,同时避免端口冲突影响功能运行。以下是本次配置的关键端口用途:

  • 6443 端口 —— 提供 API 服务器 访问,集群管理与 Kubernetes 操作均通过此端口完成。

  • 22623 端口 —— 负责 新节点引导,当 Master 或 Worker 节点加入集群时,它们会从该端口获取必要的 Ignition 配置文件,确保启动参数正确。

  • 80 / 443 端口 —— 用于 Ingress 路由,所有 OpenShift 运行的应用流量通过这些端口提供对外访问。

  • 2000 端口 —— 由于 80 端口用于 Ingress,我们的 PXE 相关 HTTP 服务(提供 rootfs 和 Ignition 文件)选择了 2000 端口 避免冲突。

这种 合理的端口规划 确保了:
集群节点能够正确启动 —— 22623 端口提供 Ignition 使新节点完成初始化。
API 请求稳定 —— 6443 端口为所有 OpenShift API 交互提供高可用性。
应用流量无冲突 —— 80/443 端口专门用于 Ingress,保证业务正常运行。
PXE 过程自动化 —— 2000 端口独立提供安装文件,不影响 OpenShift 其他服务。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
cat > /etc/haproxy/haproxy.cfg <<'EOF'
global
log 127.0.0.1 local2
pidfile /var/run/haproxy.pid
maxconn 4000
daemon
defaults
mode http
log global
option dontlognull
option http-server-close
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
frontend stats
bind *:1936
mode http
log global
maxconn 10
stats enable
stats hide-version
stats refresh 30s
stats show-node
stats show-desc Stats for cluster
stats auth admin:admin
stats uri /stats
listen api-server-6443
bind *:6443
mode tcp
server bootstrap bootstrap.cluster1.xiaohui.cn:6443 check inter 1s
server master0 master0.cluster1.xiaohui.cn:6443 check inter 1s
server master1 master1.cluster1.xiaohui.cn:6443 check inter 1s
server master2 master2.cluster1.xiaohui.cn:6443 check inter 1s
listen machine-config-server-22623
bind *:22623
mode tcp
server bootstrap bootstrap.cluster1.xiaohui.cn:22623 check inter 1s
server master0 master0.cluster1.xiaohui.cn:22623 check inter 1s
server master1 master1.cluster1.xiaohui.cn:22623 check inter 1s
server master2 master2.cluster1.xiaohui.cn:22623 check inter 1s
listen ingress-router-443
bind *:443
mode tcp
balance source
server compute0 compute0.cluster1.xiaohui.cn:443 check inter 1s
server compute1 compute1.cluster1.xiaohui.cn:443 check inter 1s
listen ingress-router-80
bind *:80
mode tcp
balance source
server compute0 compute0.cluster1.xiaohui.cn:80 check inter 1s
server compute1 compute1.cluster1.xiaohui.cn:80 check inter 1s
EOF

为了让haproxy能正常工作,我们授权一下端口信息,并开通相对应的防火墙

1
for port in 1936 6443 22623 443 80;do semanage port -a -t http_port_t -p tcp $port;done
1
2
3
systemctl enable haproxy --now
for port in 1936 6443 22623 443 80;do firewall-cmd --add-port=$port/tcp --permanent;done
firewall-cmd --reload

配置SSH密钥

在 CoreOS 中,默认 不提供用户名和密码登录,而是完全依赖 SSH 密钥 进行身份验证。这种方式更加安全,也符合现代云原生操作系统的最佳实践。为了顺利登录,我们需要 生成 SSH 公私钥对,并将公钥配置到 CoreOS 服务器。

1
2
3
ssh-keygen -t ed25519 -N '' -f /root/.ssh/id_ed25519
eval "$(ssh-agent -s)"
ssh-add /root/.ssh/id_ed25519

配置私有仓库

如果你的环境可以直接连接互联网,就不需要做这一步,只有在你的机器不能连接互联网时,才需要做私有仓库步骤,将镜像都下载到私有仓库中,然后再从私有仓库来完成我们离线节点的安装

请自行生成这里所需的证书,可参考证书签发

以下是我本次的私有仓库信息:

  1. 用户名:admin
  2. 密码:lixiaohui
  3. 主机名:content.cluster1.xiaohui.cn

将私有仓库数据存放在/data中

1
2
mkdir /data
dnf install podman jq -y

下载本地容器镜像仓库

1
2
wget https://mirror.openshift.com/pub/cgw/mirror-registry/latest/mirror-registry-amd64.tar.gz
tar Cvxf /usr/local/bin mirror-registry-amd64.tar.gz

完成对自己的密钥信任

1
2
cat /root/.ssh/id_ed25519.pub >> /root/.ssh/authorized_keys
ssh-copy-id root@content.cluster1.xiaohui.cn

完成quay容器仓库的部署

1
2
3
4
mirror-registry install --initPassword lixiaohui --initUser admin \
--quayHostname content.cluster1.xiaohui.cn --quayRoot /data \
--ssh-key /root/.ssh/id_ed25519 --sslCert /etc/pki/tls/certs/xiaohui.cn.crt \
--sslKey /etc/pki/tls/private/xiaohui.cn.key --targetHostname content.cluster1.xiaohui.cn

quay默认工作在8443端口,别忘了开防火墙

1
2
firewall-cmd --add-port=8443/tcp --permanent
firewall-cmd --reload

将我们的quay私有仓库凭据初始化为base64数据

1
2
echo -n 'admin:lixiaohui' | base64 -w0
YWRtaW46bGl4aWFvaHVp

本地和远程拉取密钥合并

先格式化从官网下载的文件,官网的auth为了隐私,我删减了一部分,官网链接:https://console.redhat.com/openshift/install/pull-secret

1
cat /root/pull-secret.txt | jq . | tee /root/remote.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
"auths": {
"cloud.openshift.com": {
"auth": "bSkhBOEVCUOOUdVVg==",
"email": "xiaohui_li@foxmail.com"
},
"quay.io": {
"auth": "b3BlOTFOOUdVVg==",
"email": "xiaohui_li@foxmail.com"
},
"registry.connect.redhat.com": {
"auth": "fHZ1dm10eZjRQ==",
"email": "xiaohui_li@foxmail.com"
},
"registry.redhat.io": {
"auth": "fHVOTFOOUdVjRQ==",
"email": "xiaohui_li@foxmail.com"
}
}
}

把本地的local-secret.txt也按照格式加进来,具体加完如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[root@content ~]# cat remote.txt
{
"auths": {
"cloud.openshift.com": {
"auth": "bSkhBOEVCUOOUdVVg==",
"email": "xiaohui_li@foxmail.com"
},
"quay.io": {
"auth": "b3BlOTFOOUdVVg==",
"email": "xiaohui_li@foxmail.com"
},
"registry.connect.redhat.com": {
"auth": "b3BlOTFOOUdVVg==",
"email": "xiaohui_li@foxmail.com"
},
"registry.redhat.io": {
"auth": "b3BlOTFOOUdVVg==",
"email": "xiaohui_li@foxmail.com"
},
"content.cluster1.xiaohui.cn:8443": {
"auth": "YWRtaW46bGl4aWFvaHVp",
"email": "lixiaohui@xiaohui.cn"
}
}
}

关于openshift版本,请参考OpenShift

1
2
3
4
5
6
7
export OCP_RELEASE='4.18.15'
export LOCAL_REGISTRY='content.cluster1.xiaohui.cn:8443'
export LOCAL_REPOSITORY='openshift'
export PRODUCT_REPO='openshift-release-dev'
export LOCAL_SECRET_JSON='/root/remote.txt'
export RELEASE_NAME='ocp-release'
export ARCHITECTURE='x86_64'

将镜像上传到私有仓库,这一步需要较久的时间,当然也取决于你的网络情况,在下载好之后,会上传到你的quay私有仓库中

1
2
3
4
oc adm -a ${LOCAL_SECRET_JSON} release mirror \
--from=quay.io/${PRODUCT_REPO}/${RELEASE_NAME}:${OCP_RELEASE}-${ARCHITECTURE} \
--to=${LOCAL_REGISTRY}/${LOCAL_REPOSITORY} \
--to-release-image=${LOCAL_REGISTRY}/${LOCAL_REPOSITORY}:${OCP_RELEASE}-${ARCHITECTURE}

注意结束之后的输出,我们把imageContentSources的内容放到稍后的install-config.yaml文件中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Update image:  content.cluster1.xiaohui.cn:8443/openshift:4.18.15-x86_64
Mirror prefix: content.cluster1.xiaohui.cn:8443/openshift
Mirror prefix: content.cluster1.xiaohui.cn:8443/openshift:4.18.15-x86_64

To use the new mirrored repository to install, add the following section to the install-config.yaml:

imageContentSources:
- mirrors:
- content.cluster1.xiaohui.cn:8443/openshift
source: quay.io/openshift-release-dev/ocp-release
- mirrors:
- content.cluster1.xiaohui.cn:8443/openshift
source: quay.io/openshift-release-dev/ocp-v4.0-art-dev


To use the new mirrored repository for upgrades, use the following to create an ImageContentSourcePolicy:

apiVersion: operator.openshift.io/v1alpha1
kind: ImageContentSourcePolicy
metadata:
name: example
spec:
repositoryDigestMirrors:
- mirrors:
- content.cluster1.xiaohui.cn:8443/openshift
source: quay.io/openshift-release-dev/ocp-release
- mirrors:
- content.cluster1.xiaohui.cn:8443/openshift
source: quay.io/openshift-release-dev/ocp-v4.0-art-dev

生成匹配版本的openshift-install文件,如果不做这个步骤,而用官方的openshift-install生成配置文件,将有可能导致无法从私有仓库拉取镜像数据

1
2
3
oc adm -a ${LOCAL_SECRET_JSON} release extract \
--command=openshift-install "${LOCAL_REGISTRY}/${LOCAL_REPOSITORY}:${OCP_RELEASE}-${ARCHITECTURE}" \
--skip-verification=true --insecure=true

用我们生成的openshift-install替换掉原有的

1
cp openshift-install /usr/local/bin

拉取密钥

在openshift安装过程中,需要从官方拉取镜像,请打开下面的链接,保存好账号的拉取密钥

1
2
打开网址,登录账号,下载文件到合适的位置,例如/root
https://console.redhat.com/openshift/install/pull-secret

准备安装配置文件

参数意义
baseDomainxiaohui.cn域名后缀
metadata.namecluster1集群名称
pullSecretXXX填写真实pullSecret
sshKeyXXX填写真实ssh公钥
1
mkdir /openshift

要格外注意,这个配置文件名称必须是install-config.yaml

pullSecret 请使用自己从官方下载的,如果有私有仓库,可以加上进行加速,注意要加上仓库使用的CA证书,如果没有私有仓库,直接从官方拉取,配置文件就到sshkey结束

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
cat > /openshift/install-config.yaml <<'EOF'
apiVersion: v1
baseDomain: xiaohui.cn
compute:
- hyperthreading: Enabled
name: worker
replicas: 0
controlPlane:
hyperthreading: Enabled
name: master
replicas: 3
metadata:
name: cluster1
networking:
clusterNetwork:
- cidr: 10.128.0.0/14
hostPrefix: 23
networkType: OVNKubernetes
serviceNetwork:
- 172.16.0.0/16
machineNetwork:
- cidr: 192.168.8.0/24
platform:
none: {}
fips: false
pullSecret: '{"auths":{"content.cluster1.xiaohui.cn:8443":{"auth":"YWRtaW46bGl4aWFvaHVp","email":"lixiaohui@xiaohui.cn"}}}'
sshKey: 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGxL3I2R2omOzpdXslWUogEkG9jik0OGHR234SwUzyVl root@content.cluster1.xiaohui.cn'
# 请注意,如果是直接从互联网拉取镜像,就不要写入包括本行在内的下面所有内容,把本行以及下面的内容写成EOF,即可完成文件的创建
imageContentSources:
- mirrors:
- content.cluster1.xiaohui.cn:8443/openshift
source: quay.io/openshift-release-dev/ocp-release
- mirrors:
- content.cluster1.xiaohui.cn:8443/openshift
source: quay.io/openshift-release-dev/ocp-v4.0-art-dev
additionalTrustBundle: |
-----BEGIN CERTIFICATE-----
MIIFrzCCA5egAwIBAgIUZBSHC378o/0vC2gYDHojyr2tpJ4wDQYJKoZIhvcNAQEN
BQAwZzELMAkGA1UEBhMCQ04xETAPBgNVBAgMCFNoYW5naGFpMREwDwYDVQQHDAhT
aGFuZ2hhaTEQMA4GA1UECgwHQ29tcGFueTELMAkGA1UECwwCU0gxEzARBgNVBAMM
CnhpYW9odWkuY24wHhcNMjIwOTI0MDYzMTE1WhcNMzIwOTIxMDYzMTE1WjBnMQsw
CQYDVQQGEwJDTjERMA8GA1UECAwIU2hhbmdoYWkxETAPBgNVBAcMCFNoYW5naGFp
MRAwDgYDVQQKDAdDb21wYW55MQswCQYDVQQLDAJTSDETMBEGA1UEAwwKeGlhb2h1
aS5jbjCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAL1pjGe237Axfcqz
4XoKsec2gceCP155SboFdA2fl5I2NBBnGCqMivxn2k5qMpVT5t7CLcgMVtfg1XRj
zGQ4Pg/2/vVlHUHibMKPDBnPYm+xIoLg9/qE231/eWEjKfLRkJ6CCDCSLYQXhqcB
tWdwML46mtq0krtyPEHeJlbil4U2cMJeRhdk6xRV4omY54vuBlg+rMiXdOZqCP1G
2NL2lv7C1VH0mgCGLBr03CgsazWD8E3quPortTD5H+znf4vb7YKSfsdMbTDfBO3/
EXHzwQJiupl9M9g3p/bjTrchs5ONZ6b0tH8Z5YR+UpMxe4ltGxOYo8I6TJ4w6Q7k
Wk4VHK1wlxKw6KJ1Qfed3DqTvdNMGp7whxghFfI0IrJG/TjAjMEHLLS/G3VET/dP
+LT/KchBiBgKNEIEpCB52LKz4owAdfQaao3/l0rVxr2x0hQiZuf1QpqrTaRdXURP
AaOX540mQbNvnfyCxEDgXS9WicjQmEHNOi8486fLACOEhZgj4SK1pz4W4N8yKoOp
1obkJgIJZ3DsQ4bKvbvgQNmjQMZFwpD4l2FKi/fEKRKZuzvEEo413gUFdDpQtfvk
znlJ0llEtzievz3QciorGEdynJJM0AuJbf1D0G/LCpEWUtwmn0SykrZe403e2V0u
RlTjo29Hwb+6PRGvUC0g6JOIWWe5AgMBAAGjUzBRMB0GA1UdDgQWBBQZj5fnxo5L
36wiyR+wuvCqPd1XjjAfBgNVHSMEGDAWgBQZj5fnxo5L36wiyR+wuvCqPd1XjjAP
BgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBDQUAA4ICAQCRhXXwzSTQZIm9aJZ2
d1fWTMWpkNOL/nc2oPq3y+i45rWnAkM/b8ZsW1csuFM3cvny0I9Jge8B3OHzc4Of
cHvSBbftRV0F8R3fd9wtcS913ZPBSsbD7nan1txV7qBnN/RMVkhoWZ927aSUacTT
Ee9jANWafIaU4VUBGV7IW53/j8xi6hnrf2prSjKcHE5pahh5rRvtABf0srI2sVec
A104jX6jwracFExaNfnA2sS9mpXp2G/xDUgDvJSen+M1mSgsXSURTIuLG9Gor+Vv
9aHuDCIvAvXPKsPlvsDuEoa+xaNCxU2kbMZOdPi988KWMAszZKZhTuM5NfNWdbjM
OZjdmpCrDyQbj61GnN/baWCSr8aeosVJHGoXTfZ5wm/+n783jmmX92aDz4Qq96Jh
VIdAZl+CTyZnaN7mkF0Es+QUOr429F8wnFp8uASu3hBUNIs/cMo4XX7yPdxIiKXf
EPvlWPKEw10phTHrOqo0I9AYklxsogpinMG38rJJALZXg4mysEhZaYbezIIzbMIy
E5ZNmj/C8EyCDFcHW4jr/2nTTAuas7VXq7J6nf4BhN83U2WwBwjIUdN/xcHyZoU3
PYteQypw/qXDwbIW8uuI14S4ee08qjLa75oKbgBidKAVG15/tq/HKc7UlPp4XRPS
y9SPl5QdyAqw3gzs7Jbc+1Z+Gw==
-----END CERTIFICATE-----
EOF

准备kubernetes清单和bootstrap配置文件

在这一关键步骤中,我们使用匹配版本的 openshift-install 工具来 生成集群的配置文件,包括 bootstrapmasterworkerauth 相关文件。如果你是从 官网直接下载openshift-install,需要特别注意它的来源;如果打算使用 私有仓库 拉取 OpenShift 镜像,请务必确保 openshift-install 是通过 oc 工具解压的版本,而不是官网的默认下载版本。

重要提示

🚨 执行 openshift-install 生成配置文件后,install-config.yaml 将被删除,如果有修改需求,请 提前备份
🚨 必须在 24 小时内完成安装,否则 证书自动续订 可能导致安装失败。
🚨 PXE 需要正确指向 HTTP 服务器,所以我们拷贝所有配置文件到 2000 端口提供服务的 Web 目录

1
2
3
4
5
6
7
8
9
10
eval "$(ssh-agent -s)"
ssh-add /root/.ssh/id_ed25519
# 执行了下面的install命令,install-config.yaml这个文件会消失,可以考虑是否备份
openshift-install create manifests --dir /openshift
openshift-install create ignition-configs --dir /openshift
cp -a /openshift/* /content
chmod a+rx /content -R
semanage fcontext -a -t httpd_sys_content_t "/content(/.*)?"
restorecon -RvF /content
systemctl restart httpd

部署bootstrap节点

集群安装的顺序至关重要,确保各个节点能正确启动并完成初始化。以下是详细的 安装流程,确保 OpenShift UPI 部署的稳定性:

PXE 启动流程

  1. 安装 Bootstrap 节点

    • 开机 bootstrap 节点 并从 网卡 PXE 启动,在 PXE 界面选择 bootstrap 选项。

    • 等待 bootstrap 节点安装完成,直到出现 login

  2. 检查 Bootstrap 进度

    • content.cluster1.xiaohui.cn 服务器上,使用 SSH 连接 bootstrap:
1
ssh core@bootstrap

观察 bootstrap 节点的安装进度:

1
journalctl -b -f -u release-image.service -u bootkube.service

等待日志滚动停止,并出现如下信息:

1
Created "99_openshift-cluster-api_worker-user-data-secret.yaml"

此时 bootstrap 节点已就绪,但它的主要作用是 引导 Master 节点安装,最终会从集群中移除。

部署master节点

  • 启动 Master 节点

    • 开机 master 节点 并从 PXE 启动,选择 master(如 master0)。

    • 等待 Master 安装完成,出现 login 提示符。

  • 确认 Bootstrap 完成

    • 安装 Master 并不意味着集群已准备好,此时需要进一步检查 集群状态
1
openshift-install wait-for bootstrap-complete --log-level=info

这里要注意,可能会卡住,很正常的,它需要较久的时间才能完成

等待期间可以用以下命令来看看进度

1
oc get co --kubeconfig /openshift/auth/kubeconfig

你会看到各种operator都在努力工作中,你可能会临时看到一些报错,那都不要紧,继续等待,直到全部正常

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
[root@content ~]# oc get co --kubeconfig /openshift/auth/kubeconfig
NAME VERSION AVAILABLE PROGRESSING DEGRADED SINCE MESSAGE
authentication 4.18.15 False True True 2m25s APIServerDeploymentAvailable: no apiserver.openshift-oauth-apiserver pods available on any node....
baremetal 4.18.15 True False False 78s
cloud-controller-manager 4.18.15 True False False 3m54s
cloud-credential True False False 33m
cluster-autoscaler 4.18.15 True False False 87s
config-operator 4.18.15 True False False 2m13s
console
control-plane-machine-set 4.18.15 True False False 78s
csi-snapshot-controller 4.18.15 True False False 2m8s
dns 4.18.15 True False False 80s
etcd 4.18.15 True True False 6s NodeInstallerProgressing: 1 node is at revision 2; 0 nodes have achieved new revision 3
image-registry
ingress False True True 114s The "default" ingress controller reports Available=False: IngressControllerUnavailable: One or more status conditions indicate unavailable: DeploymentAvailable=False (DeploymentUnavailable: The deployment has Available status condition set to False (reason: MinimumReplicasUnavailable) with message: Deployment does not have minimum availability.)
insights 4.18.15 True False False 93s
kube-apiserver False False True 2m11s StaticPodsAvailable: 0 nodes are active; 1 node is at revision 0
kube-controller-manager False True True 2m12s StaticPodsAvailable: 0 nodes are active; 1 node is at revision 0; 0 nodes have achieved new revision 3
kube-scheduler 4.18.15 False True False 2m12s StaticPodsAvailable: 0 nodes are active; 1 node is at revision 0; 0 nodes have achieved new revision 4
kube-storage-version-migrator 4.18.15 True False False 2m8s
machine-api 4.18.15 True False False 63s
machine-approver 4.18.15 True False False 114s
machine-config 4.18.15 True False False 69s
marketplace 4.18.15 True False False 82s
monitoring Unknown True Unknown 78s Rolling out the stack.
network False True False 3m38s The network is starting up
node-tuning 4.18.15 True False False 102s
olm 4.18.15 False True False 118s CatalogdDeploymentCatalogdControllerManagerAvailable: Waiting for Deployment...
openshift-apiserver 4.18.15 False False False 2m13s APIServicesAvailable: PreconditionNotReady
openshift-controller-manager False True False 2m6s Available: no pods available on any node.
openshift-samples
operator-lifecycle-manager 4.18.15 True False False 71s
operator-lifecycle-manager-catalog 4.18.15 True False False 63s
operator-lifecycle-manager-packageserver False True False 71s
service-ca 4.18.15 True False False 2m11s
storage 4.18.15 True False False 2m13s

看到都正常之后,运行下面命令来确认一下

如果你没在/openshift下执行此命令就会提示:

FATAL loading kubeconfig: stat auth/kubeconfig: no such file or directory

1
2
3
4
5
6
[root@content ~]# openshift-install --dir /openshift wait-for bootstrap-complete --log-level=info
INFO Waiting up to 20m0s (until 9:32PM) for the Kubernetes API at https://api.cluster1.xiaohui.cn:6443...
INFO API v1.30.0-2368+b62823b40c2cb1-dirty up
INFO Waiting up to 30m0s (until 9:42PM) for bootstrapping to complete...
INFO It is now safe to remove the bootstrap resources
INFO Time elapsed: 15m50s

看到上方的It is now safe to remove the bootstrap resources之后,请从haproxy文件中去掉bootstrap的条目,具体来说,就是在content上,修改haproxy配置文件,在所有的监听中,去掉bootstrap的条目,因为此时,我们的master0、master1、master2等等这些机器已经可以独当一面了

确认master就绪后,以此类推尽快安装其他master

添加管理凭据

如果想在content机器上管理openshift,把config文件创建好就可以了

1
2
mkdir /root/.kube
cp /openshift/auth/kubeconfig /root/.kube/config

添加命令自动补齐功能

1
2
3
4
oc completion bash > /etc/bash_completion.d/oc
kubectl completion bash > /etc/bash_completion.d/kubectl
source /etc/bash_completion.d/oc
source /etc/bash_completion.d/kubectl

确认Master节点就绪

在没有worker的情况下,可能authentication、console、ingress等几个的available状态一直不对,但其他都是正常,这个命令可能要很久才会全部就绪,请耐心等,而且过程中,会各种报错,是正常的,那是正在工作的表现,以下我的状态正常是因为我这是加好worker之后的内容

如果只看到master节点是ready是不够的,一定要等到下面的available更新状态为true

1
2
3
4
5
[root@content ~]# oc get nodes
NAME STATUS ROLES AGE VERSION
master0.cluster1.xiaohui.cn Ready master,worker 63m v1.30.0+4f0dd4d
master1.cluster1.xiaohui.cn Ready master,worker 63m v1.30.0+4f0dd4d
master2.cluster1.xiaohui.cn Ready master,worker 63m v1.30.0+4f0dd4d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
[root@content ~]# oc get co
NAME VERSION AVAILABLE PROGRESSING DEGRADED SINCE MESSAGE
authentication 4.18.15 True False False 3m31s
baremetal 4.18.15 True False False 52m
cloud-controller-manager 4.18.15 True False False 58m
cloud-credential 4.18.15 True False False 68m
cluster-autoscaler 4.18.15 True False False 52m
config-operator 4.18.15 True False False 54m
console 4.18.15 True False False 108s
csi-snapshot-controller 4.18.15 True False False 52m
dns 4.18.15 True False False 52m
etcd 4.18.15 True False False 50m
image-registry 4.18.15 True False False 41m
ingress 4.18.15 True False False 44m
insights 4.18.15 True False False 47m
kube-apiserver 4.18.15 True False False 38m
kube-controller-manager 4.18.15 True False False 49m
kube-scheduler 4.18.15 True False False 48m
kube-storage-version-migrator 4.18.15 True False False 53m
machine-api 4.18.15 True False False 52m
machine-approver 4.18.15 True False False 52m
machine-config 4.18.15 True False False 11m
marketplace 4.18.15 True False False 52m
monitoring 4.18.15 True False False 40m
network 4.18.15 True False False 54m
node-tuning 4.18.15 True False False 48m
openshift-apiserver 4.18.15 True False False 38m
openshift-controller-manager 4.18.15 True False False 48m
openshift-samples 4.18.15 True False False 44m
operator-lifecycle-manager 4.18.15 True False False 52m
operator-lifecycle-manager-catalog 4.18.15 True False False 52m
operator-lifecycle-manager-packageserver 4.18.15 True False False 45m
service-ca 4.18.15 True False False 54m
storage 4.18.15 True False False 54m

添加Worker节点

除刚才提到的几个available状态不对,其他的基本更新结束之后就正常了,此时我们可以通过pxe安装更多的worker节点,安装步骤和其他的一样,开机从网卡启动,选择对应的PXE条目即可

对于worker节点,需要集群审批证书才可以在oc get nodes中出现,请多次通过以下方式去批准证书申请请求,审批好的标准是执行oc get nodes能看到worker节点,看不到可以多次审批

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@content ~]# oc get csr -o name | xargs oc adm certificate approve
certificatesigningrequest.certificates.k8s.io/csr-4d24n approved
certificatesigningrequest.certificates.k8s.io/csr-8dlnx approved
certificatesigningrequest.certificates.k8s.io/csr-bk98l approved
certificatesigningrequest.certificates.k8s.io/csr-dc7p8 approved
certificatesigningrequest.certificates.k8s.io/csr-dwmnx approved
certificatesigningrequest.certificates.k8s.io/csr-g9m6x approved
certificatesigningrequest.certificates.k8s.io/csr-hbfvr approved
certificatesigningrequest.certificates.k8s.io/csr-hccdb approved
certificatesigningrequest.certificates.k8s.io/csr-hcqcc approved
certificatesigningrequest.certificates.k8s.io/csr-kglq7 approved
certificatesigningrequest.certificates.k8s.io/csr-kzc8c approved
certificatesigningrequest.certificates.k8s.io/csr-rjr8h approved
certificatesigningrequest.certificates.k8s.io/csr-sklnx approved
certificatesigningrequest.certificates.k8s.io/csr-zkvxp approved
certificatesigningrequest.certificates.k8s.io/csr-zxggg approved
certificatesigningrequest.certificates.k8s.io/system:openshift:openshift-authenticator-znwx7 approved
certificatesigningrequest.certificates.k8s.io/system:openshift:openshift-monitoring-4vw5b approved

确认Worker状态就绪

在worker添加并多次审批证书之后,所有的available状态都会是正常的,用一下命令来确认一下集群安装进度,而且这个命令还可以给我们看到用于登录的网址和账号密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[root@content ~]# openshift-install wait-for install-complete --dir=/openshift --log-level=debug
DEBUG OpenShift Installer 4.11.0-0.okd-2022-08-20-022919
DEBUG Built from commit 7493bb2821ccd348c11aa36f05aa060b3ab6beda
DEBUG Loading Install Config...
DEBUG Loading SSH Key...
DEBUG Loading Base Domain...
DEBUG Loading Platform...
DEBUG Loading Cluster Name...
DEBUG Loading Base Domain...
DEBUG Loading Platform...
DEBUG Loading Networking...
DEBUG Loading Platform...
DEBUG Loading Pull Secret...
DEBUG Loading Platform...
DEBUG Using Install Config loaded from state file
INFO Waiting up to 40m0s (until 2:46AM) for the cluster at https://api.cluster1.xiaohui.cn:6443 to initialize...
DEBUG Cluster is initialized
INFO Waiting up to 10m0s (until 2:16AM) for the openshift-console route to be created...
DEBUG Route found in openshift-console namespace: console
DEBUG OpenShift console route is admitted
INFO Install complete!
INFO To access the cluster as the system:admin user when using 'oc', run
INFO export KUBECONFIG=/openshift/auth/kubeconfig
INFO Access the OpenShift web-console here: https://console-openshift-console.apps.cluster1.xiaohui.cn
INFO Login to the console with user: "kubeadmin", and password: "B2JR4-yVzPQ-N3V8r-Jz48V"
INFO Time elapsed: 0s

添加了worker节点之后持续获取oc get co状态,如果发现上面提到的authentication、console、ingress等几个的available状态一直不对,可以通过以下方式解决

当然,这种方法是删除pod,并等他重建,它重建也需要一段时间,不要着急

1
2
3
oc get pod -o name -n openshift-ingress | xargs oc delete -n openshift-ingress
oc get pod -o name -n openshift-authentication | xargs oc delete -n openshift-authentication
oc get pod -o name -n openshift-console | xargs oc delete -n openshift-console

确认所有节点状态

如果没有worker节点,就再去审批一下证书

1
2
3
4
5
6
7
[root@content ~]# oc get nodes
NAME STATUS ROLES AGE VERSION
compute0.cluster1.xiaohui.cn Ready worker 22m v1.30.0+4f0dd4d
compute1.cluster1.xiaohui.cn Ready worker 23m v1.30.0+4f0dd4d
master0.cluster1.xiaohui.cn Ready master,worker 68m v1.30.0+4f0dd4d
master1.cluster1.xiaohui.cn Ready master,worker 68m v1.30.0+4f0dd4d
master2.cluster1.xiaohui.cn Ready master,worker 68m v1.30.0+4f0dd4d

界面展示

Redhat OpenShift 版本: