Red Hat OpenShift 4 Developer Preview スタートガイド

Red Hatでソリューションアーキテクトをしている小島です。

赤帽エンジニアAdvent Calendar 2018の23日目の記事です。

2018年12月にOpenShift 4 Developer Previewがリリースされました。本記事ではスタートガイドを紹介します。

Red Hat OpenShift 4 Developer Preview

2015年6月にRed Hat OpenShift 3.0 GA版がリリースされてから3年半の期間をおいて、プレビュー版となるRed Hat OpenShift 4 Developer Previewがリリースされました。OpenShift 3系では最新版の3.11がリリースされるまでに様々な機能拡張が行われてきましたが、OpenShift 4ではさらに大きな変更が加えられる予定です。具体的には次の項目などが挙げられます。*1

  • ベースOSにRed Hat CoreOSを採用
  • デフォルトのコンテナランタイムがDockerからCRI-Oに変更
  • Kubernetes-Nativeのアプリケーション管理ツールであるOperatorの採用
  • スタンドアロンのコンテナレジストリやWebベースのグラフィカルモニタリングツールにRed Hat Quayが利用可能
  • クラスタモニタリングツールがHawkular/Cassandra/HeapsterからPrometheusに変更 (3.11でPrometheusがGA)
  • Webコンソールの刷新 (3.11〜)

これらの変更が加えられたRed Hat OpenShift 4のプレビュー版を、Red Hat Developer Programに登録して無料で試してみることができます。ただし、Red Hatからのサポートは提供されないのでご注意ください。

前準備

Red Hat OpenShift 4(以降OpenShift 4と記載)は、2018年12月時点では次のプラットフォームに対応しています。

本記事ではノートPCなどにあるLibvirt with KVM環境を利用した、OpenShift 4のスタートガイドを紹介していきます。以降の手順はFedora 29+かRHEL 8+の利用を前提とします。*2現時点ではRHEL 7は利用できませんのでご注意ください。Libvirt with KVM環境利用時の、OpenShift 4 クラスター構築時に作成される仮想マシンは次の2台です。*3

  • Master 1台 (デフォルトのリソース割当: vCPU: 2, Memory: 4GB)
    • コントローラ/コンソール/API/etcdなどのPodが動作
  • Worker 1台 (デフォルトのリソース割当: vCPU: 2, Memory: 2GB)
    • ユーザが作成したアプリケーションのPodが動作

この2台の仮想マシンのディスクイメージが消費するストレージ容量は、最低で20GB程となります。また、デフォルトで割り当てられるvCPUとメモリの量についてですが、そのまま利用すると仮想マシンのパワーが足りなくなり、簡単なアプリケーションの作成でも失敗する可能性が高くなります。そのため、後述の手順により、各仮想マシンのリソースを少なくともvCPU: 4, Memory: 8GB程に割り当て直しておくことを推奨します。

上記の仮想マシンを実行可能なノートPCを用意した後は、各種設定を行っていきます。最初に必要となるパッケージをインストールします。仮想化環境の構築に必要となるlibvirt関連のパッケージと、OpenShift 4 インストーラのビルドに利用するgitgolangパッケージをインストールします。なお、FedoraではKubernetesやOpenShiftのクライアントツール一式が入ったorigin-clientsパッケージが用意されているため、こちらもインストールしておきます。

# dnf -y install libvirt virt-manager libvirt-devel libvirt-daemon-kvm qemu-kvm
# dnf -y install git golang origin-clients

仮想マシンへのパケット転送を有効化します。この設定は、libvirtがホスト上に作成して仮想マシンに接続するブリッジデバイスのために利用されます。net.ipv4.ip_forward = 0となっている場合は、sysctlコマンドで有効化します。

# sysctl net.ipv4.ip_forward=1

そしてlibvirtdへのTCP接続を有効化します。この設定は、libvirt環境で作成された仮想マシンの中で動作するKubernetes Cluster APIのために必要となります。Kubernetes Cluster APIは、KubernetesのMaster/Nodeというクラスター構成を宣言的なインフラ構造としてライフサイクルを管理する目的のもとに産まれたオープンソースプロジェクトです。これはlibvirt用にも開発が進められており、今回の環境ではBootstrapのための仮想マシンが最初に作成され、その中でOpenShift 4のクラスター環境を作成するためのCluster APIが呼び出されて仮想マシンの外にあるlibvirtdにアクセスし、クラスターに参加する仮想マシン(ここではWorker)を新規作成するという仕組みになっています。この仕組みを実施するために、non-rootユーザでもlibvirtdにアクセスできるようにするためのルールと、libvirtdにTCPのポート16509番をリッスンさせるための設定を追加します。設定を反映するために、libvirtdサービスの起動(または再起動)と有効化をしておきます。

