ひょんなことから、OpenShiftを使うことになった。ただ、まずは手元で簡単に動かしてみたい。なんとKindやminikubeのように動かせることが判明。やってみた。
ちなみに、16インスタンスも無料で使えるRed HatのDeveloper登録をまずしておくこと。(無償なのでやらない理由はないと思うw)
ハードウェアの準備
CPU、メモリはふんだんにあったほうがいい。特にCPUのパワーが必要!MacBook Airだときついw
4 virtual CPUs (vCPUs) / 9 GB RAM / 35 GB HDD
以下いずれかの環境。
Windows 10 Fall Creators Update (version 1709)以降
macOS 10.12 Sierra 以降
Red Hat Enterprise Linux/CentOS 7.5 以降 (Xwindowのインストールが必要)
一度、ここをみておくといい。https://code-ready.github.io/crc/
バイナリの入手方法
cloud.redhat.comにアクセスして、Clustersを選択、Create clusterをクリック
Localタブに移動して、プラットフォームに応じたファイルをダウンロード。2GBくらいある。
Linux(CentOS7)の場合は、KVMで動作
一般ユーザで実行する必要がある。また、ローカルでウェブブラウザを必要とするのでX Windowが必要
https://kubernetes.io/ja/docs/tasks/tools/install-kubectl/
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
yum install -y kubectl git
yum -y groupinstall “GNOME Desktop”
mkdir crc
tar Jvfz crc-linux-amd64.tar.xz -C crc
MACの場合は、Hyper-Kitで動作
% brew install kubectrl
% mkdir ~/crc
% mv crc-macos-amd64.tar.xz crc
% cd crc/
% tar xvfz crc-macos-amd64.tar.xz
x crc-macos-1.21.0-amd64/
x crc-macos-1.21.0-amd64/LICENSE
x crc-macos-1.21.0-amd64/doc.pdf
x crc-macos-1.21.0-amd64/crc
% cd crc-macos-1.21.0-amd64/
% ls
LICENSE crc* doc.pdf
% xattr -d com.apple.quarantine ./crc
Windowsの場合は、Hyper-Vで動作
ー>未検証
以下各プラットフォーム共通だと思われる。Macでやった場合のログ
% ./crc –help
CodeReady Containers is a tool that manages a local OpenShift 4.x cluster optimized for testing and development purposes
Usage:
crc [flags]
crc [command]
Available Commands:
cleanup Undo config changes
config Modify crc configuration
console Open the OpenShift Web Console in the default browser
delete Delete the OpenShift cluster
help Help about any command
ip Get IP address of the running OpenShift cluster
oc-env Add the ‘oc’ executable to PATH
podman-env Setup podman environment
setup Set up prerequisites for the OpenShift cluster
start Start the OpenShift cluster
status Display status of the OpenShift cluster
stop Stop the OpenShift cluster
version Print version information
Flags:
-h, –help help for crc
–log-level string log level (e.g. “debug | info | warn | error”) (default “info”)
Use “crc [command] –help” for more information about a command.
セットアップ
% ./crc setup
CodeReady Containers is constantly improving and we would like to know more about usage!
Would you like to contribute anonymous usage statistics (more details at https://developers.redhat.com/article/tool-data-collection)? [y/N]:
No worry, you can still enable telemetry manually with the command ‘crc config set consent-telemetry yes’.
INFO Checking if running as non-root
INFO Checking if podman remote executable is cached
INFO Checking if admin-helper executable is cached
INFO Caching admin-helper executable
INFO Will use root access: change ownership of /Users/tmase/.crc/bin/admin-helper-darwin
INFO Will use root access: set suid for /Users/tmase/.crc/bin/admin-helper-darwin
INFO Checking if CRC bundle is extracted in ‘$HOME/.crc’
INFO Extracting bundle from the CRC executable
crc.qcow2: 9.85 GiB / 9.85 GiB [————————————] 100.00%
INFO Checking minimum RAM requirements
INFO Checking if HyperKit is installed
INFO Setting up virtualization with HyperKit
INFO Will use root access: change ownership of /Users/tmase/.crc/bin/hyperkit
INFO Will use root access: set suid for /Users/tmase/.crc/bin/hyperkit
INFO Checking if crc-driver-hyperkit is installed
INFO Installing crc-machine-hyperkit
INFO Will use root access: change ownership of /Users/tmase/.crc/bin/crc-driver-hyperkit
INFO Will use root access: set suid for /Users/tmase/.crc/bin/crc-driver-hyperkit
INFO Checking file permissions for /etc/hosts
INFO Checking file permissions for /etc/resolver/testing
INFO Setting file permissions for /etc/resolver/testing
INFO Will use root access: create dir /etc/resolver
INFO Will use root access: create file /etc/resolver/testing
INFO Will use root access: change ownership of /etc/resolver/testing
Setup is complete, you can now run ‘crc start’ to start the OpenShift cluster
pull-secretを入手
cloud.redhat.comにログインをして、localのタブでDownload pull secretをクリック。pull-secret.txtがダウンロードされる。
% mv ~/Downloads/pull-secret.txt .
% ./crc start -p pull-secret.txt
INFO Checking if running as non-root
INFO Checking if podman remote executable is cached
INFO Checking if admin-helper executable is cached
INFO Checking minimum RAM requirements
INFO Checking if HyperKit is installed
INFO Checking if crc-driver-hyperkit is installed
INFO Checking file permissions for /etc/hosts
INFO Checking file permissions for /etc/resolver/testing
INFO Loading bundle: crc_hyperkit_4.6.9.crcbundle …
INFO Verifying bundle crc_hyperkit_4.6.9.crcbundle …
INFO Creating CodeReady Containers VM for OpenShift 4.6.9…
INFO CodeReady Containers VM is running
INFO Generating new SSH Key pair …
INFO Updating authorized keys …
INFO Copying kubeconfig file to instance dir …
INFO Starting network time synchronization in CodeReady Containers VM
INFO Restarting the host network
INFO Check internal and public DNS query …
INFO Check DNS query from host …
INFO Adding user’s pull secret to instance disk…
INFO Verifying validity of the kubelet certificates …
INFO Starting OpenShift kubelet service
INFO Adding user’s pull secret to the cluster …
INFO Updating cluster ID …
INFO Starting OpenShift cluster … [waiting 3m]
INFO Updating kubeconfig
WARN Skipping the kubeconfig update. Cluster operator authentication still not ready after 2min.
WARN The cluster might report a degraded or error state. This is expected since several operators have been disabled to lower the resource usage. For more information, please consult the documentation
Started the OpenShift cluster
To access the cluster, first set up your environment by following the instructions returned by executing ‘crc oc-env’.
Then you can access your cluster by running ‘oc login -u developer -p developer https://api.crc.testing:6443’.
To login as a cluster admin, run ‘oc login -u kubeadmin -p D4tTL-hJYdy-qe36Y-okTwh https://api.crc.testing:6443’.
You can also run ‘crc console’ and use the above credentials to access the OpenShift web console.
The console will open in your default browser.
% ./crc oc-env
export PATH=”/Users/tmase/.crc/bin/oc:$PATH”
# Run this command to configure your shell:
# eval $(crc oc-env)
% eval $(./crc oc-env)
% oc login -u kubeadmin -p D4tTL-hJYdy-qe36Y-okTwh https://api.crc.testing:6443
The server uses a certificate signed by an unknown authority.
You can bypass the certificate check, but any data you send to the server could be intercepted by others.
Use insecure connections? (y/n): y
Login successful.
You have access to 58 projects, the list has been suppressed. You can list all projects with ‘ projects’
Using project “default”.
Welcome! See ‘oc help’ to get started.
% ./crc status
CRC VM: Running
OpenShift: Starting (v4.6.9)
Disk Usage: 10.88GB of 32.72GB (Inside the CRC VM)
Cache Usage: 13.53GB
Cache Directory: /Users/tmase/.crc/cache
ここからは待つ必要がある。面倒なら10分程度休憩
2.3分待つ
% oc version
Client Version: 4.6.9
Server Version: 4.6.9
Kubernetes Version: v1.19.0+7070803
% oc get nodes
NAME STATUS ROLES AGE VERSION
crc-lf65c-master-0 Ready master,worker 18d v1.19.0+7070803
% oc status
In project default on server https://api.crc.testing:6443
svc/openshift – kubernetes.default.svc.cluster.local
svc/kubernetes – 172.25.0.1:443 -> 6443
View details with ‘oc describe /’ or list resources with ‘oc get all’.
% oc get all
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 172.25.0.1 443/TCP 28d
service/openshift ExternalName kubernetes.default.svc.cluster.local 28d
5分くらいまつ。
コンソールにアクセス
% ./crc console
Opening the OpenShift Web Console in the default browser…
https://console-openshift-console.apps-crc.testing が開く
Kube:adminを選択
kubeadmin / D4tTL-hJYdy-qe36Y-okTwh でログイン
コンソールが表示される。
以下終了、削除の方法
停止
./crc stop
削除
./crc delete
./crc cleanup
rm -rf ~/.crc
CPUに余裕あるマシンだったら楽しめると思う。自分のMacBook Airだとキツキツ。
なのでvCenterに構築した。