みなさん、はじめまして。Red Hat OpenShift(以下OpenShift)の構築を担当している北出です。
今回は、OpenShiftを Single Node OpenShift(SNO)構成で構築してみた内容を共有します。一般的にOpenShiftでは、クラスタを構成するために複数のノードが必要とされ、仮想環境でもそれなりのスペックが要求されるため、検証環境の構築には高いハードルがありました。しかし、SNOはControl Plane・Worker・Infraノードを1台に集約した構成で、構築の手軽さといった観点から、検証環境の構築に最適です。
本記事では、踏み台サーバの設定からベアメタルサーバでのOpenShiftのAgent-basedインストールまでの手順を紹介します。
Single Node Openshift(SNO)について
Openshift4.2から4.8までの最小構成はControl Plane兼workerの3ノード構成でした。しかし、Openshift4.9からSingle Node Openshift構成が提供され、1ノードでOpenshiftの作成が可能になりました。以下が、Single Node Openshift最小リソース要件になります。(Openshift4.18の場合)
|
リソース |
最小要件 |
|
CPU |
8 CPU |
|
メモリ |
16 GB RAM |
|
ストレージ |
120 GB |
Single Node構成でのOpenShift構築手順
環境情報
|
OCPバージョン |
4.18.5 |
|
インターネット接続 |
接続可能 |
|
インストール方式 |
Agent-based |
|
SNO起動方法 |
ISOブート(Virtual Media) |
|
踏み台サーバOS |
RHEL9.5 |
|
DNSサーバ |
dnsmasq |
|
Webサーバ |
nginx |
ネットワーク情報
|
OCPクラスタ名 |
cluster01 |
|
ドメイン |
openshift.local |
|
IPアドレス(踏み台サーバ) |
172.30.209.230 |
|
ホスト名(踏み台サーバ) |
bastion01 |
|
IPアドレス(OCPホスト) |
172.30.209.231 |
|
ホスト名(OCPホスト) |
master01 |
|
デフォルトゲートウェイ |
172.30.208.1 |
構成図