# cat <<EOF > /etc/polkit-1/rules.d/80-libvirt.rules
polkit.addRule(function(action, subject) {
  if (action.id == "org.libvirt.unix.manage" && subject.local && subject.active && subject.isInGroup("wheel")) {
      return polkit.Result.YES;
  }
});
EOF
# cat <<EOF >> /etc/libvirt/libvirtd.conf
listen_tls = 0
listen_tcp = 1
auth_tcp = "none"
tcp_port = "16509"
EOF
# sed -ie "s/#LIBVIRTD_ARGS="--listen"/LIBVIRTD_ARGS="--listen"/g" /etc/sysconfig/libvirtd
# systemctl restart libvirtd.service; # systemctl enable libvirtd.service

今回の環境で仮想マシンが利用するネットワークは192.168.126.0/24と決め打ちされているため、このネットワークから送信されたパケットがホストのファイアーウォールで弾かれないようにしておきます。より厳密に表現すると、192.168.126.0/24からlibvirtがデフォルトで作成するdefaultのサブネット192.168.124.0/24(Fedoraの場合)への通信を許可する必要があるので、それに対応したファイアーウォールのルールを設定するということになります。なお、検証の利便性を上げたい場合は、適宜永続化(firewalldの場合は--permanetオプションを利用)しておきます。

# firewall-cmd --zone=FedoraWorkstation --add-source=192.168.126.0/24
# firewall-cmd --zone=FedoraWorkstation --list-sources
192.168.126.0/24

今回の環境では、libvirtがデフォルトで定義するdefaultというストレージプールを利用してディスクイメージファイルなどを格納するので、virsh pool-listdefaultが無いことを確認した場合は、次のような手順でdefaultストレージプールを作成しておきます。この手順の例ではホストの/var/lib/libvirt/imagesディレクトリを、ストレージプールのPATHとして設定しています。

# virsh pool-define /dev/stdin <<EOF
<pool type='dir'>
  <name>default</name>
  <target>
    <path>/var/lib/libvirt/images</path>
  </target>
</pool>
EOF
# virsh pool-start default
# virsh pool-autostart default
# virsh pool-list
 Name                 State      Autostart 
-------------------------------------------
 default              active     yes

最後にNetworkManagerの設定変更を行います。OpenShift 4のインストーラがクラスター内ホストの名前解決ができるように、NetworkManagerのdnsmasqプラグインを有効化します。この例ではドメイン名をtt.testing、ネームサーバのIPアドレスを192.168.126.1と指定しています。192.168.126.1は、今回作成するOpenShift 4のクラスターが利用するネットワークのブリッジデバイスに割り当てられるIPアドレスです。また、NetworkManager.conf[main]セクションにdns=dnsmasqを追加することで、ホストが問い合わせるネームサーバがローカルホストになります。これにより、libvirtが仮想マシンの名前解決のために作成したdnsmasqの設定内容をホストとインストーラで利用できるようになります。変更後はNetworkManager.serviceを再起動して設定を反映します。これで一通りの準備は完了です。

# sed -ie "s/\[main\]/\[main\]\\ndns=dnsmasq\\n/g" /etc/NetworkManager/NetworkManager.conf
# echo "server=/tt.testing/192.168.126.1" > /etc/NetworkManager/dnsmasq.d/openshift.conf
# systemctl restart NetworkManager.service

OpenShift 4 クラスターの作成

クラスター作成に必要なインストーラをビルドするために、GitHubにあるOpenShift Installerのリポジトリをクローンします。インストーラをビルドするスクリプトでは、クローンしたリポジトリが$HOME/go/src/github.com/openshiftにあることを要求しているので、mkdirでディレクトリを作成した後にgit cloneでリポジトリをクローンします。そしてインストーラをビルドするスクリプトhack/build.shを実行します。この時TAGS=libvirtを指定することで、インストーラへのlibvirt対応機能を追加しています。無事ビルドに成功すると、インストーラであるbin/openshift-installが作成されます。

# mkdir -p /root/go/src/github.com/openshift/; cd /root/go/src/github.com/openshift/
# git clone https://github.com/openshift/installer.git
# TAGS=libvirt /root/go/src/github.com/openshift/installer/hack/build.sh 
...<snip>...
+ go build -ldflags ' -X main.version=v0.7.0-master-69-gc0104bd60f6a9502a86fdd8ecc210ee11028cf3f' -tags 'libvirt release' -o bin/openshift-install ./cmd/openshift-install
# ls /root/go/src/github.com/openshift/installer/bin/
openshift-install

