002.OpenShift安裝與部署


一 前置條件說明

1.1 安裝准備概述

Red Hat OpenShift容器平台是由Red Hat作為RPM包和容器映像兩種類型存在。RPM包使用訂閱管理器從標准Red Hat存儲庫(即Yum存儲庫)下載,容器映像來自Red Hat私有倉庫。
OpenShift容器平台安裝需要多個服務器,支持服務器或虛擬機的多種形式。同時為了簡化OpenShift集群的部署,Red Hat提供了一個基於Ansible的安裝程序,它可以通過交互運行,也可以使用包含環境配置細節的應答文件以自動的非交互方式運行。
在運行安裝程序之前,需要執行一些預安裝任務,以及安裝后的安裝任務,以獲得功能齊全的OpenShift容器平台集群。RedHat為安裝OpenShift容器平台提供了兩種不同的方法。
  • 第一種方法使用快速安裝程序,可用於簡單的集群設置。
  • 第二種方法是較為精細的安裝方式,並使用Ansible playbook來自動化該過程。
本實驗使用Ansible來自動配置OpenShift集群。同時,Ansible可以為OpenShift安裝准備主機,例如包安裝、禁用服務和客戶化配置。
提示:更多Ansible內容參考https://www.cnblogs.com/itzgr/category/1333622.html

1.2 節點准備

需要相應的master和node節點互通,並且配置master至所有節點的免秘鑰登錄。同時能解析所有FQDN,及注冊相應repo庫。
提示:以上准備工作也可通過Ansible直接跑相應的yml完成。

二 實驗一:前置條件操作

2.1 環境准備

[student@workstation ~]$ lab install-prepare setup #運行准備腳本
提示:本環境基於RedHat RH280環境,所有lab命令為環境自動化准備命令,后續不再贅述。

2.2 安裝Ansible

[student@workstation ~]$ rpm -qa | grep ansible
[student@workstation ~]$ sudo yum -y install ansible

2.3 驗證Ansible

[student@workstation ~]$ cd /home/student/DO280/labs/install-prepare/
[student@workstation ~]$ ansible --version
[student@workstation install-prepare]$ cat ansible.cfg
clipboard
[student@workstation install-prepare]$ cat inventory
clipboard
Inventory文件解釋:
Inventory定義了六個主機組:
  • workstations:為developer節點,即運行playbook的節點;
  • nfs:為集群存儲提供nfs服務的環境中的vm;
  • masters:OpenShift集群中用作master角色的節點;
  • etcd:用於OpenShift集群的etcd服務的節點,本環境中使用master節點;
  • node:OpenShift集群中的node節點;
  • OSEv3:組成OpenShift集群的所有接待,包括master、etcd、node或nfs組中的節點。
注意:默認情況下,docker使用在線倉庫下載容器映像。本環境內部無網絡,因此將docker倉庫配置為內部私有倉庫。在yml中使用變量引入倉庫配置。
此外,安裝會在每個主機上配置docker守護進程,以使用overlay2 image驅動程序存儲容器映像。Docker支持許多不同的image驅動。如AUFS、Btrfs、Device mapper、OverlayFS。

2.4 檢查節點連通性

[student@workstation install-prepare]$ cat ping.yml
  1 ---
  2 - name: Verify Connectivity
  3   hosts: all
  4   gather_facts: no
  5   tasks:
  6     - name: "Test connectivity to machines."
  7       shell: "whoami"
  8       changed_when: false
[student@workstation install-prepare]$ ansible-playbook -v ping.yml

2.5 確認yml

[student@workstation install-prepare]$ cat prepare_install.yml
clipboard
解釋:如上yml引入了三個role。
docker-storage內容如下,該role定義相關docker的后端存儲驅動以及創建docker所需的image存儲路徑,並最終啟動docker。
[student@workstation install-prepare]$ cat roles/docker-storage/tasks/main.yml
  1 ---
  2 - block:
  3   - name: Customize default /etc/sysconfig/docker-storage-setup
  4     template:
  5       src: docker-storage-setup
  6       dest: /etc/sysconfig/docker-storage-setup
  7       owner: root
  8       group: root
  9       mode: 0644
 10     when: not use_overlay2_driver
 11   - name: Customize /etc/sysconfig/docker-storage-setup using overlay2 storage driver
 12     template:
 13       src: docker-storage-setup-overlay2
 14       dest: /etc/sysconfig/docker-storage-setup
 15       owner: root
 16       group: root
 17       mode: 0644
 18     when: use_overlay2_driver
 19   - name: Verify existence of /dev/docker-vg/docker-pool
 20     stat:
 21       path: /dev/docker-vg/docker-pool
 22     register: p
 23   - name: Stop docker
 24     service:
 25       name: docker
 26       state: stopped
 27     when: p.stat.exists == False
 28   - name: Remove loopback docker files
 29     file:
 30       dest: /var/lib/docker
 31       state: absent
 32     when: p.stat.exists == False
 33   - name: Run docker-storage-setup
 34     command: /usr/bin/docker-storage-setup
 35     when: p.stat.exists == False
 36   - name: Start and enable docker
 37     service:
 38       name: docker
 39       state: started
 40     when: p.stat.exists == False
 41   when: docker_storage_device is defined
 42 