1. 踏み台サーバの構築
1-1.DNS初期設定
踏み台サーバのマシンを起動・基本情報の設定後、DNSの設定を追加。
(dnsmasqを立てるまで参照する既存のDNSサーバのIPを指定)
#cat /etc/resolv.conf
nameserver 172.30.209.230
1-2.SSH Keypairの作成
SSHログインをするために、SSH Keypairを作成。
#ssh-keygen -t rsa -b 4096 -N ''
1-3.dnsmasqインストール・設定
dnsmasqをインストール。
#yum install -y dnsmasq
dnsmasqの設定ファイルを編集。
※/etc/dnsmasq.conf は変更せず、OpenShift用ファイルを新規作成。
#vi /etc/dnsmasq.d/dnsmasq-ocp.conf
/etc/dnsmasq.d/dnsmasq-ocp.conf
expand-host
bogus-pri
resolv-file=/etc/dnsmasq.resolv.con
# DNSサーバのIPアドレ
listen-address=127.0.0.1,(踏み台サーバのIPアドレス
# Dnsmasqがlistenするポー
port=5
# dnsmasqでキャッシュするレコード数(0にするとキャッシュしない
cache-size=
# DNSクエリに対してのログを出力す
log-querie
# ログの出力場
log-facility=/var/log/dnsmasq.lo
local=/openshift.local
domain=/openshift.loca
address=/api.cluster01.openshift.local/172.30.209.23
ptr-record=231.209.30.172.in-addr.arpa,api.cluster01.openshift.loca
address=/api-int.cluster01.openshift.local/172.30.209.23
ptr-record=231.209.30.172.in-addr.arpa,api-int.cluster01.openshift.loca
address=/.apps.cluster01.openshift.local/172.30.209.23
address=/bastion01.openshift.local/172.30.209.23
ptr-record=230.209.30.172.in-addr.arpa,bastion01.openshift.loca
address=/master01.cluster01.openshift.local/172.30.209.23
ptr-record=231.209.30.172.in-addr.arpa,master01.cluster01.openshift.local
内部ネットワークのDNSサーバ設定を編集
#cat /etc/dnsmasq.resolv.confnameserver (上位DNSサーバのIPアドレス)DNSサーバの設定ファイル編集
#vi /etc/resolv.conf/etc/resolv.conf
search openshift.local
nameserver 127.0.0.1
nameserver (上位DNSサーバのIPアドレス)
NetworkManagerからresolve.confの上書きを防ぐため、NetworkManagerの設定ファイルを変更。
/etc/NetworkManager/NetworkManager.conf
#vi /etc/NetworkManager/NetworkManager.conf[main]
#plugins=ifcfg-rh
dns=none
dnsmasqサービスの起動
#systemctl enable --now dnsmasq.service
#systemctl start dnsmasq
#systemctl status dnsmasq
#systemctl is-active dnsmasq※サービス起動後はDNSのテスト
1-4.nginxインストール
#yum install nginxnginxの設定
#vi /etc/nginx/nginx.conf/etc/nginx/nginx.conf
~中略~
http {
~中略~
server {
# listen 80;
# listen [::]:80;
listen 8080;
listen [::]:8080;
~中略~
}
disable_symlinks off;
}nginxサービスの起動
#systemctl enable --now nginx
#systemctl start nginx
#systemctl status nginx
2. RHCOS ISOイメージの作成
2-1.インストールで利用するファイルのダウンロード
作業用のディレクトリ作成
#mkdir -p /data/work/files
#cd /data/work/files/#wget https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/stable-4.18/openshift-install-linux-4.18.5.tar.gz
#tar zxf openshift-install-linux-4.18.5.tar.gz; cp openshift-install /usr/bin/; mv openshift-install /usr/local/bin/
#openshift-install version
openshift-install 4.18.5OpenShiftクライアント(Linux)のダウンロード・設定
#wget https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/stable-4.18/openshift-client-linux-4.18.5.tar.gz
#tar zxf openshift-client-linux-4.18.5.tar.gz; cp oc kubectl /usr/bin/; mv oc kubectl /usr/local/bin/
#oc version
Client Version: 4.18.5
Kustomize Version: v5.4.2
# kubectl version
Client Version: v1.31.1
Kustomize Version: v5.4.2pull-secretのダウンロード
ブラウザでhttps://console.redhat.com/openshift/downloadsにアクセスして保存。
(pull-secret.txt)
2-2. install-config.yamlとagent-config.yamlの作成
install-config.yamlとは?
OpenShiftインストーラーに対して、クラスタの構成・ネットワーク・ノード数・認証情報などを伝えるためのファイル
install-config.yamlの作成
apiVersion: v1
baseDomain: openshift.local
compute:
- hyperthreading: Enabled
architecture: amd64
name: worker
replicas: 0
controlPlane:
hyperthreading: Enabled
architecture: amd64
name: master
replicas: 1
metadata:
name: cluster01
networking:
clusterNetwork:
- cidr: 10.128.0.0/14
hostPrefix: 23
networkType: OVNKubernetes
serviceNetwork:
- 172.21.0.0/16
machineNetwork:
- cidr: 172.30.208.0/22
platform:
none: {}
bootstrapInPlace:
installationDisk: /dev/sda
pullSecret: '{"auths":{"××××××××":{"auth":"××××××××"}}}'
sshKey: 'ssh-rsa ×××××××× root@bastion1.openshift.local'※platform:の内容は、本ブログではAgent-basedインストールのためnone
※pullSecret:の内容は、2-1でダウンロードしたpull-secret.txtを張り付け
※sshKey の内容は、1-2で作成した公開鍵ファイルを張り付け
agent-config.yamlとは?
Agent-based インストール方式で使用される構成ファイルで、各ノード(ホスト)の詳細な設定情報を宣言的に定義するためのファイル
agent-config.yamlの作成
apiVersion: v1beta1
kind: AgentConfig
metadata:
name: cluster01
rendezvousIP: 172.30.209.231
additionalNTPSources:
- bastion01.openshift.local
hosts:
- hostname: master01.openshift.local
role: master
interfaces:
- name: eno1
macAddress: 5C:ED:8C:B0:69:76
rootDeviceHints:
deviceName: /dev/sda
networkConfig:
interfaces:
- name: eno1
type: ethernet
state: up
mac-address: 5C:ED:8C:B0:69:76
ipv4:
enabled: true
address:
- ip: 172.30.209.231
prefix-length: 24
dhcp: false
dns-resolver:
config:
server:
- 172.30.209.230
routes:
config:
- destination: 0.0.0.0/0
next-hop-address: 172.30.208.1
next-hop-interface: eno1
table-id: 2542-3.RHCOS ISOイメージの作成
install-config.yamlとagent-config.yamlが格納されているディレクトリで以下のコマンドを実行。
#openshift-install agent create image --dir ./
WARNING BootstrapInPlace.InstallationDisk: /dev/sda is ignored
INFO Configuration has 1 master replicas and 0 worker replicas
INFO The rendezvous host IP (node0 IP) is 172.30.209.231
INFO Extracting base ISO from release payload
INFO Base ISO obtained from release and cached at [/root/.cache/agent/image_cache/coreos-x86_64.iso]
INFO Consuming Install Config from target directory
INFO Consuming Agent Config from target directory
INFO Generated ISO at agent/agent.x86_64.iso.
注意:openshift-installコマンドでISOを作成する際に、ディレクトリにあるinstall-config.yamlとagent-config.yamlが削除されてしまうため、別のディレクトリにコピーするなどで対応してください
3. OpenShiftインストール
3.1.OpenShiftインストール
作成したagent.x86_64.isoをnginxの公開ディレクトリに配置
cp agent/agent.x86_64.iso /usr/share/nginx/html/iLOのOSコンソールで「CD/DVD」、「Virtual Media」に移動
http://172.30.209.230:8080/agent.x86_64.isoを指定



F11を押下

iLO Virtual USB 3: iLO Virtual CD-ROMを選択

クラスタインストール中のログを確認する

# openshift-install --dir ./ agent wait-for install-complete --log-level=DEBUGインストールログに「Install complete!」メッセージが出力されるまで待機
# openshift-install --dir ./ agent wait-for install-complete --log-level=DEBUG
<中略>
INFO Cluster is installed
INFO Install complete!
INFO To access the cluster as the system:admin user when using 'oc', run
INFO export KUBECONFIG=/data/work/auth/kubeconfig
INFO Access the OpenShift web-console here: https://console-openshift-console.apps.cluster01.openshift.local
INFO Login to the console with user: "kubeadmin", and password: " ××××××"※インストールが完了すると、インストール実行ディレクトリ配下にauthという名前のクラスタへのアクセスに必要な認証情報が格納されているディレクトリができます。
OCログイン
#oc login https://api.cluster01.openshift.local:6443 -u kubeadmin -p xxxxx※パスワードはauthディレクトリ配下にあるkubeadmin-passwordに記載
状態確認
#oc get node
NAME STATUS ROLES AGE VERSION
master01.openshift.local Ready control-plane,master,worker 61m v1.31.6Cluster Operatorの状態を確認(エラーメッセージが表示されなければOKです)
#oc get co
<中略>3-2.接続設定
Webコンソールへ接続するPCのhostsに下記を設定
C:\Windows\System32\drivers\etc\hosts
172.30.209.231 console-openshift-console.apps.cluster01.openshift.local
172.30.209.231 oauth-openshift.apps.cluster01.openshift.localWebコンソールのURLの表示
#oc whoami --show-console
https://console-openshift-console.apps.cluster01.openshift.localコンソールにアクセス(お疲れ様でした。構築完了です!)

(参考 タブ補完の有効化)
#oc completion bash > oc_bash_completion
#sudo cp oc_bash_completion /etc/bash_completion.d/












