OpenShiftインストール

ここでは、Red HatのOpenShift(OSSのOpenShift Originではなく)をインストールして一先ず動く評価環境を作ってみます。
ライセンスは30日の評価版を使います。

必要な事前作業

  • Red Hatのアカウントを作成

OpenShiftの必要要件

docs.openshift.comSystem and Environment Requirements | Installing Clusters | OpenShift Container Platform 3.10

作業概要

  • OpenShiftの評価版登録
  • Red Hatのコンテナイメージを使うため registry.redhat.io のアカウント作成
  • OpenShiftのインストール

環境

ここでは、試しに動かす環境を作ってみるので master node infra を1台ずつ用意しています。

項目内容
OSRHEL7.6
OpenShift3.11

ホスト名は以下の通りです。

ホスト名
master.local
node01.local
infra01.local

DNSレコード

DNS(bind)のコレードは以下の通りです。
ドメインは local を使います。
openshift_master_default_subdomain は設定しないのでデフォルトのドメインを設定しています。

1234567[root@localhost named]# vi local.db(snip)master  IN  A   192.168.0.30node01  IN  A   192.168.0.31infra01 IN  A   192.168.0.32*.router.default.svc.cluster    IN  A   192.168.0.30 

OpenShift評価登録

ログイン

カスタマーポータルからログインします。

評価登録

ダウンロード をクリックします。

Red Hat OpenShift Container Platform の 評価をリクエスト をクリックします。

次に進む をクリックします。

AGREE AND GET STARTED をクリックします。

アクティブなサブスクリプション に表示されていることを確認します。

レジストリアカウント登録

Red Hat Container Catalog へアクセスし Service Accounts をクリックします。

New Service Account をクリックします。

Name にアカウント名を入力して CREATE をクリックします。

以下のコマンドを実行して認証が通りTokenが発行されるか確認します。

12[root@localhost ~]# curl -Lv -u <username>:<password> “https://sso.redhat.com/auth/realms/rhcc/protocol/redhat-docker-v2/auth?service=docker-registry&client_id=curl&scope=repository:rhel:pull” 
項目説明
usernameレジストリアカウント登録したユーザー
passwordRed Hatに登録したユーザーのパスワード

access.redhat.comTroubleshooting Authentication Issues with registry.redhat.io – Red Hat Customer Portal

OpenShiftインストール

Red Hatの手順書にあることをやっていきます。access.redhat.com第2章 OpenShift Container Platform のインストール – Red Hat Customer Portal

OS作業

master node01 infra01 で以下の作業を実施します。

サブスクリプションのアタッチ

まずは register でシステムを登録します。

1234567[root@master ~]# subscription-manager register登録中: subscription.rhsm.redhat.com:443/subscriptionユーザー名: ***********パスワード:このシステムは、次の ID で登録されました: ***************登録したシステム名: master.local 

最新のサブスクリプションテーブルをプルします。

123[root@master ~]# subscription-manager refreshローカルデータがすべて更新されました 

先ほど登録した評価版OpenShiftサブスクリプションの プール ID を確認します。

1234567[root@master ~]# subscription-manager list –available(snip)サブスクリプション名:     30 Day Self-Supported Red Hat OpenShift Container Platform, 2-Core Evaluation(snip)プール ID:                ********************(snip) 

確認したプール IDにアタッチします。

123[root@master ~]# subscription-manager attach –pool=***************サブスクリプションが正しく割り当てられました: 30 Day Self-Supported Red Hat OpenShift Container Platform, 2-Core Evaluation 

リポジトリーの有効化

以下のコマンドを実行してリポジトリを有効化します。

123456789[root@master ~]# subscription-manager repos –enable=”rhel-7-server-rpms” \>     –enable=”rhel-7-server-extras-rpms” \>     –enable=”rhel-7-server-ose-3.11-rpms” \>     –enable=”rhel-7-server-ansible-2.6-rpms”リポジトリー ‘rhel-7-server-rpms’ は、このシステムに対して有効になりました。リポジトリー ‘rhel-7-server-extras-rpms’ は、このシステムに対して有効になりました。リポジトリー ‘rhel-7-server-ansible-2.6-rpms’ は、このシステムに対して有効になりました。リポジトリー ‘rhel-7-server-ose-3.11-rpms’ は、このシステムに対して有効になりました。 

アップデート

必要であれば全ホストで yum update を実行して最新版にしておきます。

OpenShift Container Platformパッケージのインストール

master で以下の作業を実施します。

必要なパッケージのインストールおよびアップデート

必要なパッケージのインストールをします。

12[root@master ~]# yum -y install wget git net-tools bind-utils iptables-services bridge-utils bash-completion kexec-tools sos psacct 

最新版にアップデートして再起動します。

123[root@master ~]# yum -y update[root@master ~]# reboot 

OpenShiftはAnsibleでインストールするので openshift-ansible をインストールします。

12[root@master ~]# yum -y install openshift-ansible 

コンテナーエンジンのインストール

ここでは Docker を使おうと思うので docker をインストールします。

12[root@master ~]# yum -y install docker 

SSHのキー作成

パスワードなしでログインできるようSSHのキーを作成します。

1234567891011121314151617181920212223[root@master ~]# ssh-keygenGenerating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa):Created directory ‘/root/.ssh’.Enter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in /root/.ssh/id_rsa.Your public key has been saved in /root/.ssh/id_rsa.pub.The key fingerprint is:SHA256:tq94jFyMCPk8bmC8vemq9VEHjucfKYzFPpuouG0+0T8 root@master.localThe key’s randomart image is:+—[RSA 2048]—-+|                 ||                 ||   .  .          ||  o  + .         || . =..*oS        ||  = *O.ooo       || ..*o+*++        || ++.++EBoo       ||+==**.+oo..      |+—-[SHA256]—–+ 