上記で省略したインストーラビルド時の標準出力

# TAGS=libvirt /root/go/src/github.com/openshift/installer/hack/build.sh 
+ minimum_go_version=1.10
++ go version
++ cut -d ' ' -f 3
+ current_go_version=go1.11.2
++ version 1.11.2
++ IFS=.
++ printf '%03d%03d%03d\n' 1 11 2
++ unset IFS
++ version 1.10
++ IFS=.
++ printf '%03d%03d%03d\n' 1 10
++ unset IFS
+ '[' 001011002 -lt 001010000 ']'
+ LAUNCH_PATH=/root/go/src/github.com/openshift/installer
++ dirname ./hack/build.sh
+ cd ./hack/..
++ go list -e -f '{{.Dir}}' github.com/openshift/installer
+ PACKAGE_PATH=/root/go/src/github.com/openshift/installer
+ test -z /root/go/src/github.com/openshift/installer
+ LOCAL_PATH=/root/go/src/github.com/openshift/installer
+ test /root/go/src/github.com/openshift/installer '!=' /root/go/src/github.com/openshift/installer
+ MODE=release
++ git describe --always --abbrev=40 --dirty
+ LDFLAGS=' -X main.version=v0.7.0-master-69-gc0104bd60f6a9502a86fdd8ecc210ee11028cf3f'
+ TAGS=libvirt
+ OUTPUT=bin/openshift-install
+ export CGO_ENABLED=0
+ CGO_ENABLED=0
+ case "${MODE}" in
+ TAGS='libvirt release'
+ test -n ''
+ test -n ''
+ test '' '!=' y
+ go generate ./data
writing assets_vfsdata.go
+ echo 'libvirt release'
+ grep -q libvirt
+ export CGO_ENABLED=1
+ CGO_ENABLED=1
+ go build -ldflags ' -X main.version=v0.7.0-master-69-gc0104bd60f6a9502a86fdd8ecc210ee11028cf3f' -tags 'libvirt release' -o bin/openshift-install ./cmd/openshift-install

インストーラでクラスターを作成する時、SSHの秘密鍵、プロバイダ情報、libvirtdに接続するためのURI、OpenShift 4のクラスターが利用するドメイン名とクラスターの名前、仮想マシンのベースイメージを取得するためのPull Secret(try.openshift.comで入手可能)の入力が求められます。これらの情報を毎回入力しなくてもいいように、openshift-install create install-configinstall-config.yamlに保存しておき、次回以降のインストール時に使い回せるようにしておきます。このファイルの保存先のディレクトリPATHは--dirで指定できます。SSHの秘密鍵は指定しなくてもいいですが、指定しておくとOpenShift 4のクラスターとして作成されるCoreOSの仮想マシンにログインできるようになります。

# ssh-keygen -f /root/.ssh/id_rsa -N ''
# ./bin/openshift-install create install-config --dir=demotest
? SSH Public Key /root/.ssh/id_rsa.pub
? Platform libvirt
? Libvirt Connection URI qemu+tcp://192.168.124.1/system  <- "virbr0"デバイスのIPアドレスを指定
? Base Domain tt.testing
? Cluster Name ocp4
? Pull Secret [? for help] **********
# ls ./demotest
install-config.yaml
# cp -r demotest /root/  <- "demotest"ディレクトリを適当な場所にコピー


install-config.yamlの中身はこちらです。↓

baseDomain: tt.testing
clusterID: e9b520cc-d63d-4716-a98e-a897b076d773
machines:
- name: master
  platform: {}
  replicas: 1
- name: worker
  platform: {}
  replicas: 1
metadata:
  creationTimestamp: null
  name: ocp4
networking:
  clusterNetworks:
  - cidr: 10.128.0.0/14
    hostSubnetLength: 9
  serviceCIDR: 172.30.0.0/16
  type: OpenshiftSDN
platform:
  libvirt:
    URI: qemu+tcp://192.168.124.1/system
    defaultMachinePlatform:
      image: https://releases-rhcos.svc.ci.openshift.org/storage/releases/maipo/47.235/redhat-coreos-maipo-47.235-qemu.qcow2.gz
    network:
      if: tt0
      ipRange: 192.168.126.0/24
pullSecret:  '{"auths":{"cloud.openshift.com":{"auth":"xxxxxxxxxx","email":"xxxxx@redhat.com"},"quay.io":{"auth":"xxxxxxxxxx","email":"xxxxx@redhat.com"}}}'
sshKey: |
  ssh-rsa xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx root@redhat.com