[student@workstation install-prepare]$ cat roles/docker-storage/templates/docker-storage-setup
  1 DEVS={{ docker_storage_device }}
  2 VG=docker-vg
  3 SETUP_LVM_THIN_POOL=yes
docker-registry-cert內容如下,該role定義相關docker的使用私有倉庫,並且導入了相關crt證書。
[student@workstation install-prepare]$ cat roles/docker-registry-cert/tasks/main.yml
  1 ---
  2 - name: Enable the Trust
  3   shell: update-ca-trust enable
  4 - name:  Retrieve the certificate
  5   fetch:
  6     src: "{{ cacert }}"
  7     dest: "{{ local_destination }}"
  8   delegate_to: "{{ registry_host }}"
  9 - name:  Copy the certificate
 10   copy:
 11     src: "{{ source }}"
 12     dest: "{{ destination }}"
 13     owner: root
 14     group: root
 15     mode: 0755
 16 - name: Update the Trust
 17   shell: update-ca-trust extract
 18 - name: Restart Docker
 19   service:
 20     name: docker
 21     state: restarted
 22 
[student@workstation install-prepare]$ cat roles/docker-registry-cert/vars/main.yml 
  1 registry_host: services.lab.example.com
  2 cacert: /etc/pki/tls/certs/example.com.crt
  3 local_destination: /tmp/
  4 source: "/tmp/{{ ansible_fqdn }}/etc/pki/tls/certs/example.com.crt"
  5 destination: /etc/pki/ca-trust/source/anchors/example.com.crt
openshift-node內容如下,該role定義相關安裝OpenShift所需的所有依賴包任務。
[student@workstation install-prepare]$ ll roles/openshift-node/files/
total 4
-rw-r--r--. 1 student student 389 Jul 19 2018 id_rsa.pub
[student@workstation install-prepare]$ cat roles/openshift-node/meta/main.yml
  1 ---
  2 dependencies:
  3   - { role: docker }
[student@workstation install-prepare]$ cat roles/openshift-node/tasks/main.yml
  1 ---
  2 - name: Deploy ssh key to root at all nodes
  3   authorized_key:
  4     user: root
  5     key: "{{ item }}"
  6   with_file:
  7     - id_rsa.pub
  8 - name: Install required packages
  9   yum:
 10     name: "{{ item }}"
 11     state: latest
 12   with_items:
 13     - wget
 14     - git
 15     - net-tools
 16     - bind-utils
 17     - iptables-services
 18     - bridge-utils
 19     - bash-completion
 20     - kexec-tools
 21     - sos
 22     - psacct
 23     - atomic-openshift-clients
 24     - atomic-openshift-utils
 25     - atomic-openshift
 26 

2.6 運行playbook

[student@workstation ~]$ cd /home/student/DO280/labs/install-prepare/
[student@workstation install-prepare]$ ansible-playbook prepare_install.yml
clipboard
提示:該准備工作將完成如下操作:
  • 在每個節點上安裝並運行Docker;
  • 在每個節點上Docker使用一個邏輯卷存儲;
  • 每個節點使用自簽名證書信任私有Docker倉庫;
  • 在每個節點上都會安裝基本包。

2.7 確認驗證

[student@workstation install-prepare]$ for vm in master node1 node2;
do echo -e "\n$vm"
ssh $vm sudo systemctl status docker | head -n3
done #驗證docker服務
clipboard
[student@workstation install-prepare]$ for vm in master node1 node2;
do echo -e "\n$vm : lvs"
ssh $vm sudo lvs
echo -e "\n$vm : df -h"
ssh $vm sudo df -h | grep vg-docker
done #查看docker使用的lvm
clipboard
[student@workstation install-prepare]$ for vm in master node1 node2;
do echo -e "\n$vm"
ssh $vm docker pull rhel7:latest
done #測試pull image
clipboard
[student@workstation install-prepare]$ for vm in master node1 node2;
do echo -e "\n$vm"
ssh $vm rpm -qa wget git net-tools bind-utils \
yum-utils iptables-services bridge-utils bash-completion \
kexec-tools sos psacct atomic-openshift-utils
done #檢查相關依賴包是否安裝成功

