LoginSignup
6
1

More than 1 year has passed since last update.

OpenShift v4.9をAWSへIPIインストールしてみた

Last updated at Posted at 2021-12-10

 はじめに

みなさん、こんにちは。
本記事では、IPI(Installer-Provisioned Infrastructure)を使って、AWS上へRed Hat® OpenShift® Container Platform v4.9のクラスタを構築します。

実は個人的に5年くらい前に現OpenShiftのコミュニティ版OKDの前身のoriginを触ったことがあるのですが、
originはansibleベースのインストーラーで大量のplaybookを用いてインストールする必要があり、しんどい思いをした記憶があります…

その印象が強くてちょっと構えてしまいましたが、
かなり進化していてめちゃくちゃ簡単に構築できるので、OpenShift気になってる方、とりあえず試しに触ってみた方が早いと思います!

本手順はローカルPCとしてMacを使った手順となっています。 また、事前に下記を行なって下さい。 ・Mac PCへterraformのインストール(参考) ・AWS IAMにてユーザ作成(参考) ・AWS Route53でドメインの取得(参考

OpenShiftとは

OpenShiftは、Red Hatの提供する商用版の Kubernetes です。コミュニティ版はOKDです。

OpenShiftの標準機能はほぼオープンソースのKubernetesですが、Operatorと呼ばれるKubernetesのAPIを拡張する機能を軸に、CI/CDや可視観測など、クラウドネイティブアプリケーションの開発・運用を効率的に行うために必要な機能をバンドル提供する製品となっています。

Red Hatのサポートを受けられるサブスクリプションを購入して利用できますが、期間限定の無償利用も可能になっています。

1. OpenShiftのインストーラーのダウンロード

1-1. Red Hat Hybrid Cloud Consoleへアクセス

アカウントを作成してログインして下さい(アカウントは無料です)。

1-2. [Openshift] - [Clusters] - [Create Clusters]を押下

この時点ではクラスタは作られないので安心してください。

1-3. 右画面の下の方のRun it yourselfAWS(x86_64)を押下

image.png

1-4. インストールタイプの選択画面が表示されるので、Installer-provisioned Infrastructureを選択

image.png

OpenShitクラスタを自分でdeployしたい場合は、以下の2タイプの方法があります。

インストールタイプ 内容
IPI (Installer-Provisioned Infrastructure) OpenShiftクラスタを展開するインフラストラクチャも含めてプロビジョニング
UPI (User-provisioned infrastructure) 自分で事前にプロビジョニングしたインフラストラクチャへOpenShiftクラスタを展開

IPIは、パブリッククラウドのアカウントを事前に取得の上、OpenShiftクラスタを展開するopenshift-installというコマンドへCredentialなどを引き渡して実行することで、パブリッククラウドのAPIを用いてインフラストラクチャを自動構築してくれます。

一方、例えば会社でプライベートクラウドを運用している等、オンプレミスの環境へOpenShiftクラスタを展開したい、という場合はUPIを選択することになります。

OpenShiftクラスタ自体の運用をオフロードしたい、という場合は、AWS、GCP、Azure、IBM Cloudのマネージドサービスを利用したり、Red Hatが管理しているRed Hat Dedicatedを利用するという選択肢もあります。

1-5. インストーラーをダウンロード

image.png

2. deployするOpenShiftクラスタのconfig出力

2-1. 作業ディレクトリを作成し、解凍したopenshift-installを設置

$ mkdir work
$ ls openshift-install
openshift-install

2-2. 公開鍵の作成

deployされるインスタンスへsshするのに使用します。

$ ssh-keygen -t rsa -b 4096 -f ~/.ssh/<SSH_KEY_NAME>

2-3. Red Hat Hybrid Cloud ConsoleからPull Secretをダウンロード

image.png

2-4. config格納用の任意のディレクトリを作成

ここでは、configというディレクトリを作成しておきます。

$ mkdir config

2-5. install-config.yamlを生成

対話形式で2-2の公開鍵のパスと、2-3でダウンロードしたPull Secret(中身をそのままペースト)を入力します。

MACの [システム環境設定]-[セキュリティとプライバシー]-[一般]にて、 ダウンロードしたアプリケーションの実行許可をしてから進んでください。

$ ./openshift-install create install-config --dir=./config     
? SSH Public Key  # 2-2で作成した公開鍵 (.pub)
? Platform aws       # awsを選択
? AWS Access Key ID  # AWS IAMで取得したAccess Key ID
? AWS Secret Access Key # AWS IAMで取得したSecret Access Key ID

# 自動で~/.aws/credentialsが生成されて、ここに入力したKey IDが保存されます。

? Region ap-northeast-1   # AWS Region (ここではTokyoリージョンを指定)
? Base Domain # Route53で取得したドメイン
? Cluster Name # 任意のクラスタ名 (サブドメインなどで使用される)
? Pull Secret # 2-3で取得したPull Secretのファイルの中身をベタ貼り                                   

install-config.yamlの中身は以下の感じになってます。
masterノードやworkerノードの台数を変更したい場合は修正して下さい。
今回は特に編集せずにそのままdeployしてみます。

install-config.yaml
apiVersion: v1
baseDomain: example.com # Route53で取得したドメイン
compute:
- architecture: amd64
  hyperthreading: Enabled
  name: worker
  platform: {}
  replicas: 3 # デフォルトでworker 3台の構成
controlPlane:
  architecture: amd64
  hyperthreading: Enabled
  name: master
  platform: {}
  replicas: 3  # デフォルトでmaster 3台の構成
metadata:
  creationTimestamp: null
  name: dev # 入力したクラスタ名
networking:
  clusterNetwork:
  - cidr: 10.128.0.0/14
    hostPrefix: 23
  machineNetwork:
  - cidr: 10.0.0.0/16
  networkType: OpenShiftSDN
  serviceNetwork:
  - 172.30.0.0/16
platform:
  aws:
    region: ap-northeast-1 # 選択したAWS Region
publish: External
pullSecret:  # Pull Secret 
sshKey: |    # 公開鍵情報

--dirオプションで指定したディレクトリ配下に.openshift_install_state.jsonがある状態で、2-5のコマンドを実行すると、対話入力が表示されずに過去に入力した情報に基づいてinstall-config.yamlが生成されます。 改めて対話入力でinstall-config.yamlを作成したい場合は、.openshift_install_state.jsonを削除して下さい。

3. OpenShiftクラスタのdeploy

$ ./openshift-install create cluster --dir=./config

30分くらいするとdeployが完了します。

$ ./openshift-install create cluster --dir=./config
INFO Credentials loaded from the "default" profile in file "/path/to/dir/.aws/credentials" 
INFO Consuming Install Config from target directory 
INFO Creating infrastructure resources...         
INFO Waiting up to 20m0s for the Kubernetes API at https://example.com:6443...  
# K8s APIのエンドポイント

INFO API v1.22.3+4dd1b5a up                       
INFO Waiting up to 30m0s for bootstrapping to complete... 
INFO Destroying the bootstrap resources...        
INFO Waiting up to 40m0s for the cluster at https://example.com:6443 to initialize... 
INFO Waiting up to 10m0s for the openshift-console route to be created... 
INFO Install complete!                            
INFO To access the cluster as the system:admin user when using 'oc', run 'export KUBECONFIG=/path/to/dir/work/config/auth/kubeconfig' 
# 後述のocコマンドやkubectlコマンドを実行する際は、このkubeconfigを参照する

INFO Access the OpenShift web-console here: https://example.com 
INFO Login to the console with user: "kubeadmin", and password: "randompassword"  # Webコンソールのログインで使用されるアカウント情報

INFO Time elapsed: 34m41s 

出力されたURLへアクセスすればWebコンソールへ接続できます!

image.png

4. OpenShiftクライアントツール(oc)のダウンロード

Red Hat Hybrid Cloud Consoleの[Download]メニューからCommand line interfaceをダウンロードします。

image.png

4-1. ダウンロードファイルを解凍

$ tar zxvf openshift-client-mac.tar.gz

4-2. PATHの通ってるディクレクトリへ配置

$ mv oc /usr/local/bin/

MACの[システム環境設定]-[セキュリティとプライバシー]-[一般]にて、 ダウンロードしたアプリケーションの実行許可をして下さい。

4-3. OpenShiftクラスタへ接続してみる

$ export KUBECONFIG=/path/to/dir/work/config/auth/kubeconfig

$ oc cluster-info
Kubernetes control plane is running at https://example.com:6443

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

kubeconfig~/.kube/configへ配置すれば、
環境変数KUBECONFIGの定義不要でocコマンドを実行できます。

$ mkdir ~/.kube
$ cp -p /path/to/dir/work/config/auth/kubeconfig ~/.kube/config
$ oc cluster-info
Kubernetes control plane is running at https://example.com:6443

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

5. IPIインストールで構築されるAWSインフラの構成

openshift-installは、以下の図に示す構成でAWS環境を構築します。

image.png

この図には表現していませんが、構築中にbootstrapというインスタンスが起動し、OpenShiftの構築を行なった後に削除されます。

InternetからKubernetes APIの6443ポート宛の通信をELBで受け、ELBがいずれかのAvailability Zone(AZ)内のmasterノードへロードバランシングします。
ユーザのdeployしたアプリケーションPodのingress通信はworkerノードへ分散されます。

参考資料

6
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
1