本節內容是Docker鏡像以及Ansible實現多節點集羣Containerized Installer。大體流程和基於RPM的安裝過程類似。
新更新了一篇3.10.0的安裝博客,鏈接https://blog.csdn.net/huqigang/article/details/82351972。
本部分openshift集羣的部署分爲以下幾個階段:
- 主機準備。準備openshift集羣需要的主機。
- 安裝前預配置。準備相應的系統配置與軟件依賴。
- 執行安裝。使用Ansible Playbook進行自動化安裝。
主機準備
由於是在自己筆記本上嘗試部署多節點集羣,內存有限,這裏採用兩節點集羣。
類型 | 主機名 | IP | 操作系統 | CPU |
---|---|---|---|---|
Master | master.example.com | 192.168.121.158 | CentOS 7.3 | 2G |
Node | node.example.com | 192.168.121.157 | CentOS 7.3 | 2G |
需要分配2G內存。生產環境官方推薦Master至少16G內存,Node至少8G內存。
在這裏,我給每臺虛機均掛載了兩塊硬盤,其中一塊/dev/sdb之後會作爲Docker的存儲空間。使用fdisk -l
指令可以查看。
安裝前預配置
配置主機名
確實主機名配置正確。如有需要,可採用hostnamectl命令設置主機名。例如:
# hostnamectl set-hostname master.example.com
此外需要保證主機名能夠正確的解析到主機IP。可以通過ping $(hostname)來驗證。
實際生產環境推薦配置相關的域名解析服務器。
在此直接修改各個節點的/etc/hosts文件,加上靜態的域名解析。
192.168.121.158 master.example.com
192.168.121.157 node.example.com
- 開啓SELINUX
官方文檔推薦開啓SELINUX,否則會導致安裝失敗。
修改/etc/selinux/config
SELINUX=enforcing
SELINUXTYPE=targeted
安裝及配置軟件包
- 所有的節點下執行以下命令安裝Openshift依賴的軟件包。
# yum -y install wget git net-tools bind-utils iptables-services bridge-utils bash-completion kexec-tools sos psacct vim lrzsz
- 所有節點安裝atomic。
# yum install -y atomic
安裝及配置docker
- 所有節點安裝docker。
# yum install -y docker
- 所有節點配置Docker。
修改/etc/sysconfig/docker-storage-setup。修改Docker鏡像存儲空間。修改後內容如下。
DEVS=/dev/sdb
VG=dockervg
- 執行docker-storage-setup。
- 所有節點啓動docker。
# systemctl enable docker
# systemctl start docker
配置SSH
- master節點上生成SSH密鑰。
# ssh-keygen -f /root/.ssh/id_rsa -N ''
Ansible是基於Agentless架構實現的,即不需要在遠程的目標主機上預先安裝Agent程序。Ansible對遠程主機命令的執行依賴SSH等遠程控制協議。因爲將在Master上執行Ansible Playbook安裝openshift,所以需要配置Master到各個節點的互信,包括Master到Master的互信。
在Master節點上執行:
for host in master.example.com node.example.com ; do ssh-copy-id -i ~/.ssh/id_rsa.pub $host; done
鏡像準備
因爲是Containerized Installer,安裝過程中需要下載鏡像,這裏選擇提前準備好安裝中必備的較大的鏡像。
包括如下:
openshift/origin:v3.6.0
openshift/node:v3.6.0 (node + openshift-sdn + openvswitch RPM for client tools)
openshift/openvswitch:v3.6.0 (CentOS 7 + openvswitch RPM, runs ovsdb and ovsctl processes)
registry.access.redhat.com/rhel7/etcd:latest
openshift/origin-ansible:v3.6
這裏的鏡像列舉不全,可以參考本文最後的一張截圖查看集羣所需的所有鏡像。推薦提前在主機上pull好鏡像,或者將鏡像導入本地鏡像倉庫。
- 在Master節點上將openshift/origin-ansible鏡像pull到atomic 裏:
# atomic pull --storage ostree docker:docker.io/openshift/origin-ansible:v3.6
該步的官網解釋如下。
The openshift/origin-ansible image is a containerized version of the OpenShift Origin installer that runs as a system container. System containers are stored and run outside of the traditional docker service. Functionally, using the containerized installer is the same as using the traditional RPM-based installer, except it is running in a containerized environment instead of directly on the host.
The installer system container must be stored in OSTree instead of defaulting to docker daemon storage.
大意是openshift/origin-ansible這個鏡像是OpenShift Origin容器版安裝程序,以系統容器的方式運行。系統容器在傳統docker服務之外存儲和運行。
系統容器必須存儲在OSTree中,而不是默認的docker儲存。
配置Ansible
配置Ansible的hosts配置文件(記錄了Ansible需要操作的目標主機信息)。
- 創建hosts文件
# mkdir /etc/ansible
# touch /etc/ansible/hosts
- 創建/etc/ansible/hosts文件,添加下面的內容。
可參考https://docs.openshift.org/latest/install_config/install/advanced_install.html官網內容進行編寫。
# Create an OSEv3 group that contains the masters and nodes groups
[OSEv3:children]
masters
nodes
etcd
# Set variables common for all OSEv3 hosts
[OSEv3:vars]
# SSH user, this user should allow ssh based auth without requiring a password
ansible_ssh_user=root
openshift_deployment_type=origin
openshift_release=3.6.0
openshift_disable_check=disk_availability,docker_storage,memory_availability,docker_image_availability
containerized=true
openshift_use_etcd_system_container=true
# uncomment the following to enable htpasswd authentication; defaults to DenyAllPasswordIdentityProvider
openshift_master_identity_providers=[{'name':'htpasswd_auth','login':'true','challenge':'true','kind':'HTPasswdPasswordIdentityProvider','filename':'/etc/origin/master/htpasswd'}]
# host group for masters
[masters]
master.example.com
# host group for nodes, includes region info
[nodes]
master.example.com openshift_schedulable=True openshift_node_labels="{'region': 'infra'}"
node.example.com openshift_node_labels="{'region': 'infra', 'zone': 'east'}"
[etcd]
master.example.com
在Master節點上安裝系統容器,使其被設置爲系統服務
# atomic install --system --storage=ostree --name=openshift-installer --set INVENTORY_FILE=/etc/ansible/hosts docker:docker.io/openshift/origin-ansible:v3.6
參數INVENTORY_FILE爲上文配置的Ansible的hosts配置文件,docker爲使用的鏡像文件。
想要卸載openshift-installer的話可以執行:
# atomic uninstall openshift-installer
在Master節點上啓動安裝
# systemctl start openshift-installer
另起一個窗口,使用journalctl -f -u openshift-installer
可以查看實時日誌。
驗證安裝結果
檢查集羣狀態。
# oc get nodes
# oc get all
最終用到的鏡像如下:
Containerized Installer安裝多節點集羣成功。