主頁 > 作業系統 > 002.OpenShift安裝與部署

002.OpenShift安裝與部署

2020-09-16 04:05:22 作業系統

一 前置條件說明

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

轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/52923.html

標籤:Linux

上一篇:k8s:py專案發布完整流程

下一篇:003.OpenShift網路

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • CA和證書

    1、在 CentOS7 中使用 gpg 創建 RSA 非對稱密鑰對 gpg --gen-key #Centos上生成公鑰/密鑰對(存放在家目錄.gnupg/) 2、將 CentOS7 匯出的公鑰,拷貝到 CentOS8 中,在 CentOS8 中使用 CentOS7 的公鑰加密一個檔案 gpg -a ......

    uj5u.com 2020-09-10 00:09:53 more
  • Kubernetes K8S之資源控制器Job和CronJob詳解

    Kubernetes的資源控制器Job和CronJob詳解與示例 ......

    uj5u.com 2020-09-10 00:10:45 more
  • VMware下安裝CentOS

    VMware下安裝CentOS 一、軟硬體準備 1 Centos鏡像準備 1.1 CentOS鏡像下載地址 下載地址 1.2 CentOS鏡像下載程序 點擊下載地址進入如下圖的網站,選擇需要下載的版本,這里選擇的是Centos8,點擊如圖所示。 決定選擇Centos8后,選擇想要的鏡像源進行下載,此 ......

    uj5u.com 2020-09-10 00:12:10 more
  • 如何使用Grep命令查找多個字串

    如何使用Grep 命令查找多個字串 大家好,我是良許! 今天向大家介紹一個非常有用的技巧,那就是使用 grep 命令查找多個字串。 簡單介紹一下,grep 命令可以理解為是一個功能強大的命令列工具,可以用它在一個或多個輸入檔案中搜索與正則運算式相匹配的文本,然后再將每個匹配的文本用標準輸出的格式 ......

    uj5u.com 2020-09-10 00:12:28 more
  • git配置http代理

    git配置http代理 經常遇到克隆 github 慢的問題,這里記錄一下幾種配置 git 代理的方法,解決 clone github 過慢。 目錄 git配置代理 git單獨配置github代理 git配置全域代理 配置終端環境變數 git配置代理 主要使用 git config 命令 git單獨 ......

    uj5u.com 2020-09-10 00:12:33 more
  • Linux npm install 裝包時提示Error EACCES permission denied解

    npm install 裝包時提示Error EACCES permission denied解決辦法 ......

    uj5u.com 2020-09-10 00:12:53 more
  • Centos 7下安裝nginx,使用yum install nginx,提示沒有可用的軟體包

    Centos 7下安裝nginx,使用yum install nginx,提示沒有可用的軟體包。 18 (flaskApi) [root@67 flaskDemo]# yum -y install nginx 19 已加載插件:fastestmirror, langpacks 20 Loading ......

    uj5u.com 2020-09-10 00:13:13 more
  • Linux查看服務器暴力破解ssh IP

    在公網的服務器上經常遇到別人爆破你服務器的22埠,用來挖礦或者干其他嘿嘿嘿的事情~ 這種情況下正確的做法是: 修改默認ssh的22埠 使用設定密鑰登錄或者白名單ip登錄 建議服務器密碼為復雜密碼 創建普通用戶登錄服務器(root權限過大) 建立堡壘機,實作統一管理服務器 統計爆破IP [root ......

    uj5u.com 2020-09-10 00:13:17 more
  • CentOS 7系統常見快捷鍵操作方式

    Linux系統中一些常見的快捷方式,可有效提高操作效率,在某些時刻也能避免操作失誤帶來的問題。 ......

    uj5u.com 2020-09-10 00:13:31 more
  • CentOS 7作業系統目錄結構介紹

    作業系統存在著大量的資料檔案資訊,相應檔案資訊會存在于系統相應目錄中,為了更好的管理資料資訊,會將系統進行一些目錄規劃,不同目錄存放不同的資源。 ......

    uj5u.com 2020-09-10 00:13:35 more
最新发布
  • vim的常用命令

    Vim的6種基本模式 1. 普通模式在普通模式中,用的編輯器命令,比如移動游標,洗掉文本等等。這也是Vim啟動后的默認模式。這正好和許多新用戶期待的操作方式相反(大多數編輯器默認模式為插入模式)。 2. 插入模式在這個模式中,大多數按鍵都會向文本緩沖中插入文本。大多數新用戶希望文本編輯器編輯程序中一 ......

    uj5u.com 2023-04-20 08:43:21 more
  • vim的常用命令

    Vim的6種基本模式 1. 普通模式在普通模式中,用的編輯器命令,比如移動游標,洗掉文本等等。這也是Vim啟動后的默認模式。這正好和許多新用戶期待的操作方式相反(大多數編輯器默認模式為插入模式)。 2. 插入模式在這個模式中,大多數按鍵都會向文本緩沖中插入文本。大多數新用戶希望文本編輯器編輯程序中一 ......

    uj5u.com 2023-04-20 08:42:36 more
  • docker學習

    ###Docker概述 真實專案部署環境可能非常復雜,傳統發布專案一個只需要一個jar包,運行環境需要單獨部署。而通過Docker可將jar包和相關環境(如jdk,redis,Hadoop...)等打包到docker鏡像里,將鏡像發布到Docker倉庫,部署時下載發布的鏡像,直接運行發布的鏡像即可。 ......

    uj5u.com 2023-04-19 09:26:53 more
  • 設定Windows主機的瀏覽器為wls2的默認瀏覽器

    這里以Chrome為例。 1. 準備作業 wsl是可以使用Windows主機上安裝的exe程式,出于安全考慮,默認情況下改功能是無法使用。要使用的話,終端需要以管理員權限啟動。 我這里以Windows Terminal為例,介紹如何默認使用管理員權限打開終端,具體操作如下圖所示: 2. 操作 wsl ......

    uj5u.com 2023-04-19 09:25:49 more
  • docker學習

    ###Docker概述 真實專案部署環境可能非常復雜,傳統發布專案一個只需要一個jar包,運行環境需要單獨部署。而通過Docker可將jar包和相關環境(如jdk,redis,Hadoop...)等打包到docker鏡像里,將鏡像發布到Docker倉庫,部署時下載發布的鏡像,直接運行發布的鏡像即可。 ......

    uj5u.com 2023-04-19 09:19:04 more
  • Linux學習筆記

    IP地址和主機名 IP地址 ifconfig可以用來查詢本機的IP地址,如果不能使用,可以通過install net-tools安裝。 Centos系統下ens33表示主網卡;inet后表示IP地址;lo表示本地回環網卡; 127.0.0.1表示代指本機;0.0.0.0可以用于代指本機,同時在放行設 ......

    uj5u.com 2023-04-18 06:52:01 more
  • 解決linux系統的kdump服務無法啟動的問題

    問題:專案麒麟系統服務器的kdump服務無法啟動,沒有相關日志無法定位問題。 1、查看服務狀態是關閉的,重啟系統也無法啟動 systemctl status kdump 2、修改grub引數,修改“crashkernel”為“512M(有的機器數值太大太小都會導致報錯,建議從128M開始試,或者加個 ......

    uj5u.com 2023-04-12 09:59:50 more
  • 解決linux系統的kdump服務無法啟動的問題

    問題:專案麒麟系統服務器的kdump服務無法啟動,沒有相關日志無法定位問題。 1、查看服務狀態是關閉的,重啟系統也無法啟動 systemctl status kdump 2、修改grub引數,修改“crashkernel”為“512M(有的機器數值太大太小都會導致報錯,建議從128M開始試,或者加個 ......

    uj5u.com 2023-04-12 09:59:01 more
  • 你是不是暴露了?

    作者:袁首京 原創文章,轉載時請保留此宣告,并給出原文連接。 如果您是計算機相關從業人員,那么應該經歷不止一次網路安全專項檢查了,你肯定是收到過資訊系統技術檢測報告,要求你加強風險監測,確保你提供的系統服務堅實可靠了。 沒檢測到問題還好,檢測到問題的話,有些處理起來還是挺麻煩的,尤其是線上正在運行的 ......

    uj5u.com 2023-04-05 16:52:56 more
  • 細節拉滿,80 張圖帶你一步一步推演 slab 記憶體池的設計與實作

    1. 前文回顧 在之前的幾篇記憶體管理系列文章中,筆者帶大家從宏觀角度完整地梳理了一遍 Linux 記憶體分配的整個鏈路,本文的主題依然是記憶體分配,這一次我們會從微觀的角度來探秘一下 Linux 內核中用于零散小記憶體塊分配的記憶體池 —— slab 分配器。 在本小節中,筆者還是按照以往的風格先帶大家簡單 ......

    uj5u.com 2023-04-05 16:44:11 more