あとはopenshift-install create clusterを実行して、クラスターを作成します。--dir=demotestオプションでdemotestディレクトリ内にあるinstall-config.yamlの情報を利用するのと同時に、インストール時に指定する変数情報やログもdemotestディレクトリに保存されるようになります。また、--log-level=debugオプションでdebugレベルのログを出力することで、Terraformベースのインストーラが今何を実行しているかを確認できるようになります。

# /root/go/src/github.com/openshift/installer/bin/openshift-install create cluster --dir=demotest --log-level=debug
time="2018-12-23T13:33:23+09:00" level=debug msg="Fetching \"Terraform Variables\"..."
time="2018-12-23T13:33:23+09:00" level=debug msg="Loading \"Terraform Variables\"..."
time="2018-12-23T13:33:23+09:00" level=debug msg="  Loading \"Install Config\"..."
time="2018-12-23T13:33:23+09:00" level=debug msg="    Loading \"Cluster ID\"..."
time="2018-12-23T13:33:23+09:00" level=debug msg="    Loading \"SSH Key\"..."
time="2018-12-23T13:33:23+09:00" level=debug msg="    Loading \"Base Domain\"..."
time="2018-12-23T13:33:23+09:00" level=debug msg="      Loading \"Platform\"..."
time="2018-12-23T13:33:23+09:00" level=debug msg="    Loading \"Cluster Name\"..."
time="2018-12-23T13:33:23+09:00" level=debug msg="    Loading \"Pull Secret\"..."
time="2018-12-23T13:33:23+09:00" level=debug msg="    Loading \"Platform\"..."
time="2018-12-23T13:33:23+09:00" level=debug msg="  Using \"Install Config\" loaded from target directory"
time="2018-12-23T13:33:23+09:00" level=debug msg="  Loading \"Bootstrap Ignition Config\"..."
time="2018-12-23T13:33:23+09:00" level=debug msg="    Loading \"Install Config\"..."
...<snip>...
INFO Install complete!                            
INFO Run 'export KUBECONFIG=/root/go/src/github.com/openshift/installer/demotest/auth/kubeconfig' to manage the cluster with 'oc', the OpenShift CLI. 
INFO The cluster is ready when 'oc login -u kubeadmin -p xxxxx-xxxxx-xxxxx-xxxxx' succeeds (wait a few minutes). 
INFO Access the OpenShift web-console here: https://console-openshift-console.apps.ocp4.tt.testing 
INFO Login to the console with user: kubeadmin, password: xxxxx-xxxxx-xxxxx-xxxxx

クラスターの作成が途中で失敗した場合は、キャッシュファイルなどが保存されているディレクトリを削除した後に再実行してみてください。

# cd /root/go/src/github.com/openshift/installer/
# rm -rf ./demotest
# cp -r /root/demotest ./  <- 事前に保存しておいた"demotest"ディレクトリをコピー
# ./bin/openshift-install create cluster --dir=demotest --log-level=debug

OpenShift 4 クラスターへのアクセス

作成されたクラスターには、ocコマンドやWebブラウザでアクセスできます。アクセスするための情報は、前述のクラスター作成終了時に出力されたメッセージに記載されています。クラスター作成完了時には、クラスター内で動作するPodの一覧を下記のような出力で確認できます。大体下記の出力のようになっていてPodが正常に動作していることを確認できたら、一度仮想マシンをシャットダウンして、virt-managerやvirshで仮想マシンへのvCPU/メモリの割り当てを増やしてください。この例では、vCPU: 4, Memory: 8GBの割り当てに変更しています。

Podの一覧表示↓

