はじめに
皆さん、こんにちは。入社6年目のクラウド技術部のR.Aです。
前回は OpenShift Container Platform の構築手順をお届けしました。 
OpenShift Container Platformの最小構成はMaster3台、Worker2台であり、ここまで大掛かりなシステムは構築できないといった方に向けたブログです。 
今回はOpenShift Local (旧称Red Hat CodeReady Containers)の構築手順をご紹介します!  
OpenShift Container Platform の詳細については以下のブログをご覧ください。 
クラウドネイティブ化のすすめ - OpenShiftという選択肢 -  
目次
- はじめに
 - OpenShift Localについて
 - OpenShift Local の最小システム要件
 - OpenShift Local の構築
 - 手順
 - 構築時に出力されたエラー紹介
 - 1.ERRO crc should not be run as root
 - 2.ERRO Could not install required packages: サブスクリプション管理リポジトリーを更新しています。
 - 3.TLS handshake timeout
 - 4.connect: no such file or directory
 - おわりに
 
OpenShift Localについて
OpenShift Localは、Red Hat IDがあれば無償で使うことができる1つのサーバにギュッと収めたOpenShiftのことです。 
Red Hat CodeReady Containers と呼ばれていたもので、開発者のデスクトップ上にOpenShift環境を構築すること想定されているため、本番稼働するシステムには適していません。 
Red Hat OpenShift Local(旧称Red Hat CodeReady Containers)
公式ドキュメントのOpenShift Container Platform インストールとの違いを確認するといくつか提供されていないOperatorが存在しますが、コアコンポーネントは使用することができます。
- 提供されていないOperator
- Cloud Credential Operator
 - Cluster Autoscaler Operator
 - Cloud Controller Manager Operator
 
 
その他にもドメインが固定されていることなど、いくつかの制約がありますので、公式ドキュメントをご確認ください。
OpenShift Local の最小システム要件
早速構築と行きたいのですがいくつか満たさないといけない条件があるため、最小システム要件の概要を説明します。
ハードウェア要件
必要なリソースは以下です。 
公式ドキュメントにはメモリ、ディスクの空き領域が下の数字で紹介されているので、マシンスペックとしてはもう少し大きめである必要があるので注意です。  
- CPU: 4コア
 - メモリ: 10.5GB
 - ディスク: 35GB
 
OS要件
OSの種類はWindowsからMacOS、Linuxの主要どころからFedoraやUbuntuなどの様々なOSが対応しています。 
公式ドキュメントに記載されている一部を紹介します。  
- Windows 10 / Windows 11
- エディションに細かい制約あり
 
 - MacOS 13 Ventura 以降
 - Red Hat Enterprise Linux
- 最新の2つのマイナーリリース
 
 - CentOS
- 最新の 8 および 9 の 2つのマイナーリリース
 
 - Fedora
- 最新の2つのマイナーリリース
 
 - Ubuntu 18.04 LTS 以降
 - Debian 10 以降
 
OpenShift Local の構築
前提
今回はローカルの作業PCにOpenShift Localを構築するのではなく、社内の検証環境(VMware vSphere)に仮想マシン※を作成し、そこにOpenShift Localを構築します。 
そのため、仮想マシンが作成できるような環境があること前提に手順を記載します。  
※EC2インスタンスをはじめとしたのクラウドベンダの仮想マシンはNested Virtualization(ネストされた仮想化)はできないことが多いです。 
 ベアメタルインスタンス使用するとかそのほかの条件満たすなど方法はあるみたいですが、手ごろな弊社環境を使います。  :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
環境
- 作業PCは、Windows11です。
- Red Hat Hybrid Cloud Consoleに接続しパッケージをダウンロードするために使用します。
 - また、仮想マシンに接続するためにも使用します。
 
 - 仮想マシンは、Red Hat Enterprise Linux 9.4です。
- OpenShift 4.19.13 を構築します。
 - 仮想マシンのリソースは手順1-2を確認ください。
 
 
  
手順
- 環境準備
- 作業PCで必要なパッケージをダウンロード
- OpenShift Local(crc コマンド)
 
 - 作業PCから仮想マシンを作成
 
 - 作業PCで必要なパッケージをダウンロード
 - OpenShift Localの構築
- 仮想マシンにOpenShift Localをインストール
 - 仮想マシンにOpenShift Localを構築
 - 仮想マシンからOpenShift Web Consoleに接続
 
 - OpenShift Localの削除