三 正式安裝說明

3.1 安裝步驟

安裝准備完成后正式安裝包括四個步驟:
  • 編寫一個目錄文件來描述所需的集群特性和體系結構;
  • 執行prerequisites.yml的playbook;
  • 執行deploy_cluster,yml的playbook;
  • 驗證安裝。

3.2 安裝和配置節點

OpenShift Inventory定義了以下主機組。
master:對於OpenShift,這是必須的組,定義了OpenShift集群中哪些主機充當master節點;
node:對於OpenShift,這是必須的組,它定義了OpenShift集群中哪些主機充當node節點;
etcd:[master]部分中列出的所有主機也應屬於etcd;
nfs:這個組是可選的,應該只包含一個主機。如果Inventory文件中存在特定的變量,OpenShift playbook將在這台機器上安裝並配置NFS;
OSEv3:這個組包含任何屬於OpenShift集群的機器。安裝劇本引用這個組來運行在集群全范圍內的任務。
[student@workstation install-prepare]$ cat inventory
clipboard
說明:
  • 安裝所需版本的OpenShift容器平台;
  • 用戶使用htpasswd身份驗證對集群進行身份驗證;
  • DNS條目apps.lab.example.com用作OpenShift應用程序的子域;
  • NFS存儲用於OpenShift etcd服務和OpenShift 內部倉庫;
  • classroom container registry用作倉庫。
變量說明:
OpenShift安裝變量記錄在Inventory的[OSEv3:vars]部分。安裝變量用於配置多個OpenShift組件,例如:
  • 一個內部容器倉庫;
  • Gluster、Ceph等以便於提供持久性存儲;
  • 集群日志;
  • 自定義集群證書。

3.3 配置OpenShift版本

可通過在[OSEv3:vars]中指定如下配置確定OpenShift所安裝的版本:
openshift_deployment_type=openshift-enterprise
openshift_release=v3.9
指定OpenShift部署類型,可選值為openshift-enterprise和origin。
openshift_image_tag=v3.9.14
openshift_disable_check=disk_availability,docker_storage,memory_availability
容器化的OpenShift服務使用帶有“v3.9.14”標記的圖像。這將阻止集群自動升級到更新的容器映像;
對於非生產集群,可以禁用對系統需求的檢查。

3.4 配置驗證

OpenShift容器平台身份驗證基於OAuth, OAuth提供了一個基於HTTP的APl,用於對交互式和非交互式客戶端進行身份驗證。
OpenShift master運行一個OAuth服務器,OpenShift可以支持多種Provider,這些Provider可以與特定於組織的身份管理產品集成。支持的OpenShift身份驗證的Provider:
  • HTTP Basic,外部單點登錄(SSO)系統;
  • 使用GitHub和GitLab帳號;
  • OpenID連接,使用OpenID-compatible SSO和谷歌帳戶;
  • OpenStack Keystone v3;
  • LDAP v3服務器。
OpenShift安裝程序使用默認的安全方法,DenyAllPasswordIdentityProvider是缺省提供程序。使用此Provider,表示只有master主機上的root用戶才能使用OpenShift客戶端命令和API。

3.5 配置htpasswd驗證

OpenShift HTPasswdPasswordIdentityProvider根據Apache HTTPD htpasswd程序生成的文件驗證用戶和密碼。
htpasswd程序將用戶名和密碼保存在純文本文件中,每行一條記錄,字段用冒號分隔。密碼使用MD5散列。如果將此文件添加或刪除用戶,或更改用戶密碼,OpenShift OAuth服務器將自動重新讀取該文件。
要將OpenShift master配置使用HTPasswdPasswordIdentityProvider,需要配置openshift_master_identity_providers。
  1 openshift_master_identity_providers。
  2 openshift_master_identity_providers=[{'name': 'htpasswd_auth', 'login': 'true',
  3 'challenge': 'true', 'kind': 'HTPasswdPasswordIdentityProvider',	#配置后端驅動
  4 'filename': '/etc/origin/master/htpasswd'}]				#制定master主機上