# export KUBECONFIG=/root/go/src/github.com/openshift/installer/demotest/auth/kubeconfig
# oc get pods --all-namespaces -o wide
NAMESPACE                                                 NAME                                                              READY     STATUS      RESTARTS   AGE       IP               NODE                  NOMINATED NODE
kube-system                                               etcd-member-ocp4-master-0                                         1/1       Running     1          3h        192.168.126.11   ocp4-master-0         <none>
openshift-apiserver                                       apiserver-2fmkg                                                   1/1       Running     2          1h        10.128.0.97      ocp4-master-0         <none>
openshift-cluster-api                                     cluster-autoscaler-operator-ffff9c548-8kwvz                       1/1       Running     5          3h        10.128.0.80      ocp4-master-0         <none>
openshift-cluster-api                                     clusterapi-manager-controllers-7b9b98b888-t676g                   4/4       Running     7          3h        10.128.0.74      ocp4-master-0         <none>
openshift-cluster-api                                     machine-api-operator-ff646678f-p9zcp                              1/1       Running     2          3h        10.128.0.91      ocp4-master-0         <none>
openshift-cluster-kube-apiserver-operator                 openshift-cluster-kube-apiserver-operator-66c6f6c96f-z4m7f        1/1       Running     5          3h        10.128.0.77      ocp4-master-0         <none>
openshift-cluster-kube-controller-manager-operator        openshift-cluster-kube-controller-manager-operator-7cd59cfrmbns   1/1       Running     6          3h        10.128.0.67      ocp4-master-0         <none>
openshift-cluster-kube-scheduler-operator                 openshift-cluster-kube-scheduler-operator-58c479c58-stfcg         1/1       Running     5          3h        10.128.0.70      ocp4-master-0         <none>
openshift-cluster-machine-approver                        machine-approver-66944cf897-28kj2                                 1/1       Running     1          3h        192.168.126.11   ocp4-master-0         <none>
openshift-cluster-network-operator                        cluster-network-operator-lm7tx                                    1/1       Running     1          3h        192.168.126.11   ocp4-master-0         <none>
openshift-cluster-node-tuning-operator                    cluster-node-tuning-operator-6d7dc8b65f-l87c9                     1/1       Running     4          3h        10.128.0.88      ocp4-master-0         <none>
openshift-cluster-node-tuning-operator                    tuned-6rmm4                                                       1/1       Running     7          3h        192.168.126.11   ocp4-master-0         <none>
openshift-cluster-node-tuning-operator                    tuned-nvwx7                                                       1/1       Running     7          3h        192.168.126.51   ocp4-worker-0-h698z   <none>
openshift-cluster-openshift-apiserver-operator            openshift-cluster-openshift-apiserver-operator-bb9f88b94-xppbx    1/1       Running     9          3h        10.128.0.68      ocp4-master-0         <none>
openshift-cluster-openshift-controller-manager-operator   openshift-cluster-openshift-controller-manager-operator-86mf7m6   1/1       Running     4          3h        10.128.0.69      ocp4-master-0         <none>
openshift-cluster-samples-operator                        cluster-samples-operator-c94f564cb-kct9f                          1/1       Running     7          3h        10.128.0.90      ocp4-master-0         <none>
openshift-cluster-storage-operator                        cluster-storage-operator-664f8cd9cd-22grt                         1/1       Running     2          3h        10.128.0.83      ocp4-master-0         <none>
openshift-cluster-version                                 cluster-version-operator-86bcc6d5-9kg2m                           1/1       Running     1          3h        192.168.126.11   ocp4-master-0         <none>
openshift-console                                         console-operator-7bdb6784bb-dhqfl                                 1/1       Running     3          3h        10.128.0.89      ocp4-master-0         <none>
openshift-console                                         openshift-console-6b7776df7-cbct5                                 1/1       Running     1          3h        10.128.0.100     ocp4-master-0         <none>
openshift-console                                         openshift-console-6b7776df7-kd986                                 1/1       Running     1          3h        10.128.0.95      ocp4-master-0         <none>
openshift-console                                         openshift-console-6b7776df7-vmsf9                                 1/1       Running     2          3h        10.128.0.96      ocp4-master-0         <none>
openshift-controller-manager                              controller-manager-mqs4w                                          1/1       Running     3          1h        10.128.0.94      ocp4-master-0         <none>
openshift-core-operators                                  openshift-service-cert-signer-operator-df8478fbb-9rkdj            1/1       Running     4          3h        10.128.0.78      ocp4-master-0         <none>
openshift-core-operators                                  origin-cluster-osin-operator-655447bd7d-shk8h                     1/1       Running     4          3h        10.128.0.75      ocp4-master-0         <none>
openshift-core-operators                                  origin-cluster-osin-operator2-656d84cb7-7bqkh                     1/1       Running     5          3h        10.128.0.86      ocp4-master-0         <none>
openshift-csi-operator                                    csi-operator-fc648d7c-78hks                                       1/1       Running     7          3h        10.128.0.101     ocp4-master-0         <none>
openshift-dns-operator                                    dns-operator-86cd9b6f6b-7pnl8                                     1/1       Running     2          3h        10.128.0.73      ocp4-master-0         <none>
openshift-dns                                             dns-default-2z4zp                                                 2/2       Running     2          3h        10.129.0.20      ocp4-worker-0-h698z   <none>
openshift-dns                                             dns-default-wqhfr                                                 2/2       Running     2          3h        10.128.0.66      ocp4-master-0         <none>
openshift-image-registry                                  cluster-image-registry-operator-5b8d84bf6b-kfv55                  1/1       Running     4          3h        10.128.0.76      ocp4-master-0         <none>
openshift-image-registry                                  image-registry-846c697c7-5lpjg                                    1/1       Running     1          3h        10.128.0.87      ocp4-master-0         <none>
openshift-image-registry                                  registry-ca-hostmapper-ntlj8                                      1/1       Running     2          3h        10.128.0.107     ocp4-master-0         <none>
openshift-image-registry                                  registry-ca-hostmapper-xj7rk                                      1/1       Running     1          3h        10.129.0.12      ocp4-worker-0-h698z   <none>
openshift-ingress-operator                                ingress-operator-65446d5bd4-95dnb                                 1/1       Running     2          3h        10.128.0.104     ocp4-master-0         <none>
openshift-ingress                                         router-default-5f66c8cd9c-fj8sd                                   1/1       Running     1          3h        10.129.0.14      ocp4-worker-0-h698z   <none>
openshift-kube-apiserver                                  installer-1-ocp4-master-0                                         0/1       Completed   0          3h        10.128.0.25      ocp4-master-0         <none>
openshift-kube-apiserver                                  installer-2-ocp4-master-0                                         0/1       Completed   0          3h        10.128.0.29      ocp4-master-0         <none>
openshift-kube-apiserver                                  installer-3-ocp4-master-0                                         0/1       Completed   0          3h        10.128.0.48      ocp4-master-0         <none>
openshift-kube-apiserver                                  openshift-kube-apiserver-ocp4-master-0                            1/1       Running     4          3h        192.168.126.11   ocp4-master-0         <none>
openshift-kube-controller-manager                         installer-1-ocp4-master-0                                         0/1       Completed   0          3h        10.128.0.22      ocp4-master-0         <none>
openshift-kube-controller-manager                         installer-2-ocp4-master-0                                         0/1       Completed   0          3h        10.128.0.26      ocp4-master-0         <none>
openshift-kube-controller-manager                         openshift-kube-controller-manager-ocp4-master-0                   1/1       Running     4          3h        192.168.126.11   ocp4-master-0         <none>
openshift-kube-scheduler                                  installer-1-ocp4-master-0                                         0/1       OOMKilled   0          3h        10.128.0.14      ocp4-master-0         <none>
openshift-kube-scheduler                                  openshift-kube-scheduler-ocp4-master-0                            1/1       Running     2          3h        192.168.126.11   ocp4-master-0         <none>
openshift-machine-config-operator                         machine-config-controller-64d79bff84-54cbz                        1/1       Running     3          3h        10.128.0.112     ocp4-master-0         <none>
openshift-machine-config-operator                         machine-config-daemon-74dl9                                       1/1       Running     2          3h        192.168.126.11   ocp4-master-0         <none>
openshift-machine-config-operator                         machine-config-daemon-gqjfp                                       1/1       Running     4          3h        192.168.126.51   ocp4-worker-0-h698z   <none>
openshift-machine-config-operator                         machine-config-operator-7b4c89cc8f-8tnmt                          1/1       Running     1          3h        10.128.0.79      ocp4-master-0         <none>
openshift-machine-config-operator                         machine-config-server-bqs5m                                       1/1       Running     1          3h        192.168.126.11   ocp4-master-0         <none>
openshift-monitoring                                      alertmanager-main-0                                               3/3       Running     4          2h        10.128.0.98      ocp4-master-0         <none>
openshift-monitoring                                      alertmanager-main-1                                               3/3       Running     3          2h        10.129.0.16      ocp4-worker-0-h698z   <none>
openshift-monitoring                                      alertmanager-main-2                                               3/3       Running     3          2h        10.129.0.15      ocp4-worker-0-h698z   <none>
openshift-monitoring                                      cluster-monitoring-operator-6f47f6864c-v96ch                      1/1       Running     1          3h        10.128.0.111     ocp4-master-0         <none>
openshift-monitoring                                      grafana-58456d859d-zl5w5                                          2/2       Running     2          3h        10.129.0.13      ocp4-worker-0-h698z   <none>
openshift-monitoring                                      kube-state-metrics-dcf7dc56d-t2wq4                                3/3       Running     3          2h        10.129.0.18      ocp4-worker-0-h698z   <none>
openshift-monitoring                                      node-exporter-cf9t6                                               2/2       Running     2          2h        192.168.126.11   ocp4-master-0         <none>
openshift-monitoring                                      node-exporter-pf5mn                                               2/2       Running     2          2h        192.168.126.51   ocp4-worker-0-h698z   <none>
openshift-monitoring                                      prometheus-adapter-7fb498bdc-dkz96                                1/1       Running     2          2h        10.128.0.105     ocp4-master-0         <none>
openshift-monitoring                                      prometheus-k8s-0                                                  6/6       Running     7          2h        10.128.0.116     ocp4-master-0         <none>
openshift-monitoring                                      prometheus-k8s-1                                                  6/6       Running     7          2h        10.129.0.17      ocp4-worker-0-h698z   <none>
openshift-monitoring                                      prometheus-operator-7b5b4b567b-b6lvj                              1/1       Running     3          3h        10.128.0.117     ocp4-master-0         <none>
openshift-monitoring                                      telemeter-client-747b776f55-g6nsv                                 3/3       Running     3          2h        10.129.0.19      ocp4-worker-0-h698z   <none>
openshift-operator-lifecycle-manager                      catalog-operator-6bc4b75467-ghqvf                                 1/1       Running     6          3h        10.128.0.108     ocp4-master-0         <none>
openshift-operator-lifecycle-manager                      certified-operators-5xmp8                                         1/1       Running     2          3h        10.128.0.109     ocp4-master-0         <none>
openshift-operator-lifecycle-manager                      olm-operator-6ccd67d5d4-k26mx                                     1/1       Running     2          3h        10.128.0.106     ocp4-master-0         <none>
openshift-operator-lifecycle-manager                      olm-operators-fqc87                                               1/1       Running     2          3h        10.128.0.81      ocp4-master-0         <none>
openshift-operator-lifecycle-manager                      packageserver-584dcb6cb5-4hqkt                                    1/1       Running     8          57m       10.128.0.103     ocp4-master-0         <none>
openshift-operator-lifecycle-manager                      rh-operators-w7hgt                                                1/1       Running     1          3h        10.128.0.115     ocp4-master-0         <none>
openshift-sdn                                             ovs-5g44k                                                         1/1       Running     1          3h        192.168.126.51   ocp4-worker-0-h698z   <none>
openshift-sdn                                             ovs-bk8b8                                                         1/1       Running     1          3h        192.168.126.11   ocp4-master-0         <none>
openshift-sdn                                             sdn-controller-njvr6                                              1/1       Running     2          3h        192.168.126.11   ocp4-master-0         <none>
openshift-sdn                                             sdn-hbpct                                                         1/1       Running     1          3h        192.168.126.51   ocp4-worker-0-h698z   <none>
openshift-sdn                                             sdn-ndfvv                                                         1/1       Running     1          3h        192.168.126.11   ocp4-master-0         <none>
openshift-service-cert-signer                             apiservice-cabundle-injector-6898b7b75c-klw7l                     1/1       Running     5          3h        10.128.0.110     ocp4-master-0         <none>
openshift-service-cert-signer                             configmap-cabundle-injector-5d4d7784d8-ndstb                      1/1       Running     5          3h        10.128.0.114     ocp4-master-0         <none>
openshift-service-cert-signer                             service-serving-cert-signer-845848c4c5-98scz                      1/1       Running     5          3h        10.128.0.113     ocp4-master-0         <none>