- 仮想マシンにOpenShift Localを削除
 
 
1-1. 作業PCで必要なパッケージをダウンロード
インストーラがダウンロードできるredhatの以下のURLにアクセスします。
ログインが求められる場合はログインしてください。
  
OpenShift Local(crc コマンド)をダウンロードします。 
同じ画面にあるpull secretも一緒にダウンロードします。  
  
1-2. 作業PCから仮想マシンを作成
以下のリソースで仮想マシンを作成します。
- CPU: 4コア (ハードウェア仮想化をオン)
 - メモリ: 12GB
 - ディスク: 50GB(シン プロビジョニング)
 
  
OpenShift Web Consoleに触るため、RHELはGUIでインストールします。
  
2-1. 仮想マシンにOpenShift Localをインストール
ダウンロードしたパッケージを作業PCから仮想マシンへscpコマンド等で連携します。 
解凍し、crcコマンドが使えることを crc version コマンドで確認します。 
※公式ドキュメントにはパスを通すようにしていますが、以下のログではフルパス指定しています。  
[rei@rei-ocp-local-01 ~]$ ls
anaconda-ks.cfg  crc-linux-amd64.tar.xz
[rei@rei-ocp-local-01 ~]$ tar xvf crc-linux-amd64.tar.xz
crc-linux-2.55.0-amd64/
crc-linux-2.55.0-amd64/LICENSE
crc-linux-2.55.0-amd64/crc
[rei@rei-ocp-local-01 ~]$ ~/crc-linux-2.55.0-amd64/crc version
CRC version: 2.55.0+5be569
OpenShift version: 4.19.13
MicroShift version: 4.19.7
[rei@rei-ocp-local-01 ~]$
2-2. 仮想マシンにOpenShift Localを構築
crc setup -> crc start の順でコマンドを実行することでOpenShift Localを構築します。 
以下のログでは、TLS handshake timeoutのエラーが出力されたため、crc setup に -b crc_libvirt_4.19.13_amd64.crcbundle のオプションを付けて実行しています。 
詳細はエラー紹介をご覧ください。  
[rei@rei-ocp-local-01 ~]$ crc-linux-2.55.0-amd64/crc setup -b crc_libvirt_4.19.13_amd64.crcbundle
INFO Using bundle path crc_libvirt_4.19.13_amd64.crcbundle
INFO Checking if running as non-root
INFO Checking if running inside WSL2
INFO Checking if crc-admin-helper executable is cached
INFO Checking if running on a supported CPU architecture
INFO Checking if crc executable symlink exists
INFO Creating symlink for crc executable
INFO Checking minimum RAM requirements
INFO Check if Podman binary exists in: /home/rei/.crc/bin/oc
INFO Checking if Virtualization is enabled
INFO Checking if KVM is enabled
INFO Checking if libvirt is installed
INFO Checking if user is part of libvirt group
INFO Checking if active user/process is currently part of the libvirt group
INFO Checking if libvirt daemon is running
INFO Checking if a supported libvirt version is installed
INFO Checking if crc-driver-libvirt is installed
INFO Checking crc daemon systemd service
INFO Setting up crc daemon systemd service
INFO Checking crc daemon systemd socket units
INFO Setting up crc daemon systemd socket units
INFO Checking if vsock is correctly configured
INFO Setting up vsock support
INFO Using root access: Setting CAP_NET_BIND_SERVICE capability for /home/rei/crc-linux-2.55.0-amd64/crc executable
INFO Using root access: Creating udev rule for /dev/vsock
INFO Using root access: Changing permissions for /etc/udev/rules.d/99-crc-vsock.rules to 644
INFO Using root access: Reloading udev rules database
INFO Using root access: Loading vhost_vsock kernel module
INFO Using root access: Creating file /etc/modules-load.d/vhost_vsock.conf
INFO Using root access: Changing permissions for /etc/modules-load.d/vhost_vsock.conf to 644
INFO Checking if CRC bundle is extracted in '$HOME/.crc'
INFO Checking if crc_libvirt_4.19.13_amd64.crcbundle exists
Your system is correctly setup for using CRC. Use 'crc start' to start the instance
[rei@rei-ocp-local-01 ~]$
[rei@rei-ocp-local-01 ~]$ ~/crc-linux-2.55.0-amd64/crc start
INFO Using bundle path /home/rei/.crc/cache/crc_libvirt_4.19.13_amd64.crcbundle
INFO Checking if running as non-root
INFO Checking if running inside WSL2
INFO Checking if crc-admin-helper executable is cached
INFO Checking if running on a supported CPU architecture
INFO Checking if crc executable symlink exists
INFO Checking minimum RAM requirements
INFO Check if Podman binary exists in: /home/rei/.crc/bin/oc
INFO Checking if Virtualization is enabled
INFO Checking if KVM is enabled
INFO Checking if libvirt is installed
INFO Checking if user is part of libvirt group
INFO Checking if active user/process is currently part of the libvirt group
INFO Checking if libvirt daemon is running
INFO Checking if a supported libvirt version is installed
INFO Checking if crc-driver-libvirt is installed
INFO Checking crc daemon systemd socket units
INFO Checking if vsock is correctly configured
INFO Loading bundle: crc_libvirt_4.19.13_amd64...
CRC requires a pull secret to download content from Red Hat.
You can copy it from the Pull Secret section of https://console.redhat.com/openshift/create/local.
? Please enter the pull secret ***
INFO Creating CRC VM for OpenShift 4.19.13...
INFO Generating new SSH key pair...
INFO Generating new password for the kubeadmin user
INFO Starting CRC VM for openshift 4.19.13...
INFO CRC instance is running with IP 127.0.0.1
INFO CRC VM is running
INFO Updating authorized keys...
INFO Configuring shared directories
INFO Check internal and public DNS query...
INFO Check DNS query from host...
INFO Verifying validity of the kubelet certificates...
INFO Starting kubelet service
INFO Waiting for kube-apiserver availability... [takes around 2min]
INFO Adding user's pull secret to the cluster...
INFO Updating SSH key to machine config resource...
INFO Overriding password for developer user
INFO Changing the password for the users
INFO Updating cluster ID...
INFO Updating root CA cert to admin-kubeconfig-client-ca configmap...
INFO Starting openshift instance... [waiting for the cluster to stabilize]
INFO 4 operators are progressing: console, image-registry, ingress, network
INFO 6 operators are progressing: authentication, console, image-registry, ingress, network, ...
INFO 2 operators are progressing: image-registry, network
INFO All operators are available. Ensuring stability...
INFO Operators are stable (2/3)...
INFO Operators are stable (3/3)...
INFO Waiting until the user's pull secret is written to the instance disk...
INFO Adding crc-admin and crc-developer contexts to kubeconfig...
Started the OpenShift cluster.
The server is accessible via web console at:
  https://console-openshift-console.apps-crc.testing