也支持在配置文件中直接指定初始的用戶名和密碼。
openshift_master_htpasswd_users="{'user1':'$apr1$.NHMsZYc$MdmfWN5DM3q280/W7c51c/',
'user2':'$apr1$.NHMsZYc$MdmfWN5DM3q280/W7c51c/'}"
生產hash密碼可參考如下:
  1 [student@workstation ~]$ htpasswd -nb admin redhat
  2 [student@workstation ~]$ openssl passwd -apr1 redhat

3.6 網絡要求

集群節點的通配符DNS條目允許任何新創建的路由自動路由到subdomain的集群。通配符DNS條目必須存在於唯一的子域中,例如apps.mycluster.com,並解析為主機名或集群節點的IP地址。inventory文件中通配符DNS條目是通過變量openshift_master_default_subdomain進行設置 。
openshift_master_default_subdomain=apps.mycluster.com

3.7 master服務端口

主服務端口openshift_master_api_port變量定義主API的監聽端口。缺省端口8443,當master使用SSL時,也可以使用443端口。從而在連接的時候省略端口號。
master console端口由openshift_master_console_port變量的值設置,默認端口是8443。master console端口也可以設置為443,從而在連接的時候省略端口號。
3.8 防火牆
OpenShift節點上的默認防火牆服務是iptables。若要在所有節點上使用firewalld作為防火牆服務,需要將操作系統防火牆使用firewalld變量設置為true,即os_firewall_use_firewalld=true。

四 配置持久化存儲

4.1 持久存儲配置

默認情況下,容器數據是臨時的,並且在容器被銷毀時丟失。Kubernetes持久卷框架為容器請求和使用持久存儲提供了一種機制。為了避免數據丟失,這些服務被配置為使用持久卷。
OpenShift支持多個插件,使用各種存儲技術創建持久卷。可以使用NFS、iSCSI、GlusterFS、Ceph或其他商業雲存儲。
本環境中,OpenShift容器registry和OpenShift Ansible Broker服務被配置為使用NFS持久性存儲。
提示:生產環境默認OpenShift不支持NFS持久存儲集群,要允許NFS在非生產集群上持久存儲,需要配置openshift_enable_unsupported_configurations=true。

4.2 container倉庫

要為OpenShift容器registry配置NFS持久性存儲,請將以下內容添加到Inventory文件中:
  1 openshift_hosted_registry_storage_kind=nfs
  2 openshift_hosted_registry_storage_nfs_directory=/exports
  3 openshift_hosted_registry_storage_volume_name=registry
  4 openshift_hosted_registry_storage_nfs_options='*(rw,root_squash)'
  5 openshift_hosted_registry_storage_volume_size=40G
  6 openshift_hosted_registry_storage_access_modes=['ReadWriteMany']

4.3 OpenShift Ansible Broker

OpenShift Ansible Broker(OAB)是一個容器化的OpenShift服務,部署自己的etcd服務。持久Etcd存儲所需的配置與registry所需的配置類似。
  1 openshift_hosted_etcd_storage_kind=nfs
  2 openshift_hosted_etcd_storage_nfs_directory=/exports
  3 openshift_hosted_etcd_storage_volume_name=etcd-vol2
  4 openshift_hosted_etcd_storage_nfs_options="*(rw,root_squash,sync,no_wdelay)"
  5 openshift_hosted_etcd_storage_volume_size=1G
  6 openshift_hosted_etcd_storage_access_modes=["ReadWriteOnce"]
  7 openshift_hosted_etcd_storage_labels={'storage': 'etcd'}

五 OpenShift其他配置

5.1 配置離線本地registry

本環境OpenShift使用容器倉庫為registry.lab.example.com,要將集群配置為從內部倉庫pull image,需要在Inventory中進行如下配置:

  1 #Modifications Needed for a Disconnected Install
  2 oreg_url=registry.lab.example.com/openshift3/ose-${component}:${version}
  3 #可訪問image倉庫的位置,必須以ose-${component}:${version}結尾。
  4 openshift_examples_modify_imagestreams=true
  5 #OpenShift安裝了用於部署示例應用程序的模板。這個變量指示playbook修改所有示例的IS,使其指向私有倉庫,而不是registry.access.redhat.com。
  6 openshift_docker_additional_registries=registry.lab.example.com
  7 #此變量用於將本地可訪問倉庫添加到每個節點上的docker配置中。
  8 openshift_docker_blocked_registries=registry.access.redhat.com,docker.io
  9 #此變量用於在OpenShift節點上配置docker的blocked_registries。
  1 #Image Prefix Modifications
  2 openshift_web_console_prefix=registry.lab.example.com/openshift3/oseopenshift_cockpit_deployer_prefix='registry.lab.example.com/openshift3/'
  3 openshift_service_catalog_image_prefix=registry.lab.example.com/openshift3/osetemplate_service_broker_prefix=registry.lab.example.com/openshift3/oseansible_service_broker_image_prefix=registry.lab.example.com/openshift3/oseansible_service_broker_etcd_image_prefix=registry.lab.example.com/rhel7/