仮想マシンのvCPUとメモリの割り当て変更↓

# virsh list
 Id   Name                  State    
-------------------------------------
 19   ocp4-master-0         running  
 20   ocp4-worker-0-xxxxx   running
# virsh shutdown ocp4-master-0; virsh shutdown ocp4-worker-0-xxxxx
# virsh setvcpus <master,workerの名前> 4 --maximum --config
# virsh setvcpus <master,workerの名前> 4 --config
# virsh setmaxmem <master,workerの名前> 8G
# virsh setmem <master,workerの名前> 8G --config
# virsh start ocp4-master-0; virsh start ocp4-worker-0-xxxxx


設定変更が終了して仮想マシンを再起動した後は、Webコンソールにアクセスしてみます。oc port-forwardでローカルホストのTCP 80番と443番ポートへのアクセスを、OpenShift 4 クラスターで動作するrouter-defaultServiceにポートフォワーディングするようにします。

# export KUBECONFIG=/root/go/src/github.com/openshift/installer/demotest/auth/kubeconfig
# oc port-forward service/router-default 80 443 -n openshift-ingress
Forwarding from 127.0.0.1:80 -> 80
Forwarding from [::1]:80 -> 80
Forwarding from 127.0.0.1:443 -> 443
Forwarding from [::1]:443 -> 443