Log in as administrator:
  Username: kubeadmin
  Password: xxx
Log in as user:
  Username: developer
  Password: xxx
Use the 'oc' command line interface:
  $ eval $(crc oc-env)
  $ oc login -u developer https://api.crc.testing:6443
[rei@rei-ocp-local-01 ~]$
2-3. 仮想マシンからOpenShift Web Consoleに接続
仮想マシンのWebブラウザに OpenShift Web Console のURLを入力しログインします。 
URLやログイン情報は手順2-2のコマンド実行後に出力されます。  
  
  
3-1. 仮想マシンにOpenShift Localを削除
crc delete コマンドを使ってOpenShift Localを削除します。  
[rei@rei-ocp-local-01 ~]$ ~/crc-linux-2.55.0-amd64/crc delete
Do you want to delete the instance? [y/N]: y
Deleted the instance
[rei@rei-ocp-local-01 ~]$
構築時に出力されたエラー紹介
ココからは構築時に遭遇したエラー紹介です。 
初歩的なミスも多くありますが、同じ問題出た方は参考にして欲しいです。  
1.ERRO crc should not be run as root
手順2-2のcrc setupコマンドの実行時にrootユーザじゃダメだよって出力されました。  
1.エラー詳細
[root@rei-ocp-local-01 ~]# ~/crc-linux-2.55.0-amd64/crc setup
CRC is constantly improving and we would like to know more about usage (more details at https://developers.redhat.com/article/tool-data-collection)
Your preference can be changed manually if desired using 'crc config set consent-telemetry '
Would you like to contribute anonymous usage statistics? [y/N]: y
Thanks for helping us! You can disable telemetry with the command 'crc config set consent-telemetry no'.
INFO Using bundle path /root/.crc/cache/crc_libvirt_4.19.13_amd64.crcbundle
INFO Checking if running as non-root
ERRO crc should not be run as root
^C
[root@rei-ocp-local-01 ~]#
 
1.原因
rootユーザではcrcコマンドが実行できません。 
公式ドキュメントにもちゃんと書いてありました、、。  
Open a terminal with a user account with administrator access (but not logged in as root user) and run:
1.解決策/対応策
sudo が使える rootユーザ以外のユーザで構築を進めましょう!
2.ERRO Could not install required packages: サブスクリプション管理リポジトリーを更新しています。
手順2-2のcrc setupコマンドを実行時にRed Hatのサブスクリプション登録していないエラーが出力されました。  
2.エラー詳細
[rei@rei-ocp-local-01 ~]$ ~/crc-linux-2.55.0-amd64/crc setup
INFO Using bundle path /home/rei/.crc/cache/crc_libvirt_4.19.13_amd64.crcbundle
INFO Checking if running as non-root
<--- 省略 --->
INFO Using root access: Installing virtualization packages
ERRO Could not install required packages: サブスクリプション管理リポジトリーを更新しています。
コンシューマー識別子を読み込めません
This system is not registered with an entitlement server. You can use "rhc" or "subscription-manager" to register.
 exit status 1: エラー: "/etc/yum.repos.d", "/etc/yum/repos.d", "/etc/distro.repos.d" には有効化されたリポジトリーがありません。
[rei@rei-ocp-local-01 ~]$
2.原因
RHELのサブスクリプションを登録しないといけないです。 
前提条件にしっかり書いてありました、、、。  
Linux
  Red Hat Enterprise Linux
  - Latest two minor releases.
  - The host running CRC is registered with the Red Hat Customer Portal.
  - libvirt and NetworkManager packages are installed.
2.解決策/対応策
subscription-manager register コマンドを実行して登録しましょう!  
[rei@rei-ocp-local-01 ~]$ subscription-manager status
スーパーユーザー権限を必要とする"subscription-manager"を実行しようとしていますが、
 実行するには追加情報が必要です。
"root" として認証しています
パスワード:
+-------------------------------------------+
   システムのステータス詳細
+-------------------------------------------+
全体的な状態: 不明
システムの目的の状態: 不明
[rei@rei-ocp-local-01 ~]$ subscription-manager register
スーパーユーザー権限を必要とする"subscription-manager"を実行しようとしていますが、
 実行するには追加情報が必要です。
"root" として認証しています
パスワード:
登録中: subscription.rhsm.redhat.com:443/subscription
ユーザー名: xxx@reqtc.com
パスワード:
このシステムは、次の ID で登録されました: a9172961-1b63-4e93-adf3-af6f63dfc013
登録したシステム名: rei-ocp-local-01
[rei@rei-ocp-local-01 ~]$ subscription-manager status
スーパーユーザー権限を必要とする"subscription-manager"を実行しようとしていますが、
 実行するには追加情報が必要です。
"root" として認証しています
パスワード:
+-------------------------------------------+
   システムのステータス詳細
+-------------------------------------------+
全体的な状態: 無効
コンテンツアクセスモードは、シンプルコンテンツアクセスに設定されています。このホストは、サブスクリプションのステータスに関係なく、コンテンツにアクセスできます。
システムの目的の状態: 無効
[rei@rei-ocp-local-01 ~]$
3.TLS handshake timeout
手順2-2で実行する crc setup コマンドにてハンドシェイクのタイムアウトエラーが出力されました。  
3.エラー詳細
[rei@rei-ocp-local-01 ~]$ ~/crc-linux-2.55.0-amd64/crc setup
CRC is constantly improving and we would like to know more about usage (more details at https://developers.redhat.com/article/tool-data-collection)
<--- 省略 --->
INFO Checking if /home/rei/.crc/cache/crc_libvirt_4.19.13_amd64.crcbundle exists
INFO Getting bundle for the CRC executable
INFO Downloading bundle: /home/rei/.crc/cache/crc_libvirt_4.19.13_amd64.crcbundle...
ERRO unable to get verified hash for default bundle: Get "https://mirror.openshift.com/pub/openshift-v4/clients/crc/bundles/openshift/4.19.13/sha256sum.txt.sig": net/http: TLS handshake timeout
[rei@rei-ocp-local-01 ~]$
3.原因
原因の特定はできなかったです。 
以下の回避策・対応策のログを確認いただきたいのですが、curlでのダウンロードでも1回目が失敗しているんですよね。 
うーん、なんででしょう。  
3.解決策/対応策
curl コマンドで事前にダウンロードしておき、手順2-2で実行する crc setup コマンドを実行する際に -b crc_libvirt_4.19.13_amd64.crcbundle オプションを付けます。  
[rei@rei-ocp-local-01 ~]$ curl -OL "https://mirror.openshift.com/pub/openshift-v4/clients/crc/bundles/openshift/4.19.13/sha256sum.txt.sig"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  1355  100  1355    0     0   1334      0  0:00:01  0:00:01 --:--:--  1334
[rei@rei-ocp-local-01 ~]$ ls
crc-linux-2.55.0-amd64  crc-linux-amd64.tar.xz  sha256sum.txt.sig
[rei@rei-ocp-local-01 ~]$ cd .crc/cache/
[rei@rei-ocp-local-01 cache]$ curl -OL https://developers.redhat.com/content-gat
eway/file/pub/openshift-v4/clients/crc/bundles/openshift/4.19.13/crc_libvirt_4.1
9.13_amd64.crcbundle
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:02 --:--:--     0
100 6554M  100 6554M    0     0  70.3M      0  0:01:33  0:01:33 --:--:-- 89.0M
[rei@rei-ocp-local-01 cache]$ ll
合計 6711988
-rw-r--r--. 1 rei rei 6873072709 10月 11 12:31 crc_libvirt_4.19.13_amd64.crcbundle
[rei@rei-ocp-local-01 cache]$ cat ~/sha256sum.txt.sig | grep "crc_libvirt_4.19.13_amd64.crcbundle"
24ad08b0cefdb8db71cdfcd1bc1734459ba906d7fc294c50ec05e04b3e8c559b  crc_libvirt_4.19.13_amd64.crcbundle
[rei@rei-ocp-local-01 cache]$ sha256sum crc_libvirt_4.19.13_amd64.crcbundle
24ad08b0cefdb8db71cdfcd1bc1734459ba906d7fc294c50ec05e04b3e8c559b  crc_libvirt_4.19.13_amd64.crcbundle
[rei@rei-ocp-local-01 cache]$
[rei@rei-ocp-local-01 ~]$ ~/crc-linux-2.55.0-amd64/crc setup -b crc_libvirt_4.19.13_amd64.crcbundle
INFO Using bundle path crc_libvirt_4.19.13_amd64.crcbundle
<--- 省略 --->
INFO Checking if crc_libvirt_4.19.13_amd64.crcbundle exists
Your system is correctly setup for using CRC. Use 'crc start' to start the instance
4.connect: no such file or directory
手順2-2で実行する crc start コマンド実行時にcrcデーモン動いてないよ(?)エラーが出力されました。  
4.エラー詳細
[rei@rei-ocp-local-01 ~]$ ~/crc-linux-2.55.0-amd64/crc start
ERRO Is 'crc daemon' running? Cannot reach daemon API: Get "http://unix/api/version": dial unix /home/rei/.crc/crc-http.sock: connect: no such file or directory
4.原因
原因の特定はできなかったですが、以下のブログにデーモンの設定がうまく行ってないのかもとのことでした。
4.解決策/対応策
先ほどのブログと同じ事象だったため、crc cleanupコマンドを実行して、crc setup -> crc start を実行しなおしました。  
[rei@rei-ocp-local-01 ~]$ ~/crc-linux-2.55.0-amd64/crc cleanup
INFO Removing vsock configuration
INFO Using root access: Removing udev rule in /etc/udev/rules.d/99-crc-vsock.rules
<--- 省略 --->
INFO Removing older logs
Cleanup finished
[rei@rei-ocp-local-01 ~]$ ~/crc-linux-2.55.0-amd64/crc setup -b crc_libvirt_4.19.13_amd64.crcbundle
INFO Using bundle path crc_libvirt_4.19.13_amd64.crcbundle
<--- 省略 --->
INFO Downloading bundle: crc_libvirt_4.19.13_amd64.crcbundle...
INFO Uncompressing crc_libvirt_4.19.13_amd64.crcbundle
[rei@rei-ocp-local-01 ~]$ ~/crc-linux-2.55.0-amd64/crc start
INFO Using bundle path /home/rei/.crc/cache/crc_libvirt_4.19.13_amd64.crcbundle
INFO Checking if running as non-root
<--- 省略 --->
[rei@rei-ocp-local-01 ~]$
おわりに
本ブログでは構築の手順をご紹介しました。 
OpenShift の機能紹介や他の構築方法などは別のブログに記載する予定ですので、お待ちください! 
本ブログが OpenShift Local を構築する方の参考になれば幸いです。  


