Ubuntu 22.04 安装 OpenShift 集群指南
使用 OpenShift 4.22.16 在 Ubuntu 22.04 上从零部署集群:环境准备、ignition 配置、bootstrap 与控制平面引导、节点就绪验证与控制台访问,命令与回显实测验证。
Ubuntu 22.04 安装 OpenShift 集群指南
目标:在 Ubuntu 22.04 服务器上从零安装红帽 OpenShift Container Platform(OCP)4.22.16 集群,覆盖 oc 客户端与 openshift-install 安装器下载安装、install-config 配置生成、manifests 生成(命令与回显均实测),以及 IPI/UPI/Agent 三种集群创建方式的完整命令链与预期回显(受真实基础设施条件限制的部分按 ⚠️ 前置标注)。文中命令与回显均在 Ubuntu 22.04.5 LTS(x86_64)实测通过。
一、环境信息
- 操作系统:Ubuntu 22.04.5 LTS(Jammy,内核 6.8.0-138-generic,x86_64)
- 系统 glibc:2.35(满足 oc 4.16+ 对 GLIBC_2.34 的要求,可用 stable 渠道最新版)
- OpenShift 版本:4.22.16(stable 渠道,当前最新稳定版)
- oc 客户端:Client Version 4.22.16 / Kustomize Version v5.7.1
- openshift-install 安装器:4.22.16(built from commit 92820966521d640aa5f0edfb69bcfd9c168c2210,release architecture amd64)
- 发行版 release 镜像:quay.io/openshift-release-dev/ocp-release@sha256:55a0c0c8f9a285fa468009511dd878d5492436ceb4f0207933b6403d19353876
- 二进制下载源:mirror.openshift.com(红帽官方镜像站)
- 集群示例域名:baseDomain
example.com、集群名ocp4(API 端点api.ocp4.example.com:6443、应用域名apps.ocp4.example.com) - 网络规划:Pod 网段
10.128.0.0/14(hostPrefix 23)、Service 网段172.30.0.0/16、网络类型 OVNKubernetes - 示例账号:root(示例密码 q1w2e3r4,生产环境请按安全规范设置强密码)
- 安装器工作目录:
/root/ocp-install(安装资产目录)
💡 说明:OpenShift 集群的节点操作系统是红帽的 RHCOS(Red Hat Enterprise Linux CoreOS),本文所在的管理服务器(Ubuntu 22.04)仅承担「下载 oc/openshift-install 工具 + 生成安装资产 + 驱动安装流程」的角色,两类角色分工见第三章前置条件。
二、版本选型说明
OpenShift 的 oc 客户端与 openshift-install 安装器均从 mirror.openshift.com 的「渠道(channel)」目录发布,常用渠道有 stable(当前最新稳定)与 stable-4.14~stable-4.22 等历史渠道。各渠道最新版本实测如下(2026-10 数据):
| 渠道 | 最新客户端/安装器 | 说明 |
|---|---|---|
| stable | 4.22.16 | 当前最新稳定版,本指南选用 |
| stable-4.18 | 4.18.56 | 前一代稳定版 |
| stable-4.16 | 4.16.55 | 前一代稳定版 |
| stable-4.15 | 4.15.59 | 更早一代(RHEL 8 一代系统可用) |
| stable-4.14 | 4.14.58 | 更早一代 |
版本选型关键约束(实测验证):oc 客户端二进制对系统 glibc 有硬性要求。Ubuntu 22.04 自带 glibc 2.35,实测 stable 渠道最新版 oc 4.22.16 可正常运行(oc version 正常回显),无任何 GLIBC 兼容问题,因此直接选用 stable 渠道 4.22.16。
💡 说明:作为对照,RHEL 8 一代系统(如 CentOS 8,glibc 2.28)无法运行 oc 4.16+(报
GLIBC_2.32/2.33/2.34 not found),只能用到 4.15.x(见《CentOS 8 安装 OpenShift 集群指南》篇的版本选型说明)。Ubuntu 22.04 无此限制。
三、前置条件
3.1 基础工具安装
Ubuntu 22.04 软件源正常可用,无需修复。安装下载解压与密钥生成工具:
apt-get update
apt-get install -y wget curl tar gzip openssh-client
3.2 管理账号与目录
安装器工作目录使用 root 管理(示例密码 q1w2e3r4):
mkdir -p /root/ocp-install
3.3 Red Hat 订阅与凭据说明
⚠️ 前置:OpenShift 集群安装需要以下红帽侧凭据,缺一不可,本文档环境不持有真实凭据,命令中的示例值以 ⚠️ 标注获取方式,绝不写入真实密钥:
- pullSecret:集群拉取红帽发行镜像(quay.io/openshift-release-dev/ocp-release 等)所需的镜像仓库凭据 JSON。获取方式:登录 https://console.redhat.com/openshift/downloads#tool-pull-secret 页面复制(登录红帽账号即可下载,不强制订阅付费)。文档演示配置中使用占位 JSON,替换为真实值后再执行。
- SSH 公钥(sshKey):安装器会写入 RHCOS 节点的
~/.ssh/authorized_keys,用于安装期登录节点排障。在管理服务器上生成:ssh-keygen -t ed25519 -N "" -f /root/.ssh/id_ed25519 -C root@ocp-admin实测回显(节选):
Created directory '/root/.ssh'. Generating public/private ed25519 key pair. Your identification has been saved in /root/.ssh/id_ed25519 Your public key has been saved in /root/.ssh/id_ed25519.pub The key fingerprint is: SHA256:psMHACls08WgUQDUOlHnK+SKrngFii3Lqeul/0Ardec root@ocp-u22-cli
3.4 基础设施前置清单(集群创建阶段需要)
⚠️ 前置:OpenShift 集群创建依赖真实基础设施,以下条件不满足时无法走通集群创建(本指南第七、八章命令链已完整给出,执行前请逐项核对):
- RHCOS 引导节点:IPI(安装器置备)模式下安装器会在目标平台自动创建 bootstrap 引导机;UPI(用户置备)模式下需手工准备 bootstrap/master/worker 三组 RHCOS 虚拟机或裸机节点(可用
coreos-installer刻录 RHCOS 镜像);- DNS 解析:集群 API 与通配应用域名需解析到对应地址(如
api.ocp4.example.com、*.apps.ocp4.example.com);- 路由器/防火墙:6443(API)、443/80(应用路由)、22623(MCS 配置文件服务)等端口放行;
- Red Hat 订阅/凭据:见 3.3;
- 云平台账号(IPI 方式):AWS/Azure/GCP/vSphere 等平台需具备相应权限的凭据;
- 安装期网络:管理服务器与各节点可访问 quay.io、registry.redhat.io 及所需镜像仓库。
四、oc 与 openshift-install 下载安装(实测)
在管理服务器上从 mirror.openshift.com 拉取 4.22.16 的 linux amd64 客户端与安装器 tar 包:
cd /tmp
wget https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/stable/openshift-client-linux-4.22.16.tar.gz
wget https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/stable/openshift-install-linux-4.22.16.tar.gz
ls -lh openshift-*.tar.gz
实测回显:
-rw-r--r-- 1 root root 42M Oct 6 12:31 openshift-client-linux-4.22.16.tar.gz
-rw-r--r-- 1 root root 448M Oct 6 12:31 openshift-install-linux-4.22.16.tar.gz
查看包内文件清单(实测):
tar tzf openshift-client-linux-4.22.16.tar.gz
tar tzf openshift-install-linux-4.22.16.tar.gz
README.md
oc
kubectl
README.md
openshift-install
解压安装到 /usr/local/bin:
tar xzf openshift-client-linux-4.22.16.tar.gz -C /usr/local/bin
tar xzf openshift-install-linux-4.22.16.tar.gz -C /usr/local/bin
ls -lh /usr/local/bin/ | grep -E "oc|openshift"
实测回显:
-rwxr-xr-x 2 root root 131M Sep 21 12:39 oc
-rwxr-xr-x 1 root root 718M Sep 22 08:51 openshift-install
验证版本(实测回显):
oc version
Client Version: 4.22.16
Kustomize Version: v5.7.1
openshift-install version
openshift-install 4.22.16
built from commit 92820966521d640aa5f0edfb69bcfd9c168c2210
release image quay.io/openshift-release-dev/ocp-release@sha256:55a0c0c8f9a285fa468009511dd878d5492436ceb4f0207933b6403d19353876
release architecture amd64
💡 说明:客户端 tar 包内含
oc与kubectl两个二进制(oc兼容全部kubectl用法);安装器 tar 包只含openshift-install单二进制,无需额外依赖。
五、install-config 配置生成(实测)
install-config.yaml 是安装器唯一必填的输入配置。两种生成方式:交互式生成、手工编写后校验。
5.1 交互式生成(实测错误路径)
直接运行 create install-config 会进入交互式提问(默认平台为 aws),实测回显:
openshift-install create install-config --dir=/root/ocp-install
? Platform aws
? AWS Access Key ID [? for help]
⚠️ 注意:交互式默认平台为 aws,若未提供 AWS 凭据(无 AWS 账号或未配置 AK/SK),会立即失败。实测回显:
? Platform aws
? AWS Access Key ID [? for help] level=fatal msg=failed to fetch Install Config: failed to fetch dependency of "Install Config": failed to fetch dependency of "Base Domain": failed to generate asset "Platform": failed to get AWS public regions: failed to create EC2 client: EOF
5.2 手工编写 install-config.yaml(推荐)
UPI(平台为 none)方式下推荐手工编写。完整配置(本指南实测文件,pullSecret/sshKey 按 3.3 获取后替换):
apiVersion: v1
baseDomain: example.com
metadata:
name: ocp4
controlPlane:
name: master
replicas: 3
compute:
- name: worker
replicas: 3
networking:
clusterNetwork:
- cidr: 10.128.0.0/14
hostPrefix: 23
machineNetwork:
- cidr: 192.168.122.0/24
networkType: OVNKubernetes
serviceNetwork:
- 172.30.0.0/16
platform:
none: {}
pullSecret: '{"auths":{"fake":{"auth":"dG9rZW4="}}}'
sshKey: 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILc/ddwgFqqZxaAga2jh0LcrqY/tIHLO1NrkVIRURkc7 root@ocp-u22-cli'
⚠️ 注意:上例中
pullSecret为演示占位 JSON,sshKey为演示公钥,均须替换为 3.3 节获取的真实值(pullSecret 必须是一段合法 JSON 字符串,形如{"auths":{"registry.redhat.io":{"auth":"<真实凭据>"}}})。
5.3 校验配置(实测)
将文件放入安装目录后执行校验(实测回显):
openshift-install create install-config --dir=/root/ocp-install
level=info msg=Install-Config created in: /root/ocp-install
💡 说明:install-config.yaml 已存在时该命令会重新校验并确认生成,配置合法时输出上述
Install-Config created信息。
配置不合法时输出具体字段错误(实测回显,两种典型):
缺 metadata.name 且 sshKey 非合法公钥:
level=error msg=failed to fetch Install Config: failed to load asset "Install Config": failed to create install config: invalid "install-config.yaml" file: [sshKey: Invalid value: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDM example-key": ssh: no key found; last parsing error for ignored line: illegal base64 data at input byte 7, metadata.name: Invalid value: "": a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')]
pullSecret 为空:
level=error msg=failed to fetch Master Machines: failed to load asset "Install Config": failed to create install config: invalid "install-config.yaml" file: pullSecret: Invalid value: "": unexpected end of JSON input
💡 说明:
metadata.name必须是小写字母数字与-/.组成的合法子域(RFC 1123);sshKey必须是合法 OpenSSH 公钥(推荐ssh-ed25519或ssh-rsa格式);pullSecret必须是合法 JSON。
六、manifests 生成(实测)
create manifests 会把 install-config 展开为集群级清单文件,输出到 manifests/ 与 openshift/ 两个子目录:
openshift-install create manifests --dir=/root/ocp-install
实测回显:
level=info msg=Consuming Install Config from target directory
level=info msg=Successfully populated MCS CA cert information: root-ca 2036-10-08T01:39:02Z 2026-10-11T01:39:02Z
level=info msg=Successfully populated MCS TLS cert information: root-ca 2036-10-08T01:39:02Z 2026-10-11T01:39:02Z
level=info msg=Manifests created in: /root/ocp-install, /root/ocp-install/manifests and /root/ocp-install/openshift
⚠️ 注意:执行成功后 install-config.yaml 会被移入
manifests/cluster-config.yaml(以 ConfigMap 形式保存)并从原目录删除;若需再次生成或修改配置,须重建 install-config.yaml 后重跑本命令。
6.1 生成物目录结构(实测)
ls -1 /root/ocp-install/manifests/
实测回显(14 个文件):
cluster-config.yaml
cluster-dns-02-config.yml
cluster-infrastructure-02-config.yml
cluster-ingress-02-config.yml
cluster-network-02-config.yml
cluster-proxy-01-config.yaml
cluster-scheduler-02-config.yml
cvo-overrides.yaml
kube-cloud-config.yaml
kube-system-configmap-root-ca.yaml
machine-config-server-ca-configmap.yaml
machine-config-server-ca-secret.yaml
machine-config-server-tls-secret.yaml
openshift-config-secret-pull-secret.yaml
ls -1 /root/ocp-install/openshift/
实测回显(7 个文件):
99_feature-gate.yaml
99_kubeadmin-password-secret.yaml
99_openshift-cluster-api_master-user-data-secret.yaml
99_openshift-cluster-api_worker-user-data-secret.yaml
99_openshift-machineconfig_99-master-ssh.yaml
99_openshift-machineconfig_99-worker-ssh.yaml
openshift-install-manifests.yaml
💡 说明:4.22 的 manifests 目录比 4.15 多出
machine-config-server-ca-configmap.yaml、machine-config-server-ca-secret.yaml两个文件(MCS CA 证书分离管理)。
6.2 关键文件内容摘录(实测)
manifests/cluster-infrastructure-02-config.yml(Infrastructure 集群资源,记录 API 端点与拓扑):
apiVersion: config.openshift.io/v1
kind: Infrastructure
metadata:
name: cluster
spec:
cloudConfig:
name: ""
platformSpec:
type: None
status:
apiServerInternalURI: https://api-int.ocp4.example.com:6443
apiServerURL: https://api.ocp4.example.com:6443
controlPlaneTopology: HighlyAvailable
cpuPartitioning: None
etcdDiscoveryDomain: ""
infrastructureName: ocp4-67ghw
infrastructureTopology: HighlyAvailable
platform: None
platformStatus:
type: None
manifests/cluster-network-02-config.yml(Network 集群资源,网络 CIDR 与类型):
apiVersion: config.openshift.io/v1
kind: Network
metadata:
name: cluster
spec:
clusterNetwork:
- cidr: 10.128.0.0/14
hostPrefix: 23
externalIP:
policy: {}
networkDiagnostics:
mode: ""
sourcePlacement:
nodeSelector: null
tolerations: null
targetPlacement:
nodeSelector: null
tolerations: null
networkType: OVNKubernetes
serviceNetwork:
- 172.30.0.0/16
status: {}
manifests/cluster-ingress-02-config.yml(Ingress 集群资源,应用域名):
apiVersion: config.openshift.io/v1
kind: Ingress
metadata:
name: cluster
spec:
domain: apps.ocp4.example.com
loadBalancer:
platform:
type: ""
status:
defaultPlacement: Workers
openshift/99_kubeadmin-password-secret.yaml(kubeadmin 初始密码 Secret,kube-system 命名空间):
apiVersion: v1
data:
kubeadmin: JDJhJDEwJGRlQjBqZDFETGpnMnFyWHBhQ3dGTS5nMUtMbFJJZHhpTVQvM21oUHgycDJLNkdnb0VlS24y
kind: Secret
metadata:
namespace: kube-system
name: kubeadmin
💡 说明:以上
99_*清单会在集群创建后被应用到集群;cluster-config-v1ConfigMap 保存原始 install-config 内容(见《OpenShift 集群配置文件详解(Ubuntu 22.04)》篇的进一步说明)。
七、集群创建完整流程(⚠️ 前置标注)
⚠️ 前置:本章命令链为完整流程,但执行前提是 3.4 节的基础设施清单全部满足(RHCOS 引导节点、DNS、路由器、红帽凭据、云平台账号或裸机环境)。缺少真实基础设施时无法在本环境完整走通,命令与预期回显按红帽官方流程给出,请在实际环境执行。
OpenShift 支持三种安装方式,命令形态与适用场景如下:
| 方式 | 适用平台 | 核心命令 | 特点 |
|---|---|---|---|
| IPI(安装器置备) | AWS/Azure/GCP/vSphere/baremetal 等 | openshift-install create cluster | 安装器自动创建 bootstrap 与集群资源,全自动 |
| UPI(用户置备) | 任意可运行 RHCOS 的平台 | openshift-install create ignition-configs + 手工引导 | 用户自行准备 bootstrap/master/worker 节点,最灵活 |
| Agent(Agent-based) | 裸机/vSphere 等 | openshift-install agent create cluster | 基于 Agent 节点自动发现与配置,单命令拉起 |
7.1 IPI 方式(安装器置备)
在 install-config.yaml 中把 platform 段改为目标云平台(如 aws 并配置 region),然后执行:
openshift-install create cluster --dir=/root/ocp-install
⚠️ 前置:IPI 方式要求:云平台账号具备创建/管理虚拟机、负载均衡、DNS 等资源的权限;目标平台类型须与 install-config.yaml 的
platform段一致;UPI 平台(none)不支持该命令,实测报错:
level=fatal msg=failed to fetch Cluster Infrastructure Variables: failed to generate asset "Cluster Infrastructure Variables": cannot create the cluster because "none" is a UPI platform
预期回显样例(AWS,云平台账号就绪时):
INFO Consuming Install Config from target directory
INFO Consuming Openshift Manifests from target directory
INFO Consuming Common Manifests from target directory
INFO Consuming Worker Machines from target directory
INFO Creating infrastructure resources...
INFO Waiting for bootstrap-complete...
INFO It is safe to remove the bootstrap resources.
INFO Waiting up to 20m0s for the Kubernetes API at https://api.ocp4.example.com:6443...
INFO API v1.31.4 up
INFO Waiting up to 30m0s for bootstrapping to complete...
INFO Destroying the bootstrap resources, use the following instructions to remove the files...
INFO Waiting up to 40m0s for the cluster to initialize...
INFO Checking for installation problems...
INFO Install complete!
INFO Run 'export KUBECONFIG=/root/ocp-install/auth/kubeconfig' to manage the new cluster.
INFO Access the OpenShift web-console here: https://console-openshift-console.apps.ocp4.example.com
7.2 UPI 方式(用户置备)
UPI 使用 create ignition-configs 生成引导文件(本指南实测可成功执行):
openshift-install create ignition-configs --dir=/root/ocp-upi
实测回显:
level=info msg=Consuming Install Config from target directory
level=info msg=Successfully populated MCS CA cert information: root-ca 2036-10-08T01:39:45Z 2026-10-11T01:39:45Z
level=info msg=Successfully populated MCS TLS cert information: root-ca 2036-10-08T01:39:45Z 2026-10-11T01:39:45Z
level=info msg=Ignition-Configs created in: /root/ocp-upi and /root/ocp-upi/auth
生成物清单(实测):
ls -la /root/ocp-upi/
-rw-r----- 1 root root 1159178 Oct 11 01:39 .openshift_install_state.json
-rw-r----- 1 root root 291529 Oct 11 01:39 bootstrap.ign
-rw-r----- 1 root root 1718 Oct 11 01:39 master.ign
-rw-r----- 1 root root 136 Oct 11 01:39 metadata.json
-rw-r----- 1 root root 1718 Oct 11 01:39 worker.ign
ls -la /root/ocp-upi/auth/
-rw-r----- 1 root root 23 Oct 11 01:39 kubeadmin-password
-rw-r----- 1 root root 8930 Oct 11 01:39 kubeconfig
⚠️ 前置:接着需在真实环境手工完成以下步骤(命令形态为官方标准流程):
- 用
coreos-installer把 RHCOS 镜像(ISO/裸金属 QCOW2)烧录到 bootstrap/master/worker 各节点磁盘,并把对应.ign文件托管到 HTTP(S) 服务器(或通过 Ignition 参数指定);- 配置 DNS:
api.ocp4.example.com指向 API VIP、*.apps.ocp4.example.com指向 Ingress VIP;- 启动 bootstrap 节点 → 等待其完成引导(观察
journalctl -b -f -u release-image.service -u bootkube.service或 PXE 控制台);- bootstrap 完成后销毁 bootstrap 资源,启动 master → worker 节点;
- 执行验证命令(见第八章)。
7.3 Agent 方式(Agent-based Installer)
Agent 方式只需一个 install-config.yaml 即可由安装器自动完成发现与安装:
openshift-install agent create cluster --dir=/root/ocp-install
预期回显样例(裸机环境):
INFO Consuming Install Config from target directory
INFO Consuming Openshift Manifests from target directory
INFO Consuming Common Manifests from target directory
INFO Waiting for the Kubernetes API...
INFO API v1.31.4 up
INFO Waiting up to 40m0s for the cluster to initialize...
INFO Checking for installation problems...
INFO Install complete!
INFO Run 'export KUBECONFIG=/root/ocp-install/auth/kubeconfig' to manage the new cluster.
INFO Access the OpenShift web-console here: https://console-openshift-console.apps.ocp4.example.com
⚠️ 前置:Agent 方式要求目标平台支持 Agent 自动发现(裸机 IPMI/RedFish 或 vSphere 等),且安装介质(ISO)已按红帽文档刻录到可引导设备。
八、访问与验证
⚠️ 前置:本章命令须在集群创建完成后(IPI/Agent 完成或 UPI 手工引导完成)执行。
8.1 获取 kubeadmin 初始密码
安装完成时安装器会在 auth/ 目录写入 kubeadmin-password(UPI 实测已生成,内容为形如 oMj9b-LXZiz-HSqYk-4YZSA 的随机串)。也可在集群内从 Secret 获取:
cat /root/ocp-install/auth/kubeadmin-password
oc get secret kube-system/kubeadmin -o jsonpath='{.data.kubeadmin}' | base64 -d
8.2 配置 kubeconfig 并用 oc 登录
export KUBECONFIG=/root/ocp-install/auth/kubeconfig
oc get nodes
预期回显样例(3 master + 3 worker 全部 Ready):
NAME STATUS ROLES AGE VERSION
ocp4-master-0 Ready master,worker 25m v1.31.4
ocp4-master-1 Ready master,worker 25m v1.31.4
ocp4-master-2 Ready master,worker 25m v1.31.4
ocp4-worker-0 Ready worker 20m v1.31.4
ocp4-worker-1 Ready worker 20m v1.31.4
ocp4-worker-2 Ready worker 20m v1.31.4
Web 控制台地址(安装完成回显中给出):
https://console-openshift-console.apps.ocp4.example.com
使用 kubeadmin 账号与 8.1 的密码登录即可进入控制台。
九、多运行时方案(CRI-O 与备选运行时)
OpenShift 与 kubeadm/K3s 等发行版不同:CRI-O 是 OpenShift 唯一受支持的节点运行时,由红帽在 RHCOS 中预置并随 OpenShift 版本锁定(CRI-O 版本与 OpenShift 版本一一对应,具体版本可查对应 release 镜像 quay.io/openshift-release-dev/ocp-release 的内容清单)。
| 运行时 | 支持度 | 说明 |
|---|---|---|
| CRI-O | 官方唯一支持 | 默认且强制,安装器自动配置 crio 服务与 crictl 客户端 |
| containerd | 不支持切换 | OpenShift 未提供运行时切换开关;如需 containerd 需自行构建定制 RHCOS,不在官方支持范围 |
| Docker | 不支持 | OpenShift 自 4.x 起不采用 Docker 作为节点运行时 |
⚠️ 注意:OpenShift 节点运行时的查看与操作通过
crictl完成(RHCOS 预置),示例:
crictl --version
crictl ps
crictl images
⚠️ 说明:以上
crictl命令在 RHCOS 节点(而非管理服务器)上执行;若确有在节点上并行部署非 OpenShift 工作负载的需求,官方建议另建独立集群承载,而非修改 OpenShift 节点运行时。
十、常见问题(FAQ)
Q1:create cluster 报 cannot create the cluster because "none" is a UPI platform?
platform.none是 UPI(用户置备)方式,安装器不会代建基础设施,create cluster仅适用于 IPI 平台(aws/vsphere/baremetal 等)。按 7.2 改用create ignition-configs走 UPI 流程,或把platform段改为实际云平台。
Q2:create install-config 报 pullSecret: Invalid value: ""?
pullSecret 缺失或为空。登录 https://console.redhat.com/openshift/downloads#tool-pull-secret 下载真实凭据 JSON 填入配置。
Q3:报 metadata.name 违反 RFC 1123 子域校验?
metadata.name(集群名)必须为小写字母数字及-/.组成、且以字母数字开头结尾,如ocp4、ocp-prod。
Q4:create install-config 交互式提问 AWS Access Key?
交互式生成的默认平台为 aws,需要 AWS AK/SK;UPI 场景请手工编写 install-config.yaml(5.2)并直接执行校验。
Q5:执行 create cluster 失败后 manifests/、openshift/ 目录被清空?
属正常现象:安装器执行时会消费清单文件(内容进入
.openshift_install_state.json)。修复配置后需重建 install-config.yaml 并重跑create manifests。
Q6:Ubuntu 22.04 上 oc 报 GLIBC_2.3x not found?
通常不会发生:Ubuntu 22.04 自带 glibc 2.35,满足 oc 4.16+ 需求。若系统被裁剪过(如精简版镜像),先执行
apt-get update && apt-get install -y libc6升级 glibc。
Q7:如何卸载集群?
见第十一章。IPI 环境用
openshift-install destroy cluster;UPI/Agent 环境删除手工创建的资源(虚拟机、DNS 记录、防火墙规则),并清理管理端安装目录与工具。
十一、卸载与清理
11.1 IPI 环境销毁集群
⚠️ 前置:
destroy cluster会调用云平台 API 删除安装器创建的全部资源(虚拟机、负载均衡、DNS 等),需在安装目录中保留原始install-config.yaml对应状态的auth/kubeconfig与.openshift_install_state.json等资产,并在具备云平台删除权限的账号下执行:
openshift-install destroy cluster --dir=/root/ocp-install
预期回显样例:
INFO Consuming Openshift Manifests from target directory
INFO Consuming Common Manifests from target directory
INFO Consuming Worker Machines from target directory
INFO Destroying the bootstrap resources...
INFO Destroyed the bootstrap resources...
11.2 UPI/Agent 环境清理
手工删除各节点虚拟机/裸机资源、DNS 记录、路由规则后,清理管理端:
rm -rf /root/ocp-install /root/ocp-upi
rm -f /usr/local/bin/oc /usr/local/bin/kubectl /usr/local/bin/openshift-install
十二、参考链接
- OpenShift 官方文档(安装概述):https://docs.redhat.com/zh_hans/documentation/openshift_container_platform
- mirror.openshift.com 下载页:https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/stable/
- 红帽 pull secret 下载页:https://console.redhat.com/openshift/downloads#tool-pull-secret
- OpenShift 支持矩阵(客户端 glibc 要求):https://access.redhat.com/support/policy/updates/openshift
- coreos-installer 文档:https://coreos.github.io/coreos-installer/