ポートフォワーディングを設定した後は、別の端末を開いてDNSのワイルドカードを利用できるように設定します。作成したOpenShift 4 クラスターで作成するアプリケーションのRouteで利用されるサブドメインはapps.<Cluster Name>.<Cluster Base Domain Name>となるので、今回の例ではxxx.apps.ocp4.tt.testing127.0.0.1として名前解決できるような設定を追加します。設定追加後はNetworkManager.serviceを再起動して、変更した設定内容を反映し、名前解決ができるようになっていることを確認します。

# echo "address=/apps.ocp4.tt.testing/127.0.0.1" >> /etc/NetworkManager/dnsmasq.d/openshift.conf
# systemctl restart NetworkManager.service
# host xxx.apps.ocp4.tt.testing
xxx.apps.ocp4.tt.testing has address 127.0.0.1

これでインストール終了時に表示されたURLにアクセスできるようになります。適当なWebブラウザでhttps://console-openshift-console.apps.ocp4.tt.testingにアクセスし、kubeadminユーザでログインすると、次のような画面が表示されます。この画面ではクラスターにあるProjectの一覧が表示されています。

f:id:h-kojima:20181223172223p:plain
ログイン後のトップページ

このWebコンソールからプロジェクトの作成や、デフォルトで用意されているDeveloper Catalogを利用したアプリケーションの作成ができます。OpenShift 4はアップストリームのOKDプロジェクトベースで開発されているので、今利用できるカタログはコミュニティベースのものだけとなります。

