crcでOpenShiftをインストールするメモ

よく忘れるのでcrcでOpenShiftをインストールするメモを残しておきます。
crcを使えば簡単に1ノードのOpenShiftをデプロイすることができます。
ちょっと触ってみたいときや簡易的な検証をする時にはとても便利です。

環境情報

項目 バージョン
RHEL 8.8
CRC 2.19.0+a71226
OpenShift 4.12.13

今回はESXi上にVMを構築します。
スペックは以下の通りです。

項目
CPU 4
メモリ 16GB
HDD 100GB

crcではOpenShiftのイメージをKVMで動作させるので、VMのCPUの設定ある ハードウェア アシストによる仮想化をゲスト OS に公開 にチェックを入れます。

OpenShiftのインストール

ユーザーの作成

crcを操作するユーザーを作成してパスワードを設定します。

[root@homelab-1921681064 ~]# useradd crc
[root@homelab-1921681064 ~]# passwd crc

sudoの設定にcrcを追加します。

[root@homelab-1921681064 ~]# sudoedit /etc/sudoers
(snip)
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
crc     ALL=(ALL)       ALL
(snip)

crcのダウンロード

crcユーザーにスイッチしてcrcをダウンロードします。

[root@homelab-1921681064 ~]# su - crc
[crc@homelab-1921681064 ~]$ curl -L https://developers.redhat.com/content-gateway/file/pub/openshift-v4/clients/crc/2.19.0/crc-linux-amd64.tar.xz -O

ダウンロードしたアーカイブを解凍します。

[crc@homelab-1921681064 ~]$ tar Jxvf crc-linux-amd64.tar.xz

ホームディレクトリに bin を作ってcrcコマンドをコピーします。

[crc@homelab-1921681064 ~]$ mkdir bin
[crc@homelab-1921681064 ~]$ cp crc-linux-2.19.0-amd64/crc bin/

crcコマンドのパスを設定します。

[crc@homelab-1921681064 ~]$ vi .bashrc
(snip)
PATH=$PATH:/home/crc/bin/
[crc@homelab-1921681064 ~]$ . .bashrc
[crc@homelab-1921681064 ~]$ which crc
~/bin/crc

crcの設定

OpenShiftで使えるCPUとメモリーの初期設定は以下の通りです。

項目
CPU 4
Memory 9216MiB

必要に応じて変更してください。
ちなみに、Ansible Automation Platformをデプロイする場合はデフォルトのメモリサイズでは小さいためデプロイ時にエラーが発生します。
ここではメモリーのサイズを設定します。

[crc@homelab-1921681064 ~]$ crc config set memory 15405

セットアップ時のエラーを回避するため設定を追加します。

[crc@homelab-1921681064 ~]$ crc config set skip-check-daemon-systemd-unit true
[crc@homelab-1921681064 ~]$ crc config set skip-check-daemon-systemd-sockets true

上記設定をしなかった時のセットアップ時のエラー

Executing systemctl action failed:  exit status 1: Failed to connect to bus: No such file or directory

crcのセットアップ

crcのセットアップを実行します。
イメージのダウンロードに時間がかかるので気長に待ちましょう。

[crc@homelab-1921681064 ~]$ 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 <yes/no>'
Would you like to contribute anonymous usage statistics? [y/N]: N <- Nを入力
(snip)
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for crc: <- sudoが実行できるよにcrcのパスワードを入力
(snip)

OpenShiftの起動

OpenShiftの起動時に使用される Pull secret を以下のサイトから入手してホストにコピーします。
※ダウンロードするにはRed Hatアカウントが必要です

セットアップが終わったらOpenShiftを起動します。
※pull-secretというファイルがダウンロードしたファイルです

[crc@homelab-1921681064 ~]$ crc start -p pull-secret
(snip)
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

ocのパスを登録します。

[crc@homelab-1921681064 ~]$ crc oc-env >> .bashrc
[crc@homelab-1921681064 ~]$ which oc
~/.crc/bin/oc/oc

kubeadminでログインしてみます。

[crc@homelab-1921681064 ~]$ oc login -u kubeadmin https://api.crc.testing:6443
Logged into "https://api.crc.testing:6443" as "kubeadmin" using existing credentials.

You have access to 66 projects, the list has been suppressed. You can list all projects with 'oc projects'

Using project "default".
[crc@homelab-1921681064 ~]$ oc get pods --all-namespaces | head
NAMESPACE                                          NAME                                                      READY   STATUS        RESTARTS        AGE
hostpath-provisioner                               csi-hostpathplugin-dsbl7                                  4/4     Running       0               61d
openshift-apiserver-operator                       openshift-apiserver-operator-74548fc4c4-bk8jl             1/1     Running       0               62d
openshift-apiserver                                apiserver-8466f9767-dw777                                 2/2     Running       0               61d
openshift-authentication-operator                  authentication-operator-66f7f9fffc-llgqm                  1/1     Running       0               62d
openshift-authentication                           oauth-openshift-794c96b9c9-pgcqp                          0/1     Pending       0               5s
openshift-authentication                           oauth-openshift-fcc768d96-k6bmv                           1/1     Terminating   0               61d
openshift-cluster-machine-approver                 machine-approver-745cdf4b44-7xmlz                         2/2     Running       1 (10m ago)     62d
openshift-cluster-node-tuning-operator             cluster-node-tuning-operator-6467bbdb5-bm5c2              1/1     Running       0               62d
openshift-cluster-node-tuning-operator             tuned-2kl9l                                               1/1     Running       0               62d

OpenShiftに外部からアクセスする

VMのKVMで動作しているOpenShiftに外部からアクセスしてみます。

OpenShiftへアクセスする端末(クライアント)の hosts ファイルに以下の情報を追加します。
hosts に設定するIPアドレスは環境に合わせて(OpenShiftをデプロイしたESXi上のVMのIP)設定してください。ここでは 192.168.10.64 を設定しています。

% sudo vi /etc/hosts
(snip)
192.168.10.64 api.crc.testing canary-openshift-ingress-canary.apps-crc.testing console-openshift-console.apps-crc.testing default-route-openshift-image-registry.apps-crc.testing downloads-openshift-console.apps-crc.testing oauth-openshift.apps-crc.testing

VM側のKVM上で動作しているOpenShiftにアクセスできるようにSSHのポートフォワードを設定します。
rootで設定してください。

[root@homelab-1921681064 ~]# ssh -L 192.168.10.64:443:192.168.130.11:443 -L 192.168.10.64:80:192.168.130.11:80 192.168.10.64

firewalldの設定を追加します。

[root@homelab-1921681064 ~]# firewall-cmd --add-service=https --permanent
[root@homelab-1921681064 ~]# firewall-cmd --add-service=http --permanent
[root@homelab-1921681064 ~]# firewall-cmd --reload

これでクライアントの端末のブラウザから https://console-openshift-console.apps-crc.testing にアクセスしてみます。
OpenShiftのログイン画面が表示されれば成功です。

The post crcでOpenShiftをインストールするメモ first appeared on 日常系エンジニアのTech Blog.

Related Articles