#通過在容器image名稱前面加上registry.lab.example.com以確保OpenShift服務的容器image可以從私有內部倉庫下載。

5.2 配置NODE labels

節點label是分配給每個節點的任意key/value描述。node label通常用於區分地理數據中心或標識節點上的可用資源的有意義的描述。
應用程序可以在其deployment中根據node lables配置一個選擇器。如果匹配到,應用程序的pod必須部署在其符合node labels的節點上。
使用主機變量openshift_node_tags在Inventory文件中設置節點標簽。
  1 [nodes]
  2 ...output omitted...
  3 nodeX.example.com openshift_node_labels="{'zone':'west', 'gpu':'true'}"
  4 ...output omitted...
如上所示配置給nodeX.example.com配置兩個labels,zone=west和gpu=true。
OpenShift集群的一個常見架構是區分master、infrastructure node和compute node。
在此架構中,infrastructure node承載OpenShift Pod的registry和路由器,而compute node承載來自用戶項目的應用程序pod。
master節點不承載應用程序或infrastructure pod。
可使用 node label 來標識特定節點的角色,通常master node label 為 node-role.kubernetes.io/master=true,infrastructure node label 為 region=infra,compute node label 為 noderole.kubernetes.io/compute=true。
  1 [nodes]
  2 master.lab.example.com
  3 node1.lab.example.com openshift_node_labels="{'region':'infra'}"
  4 node2.lab.example.com
提示:如果一個節點設計為同時承載infrastructure 和 application pods,則必須顯式定義兩個節點標簽。
[nodes]
...
nodeX.example.com openshift_node_labels="{'region':'infra', 'noderole.kubernetes.io/compute':'true'}"
...

六 執行劇本

6.1 劇本說明

安裝OpenShift需要執行prerequisites.yml 和deploy_cluster.yml,由 atomic-openshift-utils 軟件包安裝。
首先執行 prequisites.yml playbook 檢查所有主機能夠滿足OpenShift 的部署,同時嘗試修改主機以滿足部署需求。然后執行 doploy_cluster.yml playbook 開始正式集群部署

6.2 驗證OpenShift

部署完成后,可訪問:https://master.lab.example.com 進行驗證。

七 正式安裝OpenShift

7.1 前置准備

[student@workstation ~]$ lab install-prepare setup
[student@workstation ~]$ sudo yum -y install ansible
[student@workstation ~]$ cd /home/student/do280-ansible/
[student@workstation do280-ansible]$ ansible-playbook playbooks/prepare_install.yml #設置相關環境
[student@workstation do280-ansible]$ lab install-run setup
[student@workstation do280-ansible]$ cd /home/student/DO280/labs/install-run/

7.2 安裝atomic

[student@workstation install-run]$ sudo yum -y install atomic-openshift-utils
提示:atomic-openshift-utils提供了安裝OpenShift所需的Ansible playbook和role。

7.3 創建Inventory

[student@workstation install-run]$ cp inventory.initial inventory
[student@workstation install-run]$ cat inventory
clipboard
[student@workstation install-run]$ echo -e "\n[OSEv3:vars]" >> inventory

7.4 配置相關安裝版本

  1 [student@workstation install-run]$ vi general_vars.txt
  2 #General Cluster Variables
  3 openshift_deployment_type=openshift-enterprise			#配置為openshift-enterprise版本
  4 openshift_release=v3.9						#配置版本為v3.9
  5 openshift_image_tag=v3.9.14
  6 openshift_disable_check=disk_availability,docker_storage,memory_availability	#禁用check