f:id:h-kojima:20181223151212p:plain
Developer Catalog

ちなみに、クラスター作成時にSSHの秘密鍵を指定しておくと、ssh -l core ocp4-master-0.<Cluster Base Domain Name>ssh -l core ocp-woker-0-xxxxx.<Cluster Base Domain Name>で仮想マシンに直接ログインできるようになります。sudo su -でrootユーザにもなれるので、クラスター内部の詳細な情報を確認できます。

# ssh -l core ocp4-master-0.tt.testing
Red Hat CoreOS 4.0
 Information: https://url.corp.redhat.com/redhat-coreos
 Bugs: https://github.com/openshift/os

---
[core@ocp4-master-0 ~]$ sudo su -
[root@ocp4-master-0 ~]# 

クリーンアップ

作成したクラスターを削除する場合は、openshift-install destroy clusterを実行します。クラスター作成時に--dirで指定していたディレクトリのPATHを、クリーンアップの時にも指定しておく必要があります。あとは必要に応じて、github.com/openshift/installerのローカルリポジトリ、キャッシュファイル、変更したNetworkManager/libvirt/firewalldの設定ファイルの削除とサービスの再起動を行います。

# /root/go/src/github.com/openshift/installer/bin/openshift-install destroy cluster --dir demotest
INFO Deleted domain                                domain=ocp4-bootstrap
INFO Deleted domain                                domain=ocp4-master-0
INFO Deleted network                               network=ocp4
INFO Deleted volume                                volume=ocp4-master-0
INFO Deleted volume                                volume=ocp4-bootstrap.ign
INFO Deleted volume                                volume=ocp4-base
INFO Deleted volume                                volume=ocp4-bootstrap
INFO Deleted volume                                volume=ocp4-master.ign
# rm -rf /root/go/src/github.com/openshift/installer
# rm -rf /root/.cache/{openshift-install,go-build}
# rm -rf /etc/NetworkManager/openshift.conf; systemctl restart NetworkManager.service
# systemctl restart libvirtd.service   <- 前述のlibvirtの設定変更を削除した後に実行
# firewall-cmd --reload

References

本記事の内容に合わせて、インストーラの概要説明やトラブルシューティングガイドも記載しているので参考にしてください。

github.com

追記

2019年6月にOpenShift 4の正式版がリリースされました。こちらのインストールガイドが最新のものとなります。

rheb.hatenablog.com

rheb.hatenablog.com

rheb.hatenablog.com

*1:詳細はRed Hat OpenShift Container Platform3.11のリリースノートに記載しています。

*2:筆者はFedoraが入ったノートPCを業務に利用しており、本記事で紹介する手順もFedora 29 Workstationで実施しています。

*3:AWSに作成する場合のデフォルトの台数は、Master 3台/Worker 3台の6台になります。AWSを利用する場合はCoreOS AMIが用意されているリージョン(us-east-1など)の選択、Route53などによるPublic DNSの設定、パブリックIPアドレスとなるEIPを最低6つ確保、などを行う必要があります。

* 各記事は著者の見解によるものでありその所属組織を代表する公式なものではありません。その内容については非公式見解を含みます。