MatchBox設定
1. 概要
OpenShiftのMaster/Workerノードを構築するとき、RedHatの提供するRHCOSをOSとしてインストール必要があります。 RHCOSをISOイメージを使って、手作業でインストールすることも可能ですが、Master/Workerの台数が4台5台と増えていくと大変な作業になります。 RHCOSをネットワークインストールできるようにすると、OpenShiftのMaster/Workerノード構築が非常に楽になります。 本稿ではその手順を解説します。
2. 解決したい課題
OpenShiftのMaster/Workerノード構築をネットワークインストールで自動化したい。
3. 解決方法
MatchBoxを使って、ネットワークインストールを自動化する「PXEサーバ」を構築します。 通常PXEサーバはBastion環境に設定しますが、ほかのサーバに構築することもできます。 また、PXEサーバは、Master/Workerノードと同じセグメントにいないと、DHCP/TFTPが届かなかったりして面倒です。できない訳ではありません。 センター+エッジ構成など、広域なOpenShift環境を作る場合は、注意する必要があります。「5.今後の追記予定」参照。
以下の段取りで構築を進めます。
- MatchBoxをインストール
- RHCOSイメージを配置
- MatchBoxのコンフィグファイルの設定
- TFTPの設定
- dnsmasqにPXEを設定
- OpenShiftのMaster/Workerのイグニッションファイルを設定
- VMをネットワークインストールで構築(説明は省略)
次章から説明する手順は、RHEL8.6へのインストールを前提にしています。CentOS7等でも大して変わらないと思います。
# cat /etc/redhat-release
Red Hat Enterprise Linux release 8.6 (Ootpa)
3.1 MatchBoxをインストール
MatchBoxはv0.9.0等にアップデートされているようですが、 無難なv0.8.0を使います。
# cd /tmp
# wget https://github.com/poseidon/matchbox/releases/download/v0.8.0/matchbox-v0.8.0-linux-amd64.tar.gz
# tar xzvf matchbox-v0.8.0-linux-amd64.tar.gz
# cd matchbox-v0.8.0-linux-amd64/
# cp matchbox /usr/local/bin
# cp contrib/systemd/matchbox-local.service /etc/systemd/system/matchbox.service
# useradd -U matchbox
# mkdir -p /var/lib/matchbox/assets
# chown -R matchbox:matchbox /var/lib/matchbox
# systemctl enable matchbox
Created symlink /etc/systemd/system/multi-user.target.wants/matchbox.service → /etc/systemd/system/matchbox.service.
# systemctl start matchbox
# systemctl status matchbox
● matchbox.service - CoreOS matchbox Server
Loaded: loaded (/etc/systemd/system/matchbox.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2022-12-30 15:43:24 JST; 8s ago
Docs: https://github.com/coreos/matchbox
Main PID: 3459 (matchbox)
Tasks: 6 (limit: 98034)
Memory: 2.5M
CGroup: /system.slice/matchbox.service
└─3459 /usr/local/bin/matchbox
(中略)
#
3.2 RHCOSイメージを配置
RHCOSのイメージは、https://mirror.openshift.com/からダウンロードします。 以下の手順は、RHCOS4.8.14を前提としてますが、バージョンは適宜読み替えてください。
# cd /var/lib/matchbox/assets/
# wget https://mirror.openshift.com/pub/openshift-v4/dependencies/rhcos/4.8/4.8.14/rhcos-4.8.14-x86_64-live-initramfs.x86_64.img
# wget https://mirror.openshift.com/pub/openshift-v4/dependencies/rhcos/4.8/4.8.14/rhcos-4.8.14-x86_64-live-kernel-x86_64
# wget https://mirror.openshift.com/pub/openshift-v4/dependencies/rhcos/4.8/4.8.14/rhcos-4.8.14-x86_64-live-rootfs.x86_64.img
# ll
合計 1000816
-rw-r--r-- 1 root root 89362572 12月 16 2021 rhcos-4.8.14-x86_64-live-initramfs.x86_64.img
-rw-r--r-- 1 root root 10030448 12月 16 2021 rhcos-4.8.14-x86_64-live-kernel-x86_64
-rw-r--r-- 1 root root 925434368 12月 16 2021 rhcos-4.8.14-x86_64-live-rootfs.x86_64.img
#
3.3 MatchBoxのコンフィグファイルの設定
MatchBoxのコンフィグファイルとイメージファイルは以下のような構成となっています。
# tree /var/lib/matchbox/
/var/lib/matchbox/
├── assets
│ ├── rhcos-4.8.14-x86_64-live-initramfs.x86_64.img
│ ├── rhcos-4.8.14-x86_64-live-kernel-x86_64
│ └── rhcos-4.8.14-x86_64-live-rootfs.x86_64.img
├── groups
│ ├── bootstrap.json
│ ├── master-0.json
│ ├── master-1.json
│ ├── master-2.json
│ ├── worker-0.json
(中略)
├── ignition
└── profiles
├── bootstrap.json
├── master.json
└── worker.json
まず、MatchBoxプロファイル。Bootstrap用、Master用、Worker用の3つを用意します。 以下の例では、PXEサーバのFQDNはbastion.ocp48.morifuku.comとなっています。適宜読み替えてください。 ポート8080は、RHCOSイメージを取得するためのポート番号で、MatchBoxが待ち構えています。 ポート8008は、OpenShiftインストーラのイグニッションファイルを取得するためのポート番号で、このポートで待ち構えているNGINX等がOCPインストーラへ処理を渡します。
# pwd
/var/lib/matchbox/profiles
# cat bootstrap.json
{
"id": "bootstrap",
"name": "OCP4 Bootstrap",
"ignition_id": "bootstrap.ign",
"boot": {
"kernel": "/assets/rhcos-4.8.14-x86_64-live-kernel-x86_64",
"initrd": [
"/assets/rhcos-4.8.14-x86_64-live-initramfs.x86_64.img"
],
"args": [
"ip=dhcp",
"rd.neednet=1",
"coreos.inst=yes",
"coreos.inst.install_dev=/dev/sda",
"coreos.live.rootfs_url=http://bastion.ocp48.morifuku.com:8080/assets/rhcos-4.8.14-x86_64-live-rootfs.x86_64.img",
"coreos.inst.ignition_url=http://bastion.ocp48.morifuku.com:8008/ocp/rhcos/ignitions/bootstrap.ign"
]
}
}
# cat master.json
{
"id": "master",
"name": "OCP4 Master",
"ignition_id": "master.ign",
"boot": {
"kernel": "/assets/rhcos-4.8.14-x86_64-live-kernel-x86_64",
"initrd": [
"/assets/rhcos-4.8.14-x86_64-live-initramfs.x86_64.img"
],
"args": [
"ip=dhcp",
"rd.neednet=1",
"coreos.inst=yes",
"coreos.inst.install_dev=sda",
"coreos.live.rootfs_url=http://bastion.ocp48.morifuku.com:8080/assets/rhcos-4.8.14-x86_64-live-rootfs.x86_64.img",
"coreos.inst.ignition_url=http://bastion.ocp48.morifuku.com:8008/ocp/rhcos/ignitions/master.ign"
]
}
}
# cat worker.json
{
"id": "worker",
"name": "OCP4 Worker",
"ignition_id": "worker.ign",
"boot": {
"kernel": "/assets/rhcos-4.8.14-x86_64-live-kernel-x86_64",
"initrd": [
"/assets/rhcos-4.8.14-x86_64-live-initramfs.x86_64.img"
],
"args": [
"ip=dhcp",
"rd.neednet=1",
"coreos.inst=yes",
"coreos.inst.install_dev=sda",
"coreos.live.rootfs_url=http://bastion.ocp48.morifuku.com:8080/assets/rhcos-4.8.14-x86_64-live-rootfs.x86_64.img",
"coreos.inst.ignition_url=http://bastion.ocp48.morifuku.com:8008/ocp/rhcos/ignitions/worker.ign"
]
}
}
# chown matchbox:matchbox *
# ll
合計 12
-rwxr-xr-x 1 matchbox matchbox 609 12月 30 16:22 bootstrap.json
-rwxr-xr-x 1 matchbox matchbox 592 12月 30 16:22 master.json
-rwxr-xr-x 1 matchbox matchbox 588 12月 30 16:23 worker.json
#
PXEサーバにアクセスしてきたPXEクライアントのMACアドレスから、どのMatchBoxプロファイルを適用するかを指定するファイルです。 Bootstrap用の他に、全Master/Worker用のものを用意する必要があります。
# pwd
/var/lib/matchbox/groups
# cat bootstrap.json
{
"id": "bootstrap",
"name": "OCP4 Bootstrap",
"profile": "bootstrap",
"selector": {
"mac": "00:01:e6:00:00:22"
}
}
# cat master-0.json
{
"id": "master-0",
"name": "OCP4 Master 0",
"profile": "master",
"selector": {
"mac": "00:01:e6:00:00:23"
}
}
# cat worker-0.json
{
"id": "worker-0",
"name": "OCP4 Worker 0",
"profile": "worker",
"selector": {
"mac": "00:01:e6:00:00:26"
}
}
# ll bootstrap.json master-0.json worker-0.json
-rwxr-xr-x 1 matchbox matchbox 140 12月 30 16:21 bootstrap.json
-rwxr-xr-x 1 matchbox matchbox 130 12月 30 16:21 master-0.json
-rwxr-xr-x 1 matchbox matchbox 130 12月 30 16:21 worker-0.json
#
上例では、3つしか記載していませんが、実際には全ノード分必要になります。
3.4 TFTPの設定
# wget http://boot.ipxe.org/undionly.kpxe
# chmod 777 undionly.kpxe
# mkdir -p /var/lib/tftpboot/
# mv undionly.kpxe /var/lib/tftpboot/
#
3.5 dnsmasqにPXEを設定
まず、MatchBoxが名前解決するのに必要な情報を/etc/hostsに登録します。
192.168.2.21 bastion.ocp48.morifuku.com bastion
192.168.2.22 bootstrap.ocp48.morifuku.com bootstrap
192.168.2.23 master-0.ocp48.morifuku.com master-0
192.168.2.24 master-1.ocp48.morifuku.com master-1
192.168.2.25 master-2.ocp48.morifuku.com master-2
192.168.2.26 worker-0.ocp48.morifuku.com worker-0
(後略)
dnsmasqをインストールして、
# yum install dnsmasq
/etc/dnsmasq.confの最終行に以下を追加します。
この例では、DNSサーバと、NATサーバを192.168.2.21にしていますが、環境によって変えてください。
### OpenShift part
dhcp-host=00:01:e6:00:00:22,bootstrap,192.168.2.22
dhcp-host=00:01:e6:00:00:23,master-0,192.168.2.23
dhcp-host=00:01:e6:00:00:24,master-1,192.168.2.24
dhcp-host=00:01:e6:00:00:25,master-2,192.168.2.25
dhcp-host=00:01:e6:00:00:26,worker-0,192.168.2.26
(中略)
dhcp-option=option:dns-server,192.168.2.21
dhcp-option=option:netmask,255.255.255.0
dhcp-option=option:router,192.168.2.21
dhcp-leasefile=/var/lib/dnsmasq/dnsmasq.leases
enable-tftp
tftp-root=/var/lib/tftpboot
pxe-service=tag:#ipxe,x86PC,"PXE chainload to iPXE",undionly.kpxe
dhcp-userclass=set:ipxe,iPXE
pxe-service=tag:ipxe,x86PC,"iPXE",http://bastion.ocp48.morifuku.com:8080/boot.ipxe
また、必要に応じてdsmasq.resolv.conf
を設定します。
# cat /etc/dnsmasq.resolv.conf
nameserver 8.8.8.8
dnsmasqを起動します。
# systemctl enable dnsmasq
# systemctl start dnsmasq
# systemctl status dnsmasq
● dnsmasq.service - DNS caching server.
Loaded: loaded (/usr/lib/systemd/system/dnsmasq.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2022-12-30 17:15:39 JST; 7min ago
Main PID: 4829 (dnsmasq)
Tasks: 1 (limit: 98034)
Memory: 764.0K
CGroup: /system.slice/dnsmasq.service
└─4829 /usr/sbin/dnsmasq -k
12月 30 17:15:39 systemd[1]: Started DNS caching server..
#
3.6 OpenShiftのMaster/Workerのイグニッションファイルを設定
nginxをインストールして、
# yum install nginx
/etc/nginx/nginx.conf
を編集して(edit for PXE
をコメントを入れた4行)
server {
listen 8008 default_server; # edit for PXE
#listen 80 default_server; # edit for PXE
#listen [::]:80 default_server; # edit for PXE
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
disable_symlinks off; # edit for PXE
}
起動します。
# systemctl enable nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
# systemctl start nginx
OpenShitインストーラに生成されたイグニッションファイルを、配置します。
(openshift-install
の使用方法は本稿では省略)
# pwd
/root/ocp
# ./openshift-install create manifests --dir=bare-metal
(中略)
# ./openshift-install create ignition-configs --dir=bare-metal
(中略)
# mkdir -p /usr/share/nginx/html/ocp/rhcos/ignitions/
# cp ./bare-metal/*.ign /usr/share/nginx/html/ocp/rhcos/ignitions/
# ll /usr/share/nginx/html/ocp/rhcos/ignitions/
合計 276
-rw-r--r-- 1 root root 271950 9月 23 16:47 bootstrap.ign
-rw-r--r-- 1 root root 1725 9月 23 16:47 master.ign
-rw-r--r-- 1 root root 1725 9月 23 16:47 worker.ign
#
3.7 VMをネットワークインストールで構築
BOOTSTRAP、MASTER、WORKERのVMをPXEブート指定で起動すると、本PXEサーバからRHCOSがネットインストールされるようになります。 続いて、イグニッションファイルで指定された、BOOTSTRAP/MASTER/WORKERのイメージがインストールされ、 OCPが自動で構築されていきます。
(詳細説明は省略)
4. その他の解決方法
MatchBoxを利用することで、簡単にPXEサーバ環境を用意に構築するとこができますが、 GitHub内を検索してみると、その他にもPXEサーバ構築の方法がいろいろありそうです。
5. 今後の追記予定
- 他のバージョンのRHCOSのインストール方法を適宜追加予定。
- 「センター+エッジ構成」など、広域なOpenShift環境を作る場合を記載予定。