7.5 設置htpasswd認證

  1 [student@workstation install-run]$ openssl passwd -apr1 redhat
  2 $apr1$/d1L7fdX$duViLRE.JG012VkZDq8bs0
  3 [student@workstation install-run]$ openssl passwd -apr1 redhat
  4 $apr1$rUMMfQfD$J8CEqQK.YenyNwYwKN1lA1				#創建兩個用戶密碼都為redhat
  5 [student@workstation install-run]$ vi authentication_vars.txt
  6 #Cluster Authentication Variables
  7 openshift_master_identity_providers=[{'name': 'htpasswd_auth', 'login': 'true', 'challenge': 'true', 'kind': 'HTPasswdPasswordIdentityProvider', 'filename': '/etc/origin/master/htpasswd'}]
  8 openshift_master_htpasswd_users={'admin':'$apr1$/d1L7fdX$duViLRE.JG012VkZDq8bs0', 'developer':'$apr1$rUMMfQfD$J8CEqQK.YenyNwYwKN1lA1'}

7.6 配置集群網絡

  1 [student@workstation install-run]$ vi networking_vars.txt
  2 #OpenShift Networking Variables
  3 os_firewall_use_firewalld=true					#開啟firewall防火牆
  4 openshift_master_api_port=443					#啟用端口
  5 openshift_master_console_port=443				        #啟用控制端口
  6 openshift_master_default_subdomain=apps.lab.example.com		#指定subdomain

7.7 配置NFS

  1 [student@workstation install-run]$ vi persistence_vars.txt
  2 #NFS is an unsupported configuration
  3 openshift_enable_unsupported_configurations=true
  4 
  5 #OCR configuration variables
  6 openshift_hosted_registry_storage_kind=nfs
  7 openshift_hosted_registry_storage_access_modes=['ReadWriteMany']
  8 openshift_hosted_registry_storage_nfs_directory=/exports
  9 openshift_hosted_registry_storage_nfs_options='*(rw,root_squash)'
 10 openshift_hosted_registry_storage_volume_name=registry
 11 openshift_hosted_registry_storage_volume_size=40Gi
 12 
 13 #OAB's etcd configuration variables
 14 openshift_hosted_etcd_storage_kind=nfs
 15 openshift_hosted_etcd_storage_nfs_options="*(rw,root_squash,sync,no_wdelay)"
 16 openshift_hosted_etcd_storage_nfs_directory=/exports
 17 openshift_hosted_etcd_storage_volume_name=etcd-vol2
 18 openshift_hosted_etcd_storage_access_modes=["ReadWriteOnce"]
 19 openshift_hosted_etcd_storage_volume_size=1G
 20 openshift_hosted_etcd_storage_labels={'storage': 'etcd'}

7.8 配置離線倉庫

  1 #Modifications Needed for a Disconnected Install
  2 oreg_url=registry.lab.example.com/openshift3/ose-${component}:${version}	#添加內部倉庫
  3 openshift_examples_modify_imagestreams=true					#修改IS
  4 openshift_docker_additional_registries=registry.lab.example.com		#內部倉庫至docker配置
  5 openshift_docker_blocked_registries=registry.access.redhat.com,docker.io	#禁止外部官方倉庫
  6 #Image Prefixes
  7 openshift_web_console_prefix=registry.lab.example.com/openshift3/ose-
  8 openshift_cockpit_deployer_prefix='registry.lab.example.com/openshift3/'
  9 openshift_service_catalog_image_prefix=registry.lab.example.com/openshift3/ose-
 10 template_service_broker_prefix=registry.lab.example.com/openshift3/ose-
 11 ansible_service_broker_image_prefix=registry.lab.example.com/openshift3/ose-
 12 ansible_service_broker_etcd_image_prefix=registry.lab.example.com/rhel7/

7.9 設置label

[student@workstation install-run]$ vi inventory
  1 ……
  2 [nodes]
  3 master.lab.example.com
  4 node1.lab.example.com openshift_node_labels="{'region':'infra', 'node-role.kubernetes.io/compute':'true'}"
  5 node2.lab.example.com openshift_node_labels="{'region':'infra', 'node-role.kubernetes.io/compute':'true'}"

7.10 合並並校對Inventory