全ホストに公開鍵を配ります。

123456for host in master.local \    node01.local \    infra01.local; \    do ssh-copy-id -i ~/.ssh/id_rsa.pub $host; \    done 

OpenShiftインストールPlaybook実行

インベントリ作成

以下のようにインベントリを作成します。
ここでは master と infra を分けていますが master+infra にする場合は node-config-master-infra を指定します。

12345678910111213141516171819202122232425262728[root@master ~]# vi /etc/ansible/hosts[OSEv3:children]mastersnodesetcd [OSEv3:vars]ansible_ssh_user=rootopenshift_deployment_type=openshift-enterprise # htpasswdでユーザーを追加できるようにするopenshift_master_identity_providers=[{‘name’: ‘htpasswd_auth’, ‘login’: ‘true’, ‘challenge’: ‘true’, ‘kind’: ‘HTPasswdPasswordIdentityProvider’}] # registry.redhat.ioのアカウントoreg_auth_user=usernameoreg_auth_password=password [masters]master.local [etcd]master.local [nodes]master.local openshift_node_group_name=’node-config-master’node01.local openshift_node_group_name=’node-config-compute’infra01.local openshift_node_group_name=’node-config-infra’ 

インベントリ例は以下を参照ください。docs.openshift.comExample Inventory Files | Installing Clusters | OpenShift Container Platform 3.10

インベントリの変数説明は以下を参照ください。access.redhat.comInstalling Clusters – Red Hat Customer Portal

Playbook実行

まずは prerequisites.yml を実行します。

1234567891011121314[root@master ~]# cd /usr/share/ansible/openshift-ansible[root@master openshift-ansible]# ansible-playbook playbooks/prerequisites.yml(snip)PLAY RECAP *****************************************************************************************************************************************************************************************************infra01.local              : ok=48   changed=21   unreachable=0    failed=0localhost                  : ok=11   changed=0    unreachable=0    failed=0master.local               : ok=69   changed=21   unreachable=0    failed=0node01.local               : ok=48   changed=21   unreachable=0    failed=0  INSTALLER STATUS ***********************************************************************************************************************************************************************************************Initialization  : Complete (0:03:52)Sunday 24 February 2019  15:43:30 +0900 (0:00:00.119)       0:12:23.538 ******* 

次に deploy_cluster.yml を実行します。

12345678910111213141516171819202122232425[root@master openshift-ansible]# ansible-playbook playbooks/deploy_cluster.yml(snip)PLAY RECAP *****************************************************************************************************************************************************************************************************infra01.local              : ok=111  changed=63   unreachable=0    failed=0localhost                  : ok=11   changed=0    unreachable=0    failed=0master.local               : ok=684  changed=324  unreachable=0    failed=0node01.local               : ok=111  changed=63   unreachable=0    failed=0  INSTALLER STATUS ***********************************************************************************************************************************************************************************************Initialization               : Complete (0:00:26)Health Check                 : Complete (0:00:49)Node Bootstrap Preparation   : Complete (0:18:00)etcd Install                 : Complete (0:02:50)Master Install               : Complete (0:06:23)Master Additional Install    : Complete (0:06:57)Node Join                    : Complete (0:00:24)Hosted Install               : Complete (0:00:47)Cluster Monitoring Operator  : Complete (0:01:14)Web Console Install          : Complete (0:00:30)Console Install              : Complete (0:00:17)metrics-server Install       : Complete (0:00:00)Service Catalog Install      : Complete (0:03:44)Sunday 24 February 2019  16:27:50 +0900 (0:00:00.048)       0:42:50.852 ******* 

状態確認

標準の system:admin でログインして状態を確認してみます。

1234567[root@master ~]# oc login -u system:admin[root@master ~]# oc get nodesNAME            STATUS    ROLES     AGE       VERSIONinfra01.local   Ready     infra     9m        v1.11.0+d4cacc0master.local    Ready     master    19m       v1.11.0+d4cacc0node01.local    Ready     compute   9m        v1.11.0+d4cacc0 

ユーザー追加

adminユーザーを追加してみます。

123[root@master ~]# htpasswd -b /etc/origin/master/htpasswd admin redhatAdding password for user admin 

OpenShiftを再起動します。

12345[root@master ~]# master-restart api2[root@master ~]# master-restart controllers2 

作成したadminに特権ロールを設定します。

1234[root@master ~]# oc adm policy add-cluster-role-to-user cluster-admin adminWarning: User ‘admin’ not foundcluster role “cluster-admin” added: “admin” 

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

1234567[root@master ~]# oc login -u adminAuthentication required for https://master.local:8443 (openshift)Username: adminPassword:Login successful.(snip) 

OpenShiftルーターのデプロイ

デフォルトルーターを削除して新規に作成します。

12345678910111213141516[root@master ~]# oc project defaultAlready on project “default” on server “https://master.local:8443”.[root@master ~]# oc delete all -l router=routerpod “router-1-cdgnr” deletedreplicationcontroller “router-1” deletedservice “router” deleteddeploymentconfig.apps.openshift.io “router” deleted[root@master ~]# oc adm router –replicas=1 –service-account=routerinfo: password for stats user admin has been set to r2nm8SJdvY–> Creating router router …    warning: serviceaccounts “router” already exists    warning: clusterrolebindings.authorization.openshift.io “router-router-role” already exists    deploymentconfig.apps.openshift.io “router” created    service “router” created–> Success 

WebUIアクセス

以下のURLでアクセスします。

URL
https://master.local:8443

adminユーザーでログインします。

ログインできることを確認します。