この記事は2019/12/10にQiitaに投稿した記事の転載です。
このエントリは Ansible 3 Advent Calendar 2019の10日目の投稿です。 最近はOpenShiftに関する記事を多く書いているのですが、3つ目のアドベントカレンダーが追加されたのを見て勢いで登録してみました。
はじめに
「OpenShift 4のクラスターにRHELのWorkerノードを追加する」という作業を行う中で、Ansibleを使う場面があります。ドキュメントに従ってopenshift-ansible
というOpenShiftのインストールと構成管理を行うPlaybookを使います。
この記事ではOpenShiftに関する内容は扱いません。OpenShift 4のクラスターにWorkerノードを追加する内容については下記の記事を参考にしてください。 [OCP4/UPIインストールにおけるWorkerノードの追加(RHCOS編) - 赤帽エンジニアブログ] (https://rheb.hatenablog.com/entry/openshift42-upi-add-rhcos)
この記事は、上記の続きの「Workerノードの追加(RHEL編)」を書くために検証を行った際の、Ansible実行部分にフォーカスを当てた内容となります。
事前準備
構成図
Ansibleの実行元は踏み台サーバー、実行先はRHELノードになります。
踏み台サーバー
構築済みの踏み台サーバーに下記の設定を追加します
OCP]# git clone https://github.com/openshift/openshift-ansible.git Cloning into 'openshift-ansible'... remote: Enumerating objects: 43, done. remote: Counting objects: 100% (43/43), done. remote: Compressing objects: 100% (32/32), done. remote: Total 144831 (delta 14), reused 23 (delta 6), pack-reused 144788 Receiving objects: 100% (144831/144831), 39.75 MiB | 6.65 MiB/s, done. Resolving deltas: 100% (90973/90973), done.
- inventory/hostsの設定
OCP]# cat openshift-ansible/inventory/hosts [all:vars] # SSH user, this user should allow ssh based auth without requiring a # password. If using ssh key based auth, then the key should be managed by an # ssh agent. ansible_user=user ansible_ssh_private_key_file=/root/.ssh/id_rsa # If ansible_user is not root, ansible_become must be set to true and the # user must be configured for passwordless sudo ansible_become=True ############################################################################### # Required configuration variables # ############################################################################### openshift_kubeconfig_path="~/OCP/bare-metal/auth/kubeconfig" # For running RHEL worker upgrades #[workers] #mycluster-worker-[1:3].example.com # For running RHEL worker scaleup [new_workers] worker-3.test.example.local
RHELノード
最小構成でインストール後、下記の設定を行います
- ネットワーク自動接続
- ipv6無効化
- ホスト名の静的設定
- Red Hatサブスクリプション登録
- 必要なyumリポジトリーの設定(ドキュメント参照)
- 実行ユーザー:
user
の作成 - 実行ユーザーに
sudo
をNOPASSWD:
で実行する権限の付与 - SSH公開鍵の配置
(参考)今回の検証環境では、実行ユーザーにsudoの権限を与えて公開鍵認証でSSH接続をおこなっています。この部分は各自のポリシーに合わせて設定を調整ください。
Playbookの実行
事前準備が完了し、踏み台サーバーからRHELノードへAnsibleのテスト実行を行います
OCP]# cd openshift-ansible openshift-ansible]# ansible -i inventory/hosts worker-3.test.example.local -m ping worker-3.test.example.local | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong" }
テスト実行が成功すれば、Playbookの実行を行います
openshift-ansible]# ansible-playbook -i inventory/hosts playbooks/scaleup.yml PLAY [Pre-scaleup checks] ****************************************************************************************************************************************************************************************************************************************************** TASK [openshift_node : Ensure [new_workers] group is populated] **************************************************************************************************************************************************************************************************************** Friday 06 December 2019 00:06:43 +0900 (0:00:00.047) 0:00:00.047 ******* skipping: [localhost] TASK [openshift_node : Get cluster nodes] ************************************************************************************************************************************************************************************************************************************** Friday 06 December 2019 00:06:44 +0900 (0:00:00.022) 0:00:00.069 ******* changed: [localhost] TASK [openshift_node : Check for nodes which are already part of the cluster] ************************************************************************************************************************************************************************************************** Friday 06 December 2019 00:06:44 +0900 (0:00:00.518) 0:00:00.588 ******* skipping: [localhost] => (item=worker-3.test.example.local) TASK [openshift_node : Fail if new_workers group contains active nodes] ******************************************************************************************************************************************************************************************************** Friday 06 December 2019 00:06:44 +0900 (0:00:00.025) 0:00:00.614 ******* skipping: [localhost] PLAY [install nodes] *********************************************************************************************************************************************************************************************************************************************************** TASK [openshift_node : include_tasks] ****************************************************************************************************************************************************************************************************************************************** Friday 06 December 2019 00:06:44 +0900 (0:00:00.046) 0:00:00.660 ******* included: /root/OCP/openshift-ansible/roles/openshift_node/tasks/install.yml for worker-3.test.example.local TASK [openshift_node : Install openshift support packages] ********************************************************************************************************************************************************************************************************************* Friday 06 December 2019 00:06:44 +0900 (0:00:00.063) 0:00:00.724 ******* changed: [worker-3.test.example.local] 〜省略〜
検証環境では完了までに約30分ほどかかりました。最終的に下記のような出力が出れば完了です。
〜省略〜 PLAY RECAP ********************************************************************************************************************************************************************************************************************************************************************* localhost : ok=1 changed=1 unreachable=0 failed=0 skipped=3 rescued=0 ignored=0 worker-3.test.example.local : ok=36 changed=28 unreachable=0 failed=0 skipped=7 rescued=0 ignored=0 Friday 06 December 2019 00:36:24 +0900 (0:00:38.106) 0:29:40.960 ******* =============================================================================== openshift_node : Install openshift support packages ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 1508.40s openshift_node : Install openshift packages --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 151.07s openshift_node : Wait for nodes to report ready ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 38.11s openshift_node : Approve node CSR -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 22.23s openshift_node : Reboot the host and wait for it to come back ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 18.41s openshift_node : Pull release image ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 15.46s openshift_node : Pull MCD image ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 12.06s openshift_node : Get machine controller daemon image from release image ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 2.63s openshift_node : Apply ignition manifest -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1.09s openshift_node : Approve node-bootstrapper CSR -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 0.74s openshift_node : Get cluster version ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 0.73s openshift_node : Write /etc/containers/registries.conf ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 0.73s openshift_node : Setting sebool container_manage_cgroup ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 0.71s openshift_node : Enable the CRI-O service ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 0.68s openshift_node : Wait for bootstrap endpoint to show up ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 0.66s openshift_node : Create CNI dirs for crio ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 0.62s openshift_node : Restart the CRI-O service ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 0.61s openshift_node : Get cluster nodes -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 0.52s openshift_node : Check for cluster http proxy --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 0.48s openshift_node : Fetch bootstrap ignition file locally ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 0.48s openshift-ansible]#
タスクの内容
タスクは全部で47ありました。下記を眺めると最小構成のRHELの状態から、Workerノードになるまでに行われたセットアップの流れが把握できます。
- Ensure [new_workers] group is populated
- Get cluster nodes
- Check for nodes which are already part of the cluster
- Fail if new_workers group contains active nodes
- include_tasks
- Install openshift support packages
- Create CNI dirs for crio
- Get cluster version
- Set fact l_cluster_version
- Override version when running CI
- Install openshift packages
- Enable the CRI-O service
- include_tasks
- Disable swap
- Enable IP Forwarding
- Disable firewalld service
- Setting sebool container_manage_cgroup
- Create temp directory
- Wait for bootstrap endpoint to show up
- Fetch bootstrap ignition file locally
- Extract the last registries.conf file from bootstrap.ign
- Check data URL encoding and extract source data
- Write /etc/containers/registries.conf
- Restart the CRI-O service
- Get cluster pull-secret
- Write pull-secret to file
- Get cluster release image
- Set l_release_image fact
- Check for cluster http proxy
- Set http proxy
- Check for cluster https proxy
- Set https proxy
- Check for cluster no proxy
- Set no proxy
- Check for additional trust bundle
- Set additional trust bundle
- Copy additional trust bundle to system CA trust
- Update CA trust
- Pull release image
- Get machine controller daemon image from release image
- Pull MCD image
- Apply ignition manifest
- Remove temp directory
- Reboot the host and wait for it to come back
- Approve node-bootstrapper CSR
- Approve node CSR
- Wait for nodes to report ready
まとめ
openshift-ansible
を使ってOCP4/UPIクラスターにRHELノードを追加する際の、手順から実行記録までを紹介しました。Playbookを使うことでRHELノードを簡単にWorkerノードとして追加できました。用意されたPlaybookを使うことで何を行ったのかがブラックボックスになりがちですが、タスクを一覧にして眺めるだけで実行内容の理解に繋がります。詳細な内容を理解するためにPlaybookの中を覗いてみると、より理解を深めることができると思います。
参考リンク
- [第6章 RHEL コンピュートマシンの OpenShift Container Platform クラスターへの追加 4.2 | Red Hat Customer Portal] (https://access.redhat.com/documentation/ja-jp/openshift_container_platform/4.2/html/machine_management/adding-rhel-compute)
- [openshift/openshift-ansible: OpenShift Installation and Configuration Management] (https://github.com/openshift/openshift-ansible)
- [OCP4/UPIインストールにおけるWorkerノードの追加(RHCOS編) - 赤帽エンジニアブログ] (https://rheb.hatenablog.com/entry/openshift42-upi-add-rhcos)
- [OpenShift 4.1をベアメタルへUPIインストールする - 赤帽エンジニアブログ] (https://rheb.hatenablog.com/entry/openshift41-baremetal-upi)