[student@workstation install-run]$ cat general_vars.txt networking_vars.txt authentication_vars.txt persistence_vars.txt disconnected_vars.txt >> inventory
[student@workstation install-run]$ lab install-run grade #本環境提供檢查Inventory的腳本
[student@workstation install-run]$ cat inventory
  1 [student@workstation install-run]$ cat general_vars.txt networking_vars.txt authentication_vars.txt persistence_vars.txt disconnected_vars.txt >> inventory
  2 [student@workstation install-run]$ lab install-run grade		#本環境提供檢查Inventory的腳本
  3 [student@workstation install-run]$ cat inventory
  4 [workstations]
  5 workstation.lab.example.com
  6 
  7 [nfs]
  8 services.lab.example.com
  9 
 10 [masters]
 11 master.lab.example.com
 12 
 13 [etcd]
 14 master.lab.example.com
 15 
 16 [nodes]
 17 master.lab.example.com
 18 node1.lab.example.com openshift_node_labels="{'region':'infra', 'node-role.kubernetes.io/compute':'true'}"
 19 node2.lab.example.com openshift_node_labels="{'region':'infra', 'node-role.kubernetes.io/compute':'true'}"
 20 
 21 [OSEv3:children]
 22 masters
 23 etcd
 24 nodes
 25 nfs
 26 
 27 #Variables needed by classroom host preparation playbooks.
 28 [nodes:vars]
 29 registry_local=registry.lab.example.com
 30 use_overlay2_driver=true
 31 insecure_registry=false
 32 run_docker_offline=true
 33 docker_storage_device=/dev/vdb
 34 
 35 
 36 [OSEv3:vars]
 37 #General Cluster Variables
 38 openshift_deployment_type=openshift-enterprise
 39 openshift_release=v3.9
 40 openshift_image_tag=v3.9.14
 41 openshift_disable_check=disk_availability,docker_storage,memory_availability
 42 #OpenShift Networking Variables
 43 os_firewall_use_firewalld=true
 44 openshift_master_api_port=443
 45 openshift_master_console_port=443
 46 openshift_master_default_subdomain=apps.lab.example.com
 47 #Cluster Authentication Variables
 48 openshift_master_identity_providers=[{'name': 'htpasswd_auth', 'login': 'true', 'challenge': 'true', 'kind': 'HTPasswdPasswordIdentityProvider', 'filename': '/etc/origin/master/htpasswd'}]
 49 openshift_master_htpasswd_users={'admin':'$apr1$/d1L7fdX$duViLRE.JG012VkZDq8bs0', 'developer':'$apr1$rUMMfQfD$J8CEqQK.YenyNwYwKN1lA1'}
 50 
 51 #NFS is an unsupported configuration
 52 openshift_enable_unsupported_configurations=true
 53 
 54 #OCR configuration variables
 55 openshift_hosted_registry_storage_kind=nfs
 56 openshift_hosted_registry_storage_access_modes=['ReadWriteMany']
 57 openshift_hosted_registry_storage_nfs_directory=/exports
 58 openshift_hosted_registry_storage_nfs_options='*(rw,root_squash)'
 59 openshift_hosted_registry_storage_volume_name=registry
 60 openshift_hosted_registry_storage_volume_size=40Gi
 61 
 62 #OAB's etcd configuration variables
 63 openshift_hosted_etcd_storage_kind=nfs
 64 openshift_hosted_etcd_storage_nfs_options="*(rw,root_squash,sync,no_wdelay)"
 65 openshift_hosted_etcd_storage_nfs_directory=/exports
 66 openshift_hosted_etcd_storage_volume_name=etcd-vol2
 67 openshift_hosted_etcd_storage_access_modes=["ReadWriteOnce"]
 68 openshift_hosted_etcd_storage_volume_size=1G
 69 openshift_hosted_etcd_storage_labels={'storage': 'etcd'}
 70 
 71 #Modifications Needed for a Disconnected Install
 72 oreg_url=registry.lab.example.com/openshift3/ose-${component}:${version}
 73 openshift_examples_modify_imagestreams=true
 74 openshift_docker_additional_registries=registry.lab.example.com
 75 openshift_docker_blocked_registries=registry.access.redhat.com,docker.io
 76 
 77 #Image Prefixes
 78 openshift_web_console_prefix=registry.lab.example.com/openshift3/ose-
 79 openshift_cockpit_deployer_prefix='registry.lab.example.com/openshift3/'
 80 openshift_service_catalog_image_prefix=registry.lab.example.com/openshift3/ose-
 81 template_service_broker_prefix=registry.lab.example.com/openshift3/ose-
 82 ansible_service_broker_image_prefix=registry.lab.example.com/openshift3/ose-
 83 ansible_service_broker_etcd_image_prefix=registry.lab.example.com/rhel7/

7.11 執行安裝劇本

