Skip to content確認兩個檔案的 checksum
解壓縮檔案,並將 oc、openshift-install 和 kubectl 加至 PATH 環境變數
確認 oc Command 版本
螢幕輸出 :
Client Version: 4.12.24
Kustomize Version: v4.5.7
確認 openshift-install Command 版本
螢幕輸出 :
openshift-install 4.12.24
built from commit 194f806390b2b20668f5ac32d7918f9773b29a5e
release image quay.io/openshift-release-dev/ocp-release@sha256:b0b11eedf91175459b5d7aefcf3936d0cabf00f01ced756677483f5f26227328
release architecture amd64
確認 kubectl Command 版本
螢幕輸出 :
clientVersion:
buildDate: "2023-06-26T20:27:30Z"
compiler: gc
gitCommit: ea7c11aac7fa39d9eb733b62251ee1bc4a242c99
gitTreeState: clean
gitVersion: v1.25.2
goVersion: go1.19.10 X:strictfipsruntime
major: "1"
minor: "25"
platform: linux/amd64
kustomizeVersion: v4.5.7
Step 2: 安裝 DNS Server
編輯 DNS Server 設定檔 named.conf
要改的地方有兩個部分
- 將
listen-on port 53 和 allow-query 的值, 改成 any
檔案內容 :
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
secroots-file "/var/named/data/named.secroots";
recursing-file "/var/named/data/named.recursing";
allow-query { any; };
- 假設我 bastion 這台機器的 Hostname 是
bastion.ocp4.example.com
IP 是 192.168.11.80,在 /etc/named.conf 新增以下內容至檔案的最後面 :
:::info
在本次範例中
- Cluster name 是
ocp4 - Base Domain Name 是
example.com
:::
設定 DNS Server 名稱解析
檔案內容如下 :
$TTL 1W
@ IN SOA bastion.ocp4.example.com. root (
2019070700 ; serial
3H ; refresh (3 hours)
30M ; retry (30 minutes)
2W ; expiry (2 weeks)
1W ) ; minimum (1 week)
IN NS bastion.ocp4.example.com.
IN MX 10 smtp.example.com.
;
;
bastion.ocp4.example.com. IN A 192.168.11.80
smtp.example.com. IN A 192.168.11.80
;
api.ocp4.example.com. IN A 192.168.11.80
api-int.ocp4.example.com. IN A 192.168.11.80
;
*.apps.ocp4.example.com. IN A 192.168.11.80
;
bootstrap.ocp4.example.com. IN A 192.168.11.81
;
master.ocp4.example.com. IN A 192.168.11.82
;
worker1.ocp4.example.com. IN A 192.168.11.83
worker2.ocp4.example.com. IN A 192.168.11.84
;
;EOF
:::danger
Note: 紅字部分為須依照環境的規劃來設定
:::
設定 DNS Server 反解析
檔案內容如下 :
$TTL 1W
@ IN SOA bastion.ocp4.example.com. root (
2019070700 ; serial
3H ; refresh (3 hours)
30M ; retry (30 minutes)
2W ; expiry (2 weeks)
1W ) ; minimum (1 week)
IN NS bastion.ocp4.example.com.
;
80.11.168.192.in-addr.arpa. IN PTR api.ocp4.example.com.
80.11.168.192.in-addr.arpa. IN PTR api-int.ocp4.example.com.
;
81.11.168.192.in-addr.arpa. IN PTR bootstrap.ocp4.example.com.
;
82.11.168.192.in-addr.arpa. IN PTR master.ocp4.example.com.
;
83.11.168.192.in-addr.arpa. IN PTR worker1.ocp4.example.com.
84.11.168.192.in-addr.arpa. IN PTR worker2.ocp4.example.com.
;
;EOF
:::danger
Note: 紅字部分為須依照環境的規劃來設定
:::
啟動 DNS Server
螢幕輸出 :
檢查
螢幕輸出 :
● named.service - Berkeley Internet Name Domain (DNS)
Loaded: loaded (/usr/lib/systemd/system/named.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2023-07-17 16:50:31 CST; 1s ago
...以下省略
將 bastion 機器的 IP 新增為 DNS Server
關閉防火牆
驗證 DNS Server 正解
驗證 DNS Server 反解
Step 3: 安裝 HAProxy 服務
設定 HAProxy
直接清掉預設的設定檔
再編輯設定檔
將以下內容複製到檔案中 :
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
listen api-server-6443
bind *:6443
mode tcp
server bootstrap bootstrap.ocp4.example.com:6443 check inter 1s backup
server master master.ocp4.example.com:6443 check inter 1s
listen machine-config-server-22623
bind *:22623
mode tcp
server bootstrap bootstrap.ocp4.example.com:22623 check inter 1s backup
server master master.ocp4.example.com:22623 check inter 1s
listen ingress-router-443
bind *:443
mode tcp
balance source
server worker1 worker1.ocp4.example.com:443 check inter 1s
server worker2 worker2.ocp4.example.com:443 check inter 1s
listen ingress-router-80
bind *:80
mode tcp
balance source
server worker1 worker1.ocp4.example.com:80 check inter 1s
server worker2 worker2.ocp4.example.com:80 check inter 1s
:::danger
Note: 紅字部分為須依照環境的規劃來設定
:::
設定允許 HAProxy 可以使用 TCP Port
If you are using HAProxy as a load balancer and SELinux is set to enforcing, you must ensure that the HAProxy service can bind to the configured TCP port by running setsebool -P haproxy_connect_any=1.
啟動 HAProxy 服務,並設為開機自動啟動
螢幕輸出 :
檢查
螢幕輸出 :
● haproxy.service - HAProxy Load Balancer
Loaded: loaded (/usr/lib/systemd/system/haproxy.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2023-07-17 17:26:21 CST; 11min ago
...以下省略
Step 4: 安裝 Web Server
將網站的 TCP Port 改成 8080
修改以下檔案內容,將 80 Port 改為 8080 Port
Listen 8080
或是用 sed 直接修改 :
sudo sed -i 's|Listen 80|Listen 8080|g' /etc/httpd/conf/httpd.conf
修改 ssl.conf 檔名
啟動 httpd 服務,並設為開機自動啟動
螢幕輸出 :
檢查
螢幕輸出 :
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2023-07-17 20:34:55 CST; 6s ago
...以下省略
Step 5: 產生 SSH Key
啟動 SSH 代理
將 SSH private key 加入 ssh-agent
Step 6: 下載 pull-secret
至以下連結下載,注意 : 需先登入帳號

可點選 “Download pull secret",或是點 “Copy pull secret” 直接將 pull-secret 複製到剪貼簿
Step 7: 撰寫 install-config.yaml
:::info
Note: install-config.yaml 這個檔案名稱不可亂改,只能取這個名稱
:::
將以下檔案內容,修改符合當前環境之設定值
apiVersion: v1
baseDomain: example.com
compute:
- hyperthreading: Enabled
name: worker
replicas: 0
controlPlane:
hyperthreading: Enabled
name: master
replicas: 1
metadata:
name: ocp4
networking:
clusterNetwork:
- cidr: 10.128.0.0/14
hostPrefix: 23
networkType: OVNKubernetes
serviceNetwork:
- 172.30.0.0/16
platform:
none: {}
fips: false
pullSecret: '{"auths": ...}'
sshKey: 'ssh-ed25519 AAAA...'
:::danger
Note: 紅字部分為須依照環境的規劃來設定
:::
- baseDomain ,The base domain of the cluster.
- 使用 user-provisioned 的方式建立 OCP 時,不要改
compute.replicas = 0 這個數字
:::info
- In installer-provisioned installations, the parameter controls the number of compute machines that the cluster creates and manages for you.
- In user-provisioned installations, you must manually deploy the compute machines before you finish installing the cluster.
:::
controlPlane.replicas = 1 ,設定 ControlPlane Node 的數量為 1 台metadata.name,設定 OCP 的 Cluster NamepullSecret ,將上一個步驟複製的 pullSecret 複製到這sshKey,bastion 主機的 SSH 公鑰,The SSH public key for the core user in Red Hat Enterprise Linux CoreOS (RHCOS).(可在 bastion 主機,透過 SSH 免密碼的方式登入 RHCOS 的機器)
:::info
- 檢視 SSH 公鑰命令 :
cat ~/.ssh/id_ed25519.pub
:::
備份 install-config.yaml
install-config.yaml 之後會不見, 會透過 openshift-install 指令變成 XXX.ign 檔案, 以防萬一有地方寫錯之後要修改, 這邊先備份
Step 8: Creating the Kubernetes manifest and Ignition config files
--dir,specify the installation directory that contains the install-config.yaml file you created.
螢幕輸出 :
Because you must modify some cluster definition files and manually start the cluster machines, you must generate the Kubernetes manifest and Ignition config files that the cluster needs to configure the machines.
The installation configuration file transforms into the Kubernetes manifests. The manifests wrap into the Ignition configuration files, which are later used to configure the cluster machines.
設定 master Node 不要 Run Pod
Create the Ignition configuration files
將 Ignition configuration files 放至網站
檢查
打開瀏覽器,連線至
http://192.168.11.80:8080/ocp4/

Setup bootstrap machine
Installing RHCOS by using an ISO image
1. 取得 bootstrap.ign 啟動設定檔案的 SHA512 雜湊值
在 bastion 主機執行以下命令
螢幕輸出 :
在稍後的步驟中,這個 SHA512 雜湊值會被提供給「coreos-installer」,以驗證叢集節點上 Ignition 設定檔的真實性。
2. 透過 openshift-install 命令獲取正確版本的 RHCOS ISO 檔
在 bastion 機器執行以下命令
螢幕輸出 :
下載 x86_64 版本的 RHCOS ISO 檔,並透過這個 ISO 檔,將 RHCOS 裝起來
下載命令 :
3. 使用上個步驟下載好的 ISO 檔安裝 RHCOS
開始安裝後,不用指定任何選項或中斷實時啟動順序。等待安裝程式進入 RHCOS 實機環境的命令提示字元。
4. 允許 SSH 使用密碼登入 和 設定網路、主機名稱
將第 68 行的 PasswordAuthentication no 改成 PasswordAuthentication yes
- 設定固定 IP:
192.168.11.81/24 - Gateway:
192.168.11.254 - DNS:
192.168.11.80, 8.8.8.8 - 關閉 Ipv6
- 設定 hostname:
boostrap.ocp4.example.com
Setup master machine
Installing RHCOS by using an ISO image
1. 取得 master.ign 啟動設定檔案的 SHA512 雜湊值
在 bastion 主機執行以下命令
螢幕輸出 :
在稍後的步驟中,這個 SHA512 雜湊值會被提供給「coreos-installer」,以驗證叢集節點上 Ignition 設定檔的真實性。
2. 使用與 bootstrap 機器相同的 ISO 檔安裝 RHCOS
3. 允許 SSH 使用密碼登入 和 設定網路、主機名稱
將第 68 行的 PasswordAuthentication no 改成 PasswordAuthentication yes
- 設定固定 IP:
192.168.11.82/24 - Gateway:
192.168.11.254 - DNS:
192.168.11.80, 8.8.8.8 - 關閉 Ipv6
- 設定 hostname:
master.ocp4.example.com
Setup worker1 machine
Installing RHCOS by using an ISO image
1. 取得 worker.ign 啟動設定檔案的 SHA512 雜湊值
在 bastion 主機執行以下命令
螢幕輸出 :
在稍後的步驟中,這個 SHA512 雜湊值會被提供給「coreos-installer」,以驗證叢集節點上 Ignition 設定檔的真實性。
2. 使用與 bootstrap 機器相同的 ISO 檔安裝 RHCOS
3. 允許 SSH 使用密碼登入 和 設定網路、主機名稱
將第 68 行的 PasswordAuthentication no 改成 PasswordAuthentication yes
- 設定固定 IP:
192.168.11.83/24 - Gateway:
192.168.11.254 - DNS:
192.168.11.80, 8.8.8.8 - 關閉 Ipv6
- 設定 hostname:
worker1.ocp4.example.com
Setup worker2 machine
Installing RHCOS by using an ISO image
1. 使用與 bootstrap 機器相同的 ISO 檔安裝 RHCOS
2. 允許 SSH 使用密碼登入 和 設定網路、主機名稱
將第 68 行的 PasswordAuthentication no 改成 PasswordAuthentication yes
- 設定固定 IP:
192.168.11.84/24 - Gateway:
192.168.11.254 - DNS:
192.168.11.80, 8.8.8.8 - 關閉 Ipv6
- 設定 hostname:
worker2.ocp4.example.com
Starting the OpenShift Container Platform bootstrap process
1. 在 bootstrap 機器執行以下安裝命令
$ sudo coreos-installer install \
--firstboot-args 'rd.neednet=1' \
--copy-network \
--ignition-url=http://192.168.11.80:8080/ocp4/bootstrap.ign \
/dev/sda \
--ignition-hash=sha512-e11591138d028175664c5779ca696c568aaf6dc3849a0facb7e76f160184284e451131968786d2c81648d0425668a922e159541c98287be07438a596d6d84d2b
螢幕輸出 :
重新開機
2. 在 master 機器執行以下安裝命令
$ sudo coreos-installer install \
--firstboot-args 'rd.neednet=1' \
--copy-network \
--ignition-url=http://192.168.11.80:8080/ocp4/master.ign \
/dev/sda \
--ignition-hash=sha512-46be965b1657dc170203ce83b9ff2ffddf34004da83cecf2440e0c50dec06ea32296c0b2c21a8324fb321ba6592ee5d12108c362d5b98ac3e5a0edf3d8fce7a8
螢幕輸出 :
重新開機
3. Monitor the bootstrap process
回到 bastion 主機,透過 ssh 連線至 bootstrap 主機
先刪除舊的公鑰紀錄
ssh 連線至 bootstrap 主機
檢視 bootstrap 主機安裝到哪個步驟
約等 20 分鐘後的正確螢幕輸出 :
4. 等待 bootstrap process 安裝完成
螢幕輸出 :
...以上省略
INFO Waiting up to 30m0s (until 10:40AM) for bootstrapping to complete...
DEBUG Bootstrap status: complete
INFO It is now safe to remove the bootstrap resources
DEBUG Time elapsed per stage:
DEBUG Bootstrap Complete: 25m47s
INFO Time elapsed: 25m47s
看到 INFO It is now safe to remove the bootstrap resources 代表安裝完成
5. 加入 worker Node
在 worker1 和 worker2 主機執行以下命令
$ sudo coreos-installer install \
--firstboot-args 'rd.neednet=1' \
--copy-network \
--ignition-url=http://192.168.11.80:8080/ocp4/worker.ign \
/dev/sda \
--ignition-hash=sha512-c61b89807d86ef9974aaa0451015205bf9e7534b9506b52fb8883c3411c1ba1c5ec0e3080c7d35bb782cd847aa64533552b3f2132ce9b0c8fc6cf4e62933f8c6
螢幕輸出 :
分別重啟 Node
6. 使用 CLI 登錄 OCP Cluster
檢視 OCP Cluster Node 的狀態
螢幕輸出 :
在某些 CSR 獲得批准之前,工作節點還無法被加入 OCP 叢集。
7. 核准 Worker Node 的 CSRs (憑證請求)
檢視 CSRs 的狀態
csr is short for “certificate signing request”
螢幕輸出 :
核准 CSRs
或者也可以執行以下命令,一次核准所有的 CSRs
:::danger
超級注意 !
由於 CSRs 會自動輪換,請在將機器新增到集群後的一小時內核准 CSRs。
:::
8. 檢視 Worker Node 是否成功加入 OCP 叢集
螢幕輸出 :
It can take a few minutes after approval of the server CSRs for the machines to transition to the Ready status.
9. 檢視整個叢集是否健康
10. 登入 Web Console
- 帳號是 :
kubeadmin - 密碼會放在 Bastion 主機的
~/ocpinstall/auth/ 目錄下的 kubeadmin-password 檔案中 - 網址可以透過以下命令獲得
螢幕輸出 :
成功登入後的畫面

TroubleShooting
Issue: Canary route checks for the default ingress controller are failing
完整錯誤訊息如下 :
開始找真正的原因
- 執行以下命令,測試 pod 是否可以透過
curl 命令使用 port 8080 連線到自己。所有的 curl 請求都應該傳回 200 狀態碼,如果狀態碼不等於 200,表示 pod 尚未運作。
- 如果問題是最近才發生的,請等個幾分鐘(1或2分鐘),然後再檢查一次。
- 如果問題一直存在,請重新啟動 pod。
- 如果都沒問題,就繼續往下一個步驟繼續找問題的真正原因
- 執行以下命令,檢查 pod 是否可以使用 service 端點進行 curl。所有的 curl 請求都應該傳回 200 狀態碼,如果狀態碼不等於 200,表示 service IP 無法路由傳入的流量。
service-cluster-IP,要記得換
- 此服務由名為「
openshift-ingress-canary」Namespace 中的 daemonset 「ingress-canary」管理。如果狀態碼不等於 200,請重啟「cluster-version-operator」Pod,然後重新啟動 daemonset。
- 執行以下命令,檢查對路由的連線,Curl 請求應該會得到 302 的回應碼。
cluster-name 和 domain-name 要記得換
- 檢查 load-balancer 是否將流量導向 router pod。
- 如果路由不存在或狀態碼不等於 302,請重新啟動 openshift-ingress Namespace 中的 cluster-version operator 和 router pods。
參考文章
Issue: Router-Default 的 pod 無法被指派到叢集中的任何一台 Node 上
- Ingress operator 報告了有關污點不容忍和節點放置的錯誤
執行以下命令看 ingress 的 message 訊息
看看是不是跟以下錯誤訊息類似
真正發生問題的原因
- Ingresscontroller/default 有透過 node Selector 指定要到 mater node 上,但是 master node 上又有 Taints,所以 Pod 沒有任何一台主機可以用
解決辦法
- 必需將 router-default pod 放置在 Worker 節點上。
- 在 openshift-ingress-operator namespace 中對
ingresscontroller/default 資源進行 oc patch 推送失敗,或者在 oc edit 編輯後也無法更改。
執行以下命令產生一個新的 default IngressController 的 Yaml 檔
覆蓋現有的 ingresscontroller/default
稍微等幾分鐘後,檢視問題是否被修復
螢幕輸出 :
參考文章