[student@workstation install-run]$ ansible-playbook /usr/share/ansible/openshift-ansible/playbooks/prerequisites.yml
#執行准備工作playbook
clipboard
[student@workstation install-run]$ ansible-playbook /usr/share/ansible/openshift-ansible/playbooks/deploy_cluster.yml
clipboard
提示:整個部署log保存至本地目錄的ansible.log中。

八 驗證測試

8.1 確認驗證說明

要驗證OpenShift安裝,必須測試和驗證所有OpenShift組件。僅僅從示例容器映像啟動pod是不夠的,因為這並不使用OpenShift builders、deployer、router或內部registry。
  • 建議通過以下方式完整驗證OpenShift:
  • 檢查所有OpenShift節點狀態;
  • 檢查相應的OpenShift registry和router的pod;
  • 使用OpenShift從源代碼構建一個應用程序,OpenShift從構建結果生成容器image,並從該映像啟動pod;
  • 創建一個service,以便可以從內部容器網絡和OpenShift節點訪問應用程序;
  • 創建一個route,以便可以從OpenShift集群外部的計算機訪問應用程序。
安裝完成后,OpenShift客戶端可以使用oc,master節點可以使用oadm命令。master節點的root用戶將被配置為雲管理員的身份運行OpenShift客戶機和管理員命令。
一些OpenShift內部服務,如內部倉庫和router,默認情況下由安裝程序配置。運行oc get nodes和oc get pods命令,以驗證安裝成功。

8.2 登錄測試

瀏覽器訪問:https://master.lab.example.com
clipboard
clipboard

8.3 驗證OpenShift功能

[student@workstation ~]$ oc login -uadmin -predhat https://master.lab.example.com
clipboard
提示:賬號權限需要單獨授予,安裝過程中創建的adminn並沒有集群的administration特權。

8.4 授予權限

system:admin是唯一一個擁有集群administration權限的賬戶。master節點的root用戶被都為集群的system:admin用戶。
[root@master ~]# oc whoami
system:admin
[root@master ~]# oc adm policy add-cluster-role-to-user cluster-admin admin #添加admin為集群管理員
提示:cluster-admin角色權限非常高,允許管理用戶銷毀和修改集群資源,必須謹慎使用。

8.5 查看節點狀態

再次使用命令登錄。
[student@workstation ~]$ oc login -uadmin -predhat https://master.lab.example.com
clipboard
[student@workstation ~]$ oc get nodes
NAME STATUS ROLES AGE VERSION
master.lab.example.com Ready master 14h v1.9.1+a0ce1bc657
node1.lab.example.com Ready compute 14h v1.9.1+a0ce1bc657
node2.lab.example.com Ready compute 14h v1.9.1+a0ce1bc657
[student@workstation ~]$ oc get pods
NAME READY STATUS RESTARTS AGE
docker-registry-1-4w5tb 1/1 Running 1 14h
docker-registry-1-j7k59 1/1 Running 1 14h
registry-console-1-mtkxc 1/1 Running 1 14h
router-4-9dfxc 1/1 Running 0 4h
router-4-kh7th 1/1 Running 0 5h

8.6 創建項目

[student@workstation ~]$ oc new-project smoke-test

8.7 創建應用

[student@workstation ~]$ oc new-app --name=hello -i php:7.0 http://registry.lab.example.com/php-helloworld
[student@workstation ~]$ oc get pods -w #監視pod創建

8.8 查看route

[student@workstation ~]$ oc get routes
NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD
hello hello-smoke-test.apps.lab.example.com hello 8080-tcp None

8.9 公開服務

[student@workstation ~]$ oc expose service hello #向外部網絡公開服務

8.10 測試服務

[student@workstation ~]$ curl http://hello-smoke-test.apps.lab.example.com
Hello, World! php version is 7.0.10
[student@workstation ~]$ oc delete project install-post #刪除項目

8.11 測試developer

[student@workstation ~]$ oc login -u developer #使用redhat密碼登錄
[student@workstation ~]$ oc new-project smoke-test
[student@workstation ~]$ oc new-app php:5.6~http://services.lab.example.com/php-helloworld --name hello
[student@workstation ~]$ oc logs -f bc/hello #監視構建過程
提示:輸出表明OpenShift能夠從倉庫clone代碼、並且構建image,同時將新image推入內部倉庫。
[student@workstation ~]$ oc expose svc hello
route "hello" exposed
[student@workstation ~]$ oc get routes
NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD
hello hello-smoke-test.apps.lab.example.com hello 8080-tcp None
[student@workstation ~]$ curl hello-smoke-test.apps.lab.example.com
Hello, World! php version is 5.6.25


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM