OpenShift 3.9 多节点集群(Ansible)安装

OpenShift集群的部署可以分为以下几个阶段:

1、主机环境准备:准备OpenShift集群需要的主机,并进行集群环境准备。

2、安装依赖包:提前安装使用Ansible安装OpenShift集群所依赖的第三方包。

3、Ansible执行安装:使用Ansible Playbook进行自动化安装。

4、OpenShift系统配置:在使用Ansible执行安装完成之后的系统配置。

5、测试问题处理

 


一、主机环境准备

类型

主机名(域名)

IP

操作系统

内存

磁盘

Master

master.192.168.40.161.nip.io

192.168.40.161

CentOS7.5

2G

sda:10G for OS

sdb:20G for docker

Node

node1.192.168.40.162.nip.io

192.168.40.162

CentOS7.5

2G

sda:10G for OS

sdb:20G for docker

Node

node2.192.168.40.163.nip.io

192.168.40.163

CentOS7.5

2G

sda:10G for OS

sdb:20G for docker

 

说明:在安装的过程中,使用了nip.io结尾的域名,关于nip.io的问题,请查阅 nip.io 网站 。

 

1、检查主机与Internet的状态

由于在安装的过程中需要通过Internet下载相关依赖,因此需要检查三台主机与Internet的状态。

 

2、检查主机名

按照上面表格中所列的主机名进行主机名检查。如果不一致,可以通过下面的命令进行配置,如下:

hostnamectl set-hostname master.192.168.40.161.nip.io

 

3、检查主机名(域名)的解析是否正常

可以通过 ping $(hostname)来验证主机名到主机IP的解析情况。

如果出现不能ping通的情况,可以直接修改各个节点的 /etc/hosts 文件,加上静态的域名解析。

 

此外由于使用的是nip.io的域名,正常的DNS都能够解析到正确的IP地址;但是在输入命令的过程中使用全域名会很麻烦,因此在hosts中添加了主机名的缩写配置,如下:

192.168.40.161 master

192.168.40.162 node1

192.168.40.163 node2

 

4、检查SELINUX是否开启

官方文档推荐开启SELINUX,否则会导致安装失败。

修改方式如下:

/etc/selinux/config

SELINUX=enforcing

SELINUXTYPE=targeted

 

5、配置三台主机ssh免密访问

5.1)在所有节点上以root账号登陆,并进入到/root的主目录

[[email protected] ~]$ pwd

/root

[[email protected] ~]$

 

5.2)在所有节点上生成**对。

[[email protected] ~]$ ssh-****** -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/home/.ssh/id_rsa):

Created directory '/home/.ssh'.

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/.ssh/id_rsa.

Your public key has been saved in /home/.ssh/id_rsa.pub.

The key fingerprint is:

29:1c:df:59:0d:5f:ee:28:07:c0:57:21:15:af:a3:88 [email protected]

The key's randomart image is:

+--[ RSA 2048]----+

| .. oo=o.|

| ...= + |

| . .o o o|

| . o o o . + |

| o S o . = .|

| . . . + . |

| E . . |

| |

| |

+-----------------+

[[email protected] ~]$

 

5.3)然后进入.ssh目录,把公钥复制到authorized_keys

[[email protected] ~]$ cd .ssh

[[email protected] .ssh]$ ls

id_rsa id_rsa.pub

[[email protected] .ssh]$ cp id_rsa.pub authorized_keys

 

5.4)分发ssh公钥到各个节点

先将node1和node2的公钥添加到master节点的authorized_keys文件中。

[[email protected] .ssh]$ ssh-copy-id master

[root@node2 .ssh]$ ssh-copy-id master

最后再使用scp将master中的authorized_keys文件传送到各个节点。

 

此处,需要注意.ssh(755)及.ssh/authorized_keys(644)的权限。 

 

 


二、安装依赖包

1、所有主机上执行以下命令进行系统更新

yum install -y update

安装完成之后,重新系统生效。

 

2、所有的主机下执行以下命令安装OpenShift依赖的软件包。

yum install wget git net-tools bind-utils iptables-services bridge-utils bash-completion kexec-tools sos psacct bash-completion.noarch bash-completion-extras.noarch python-passlib NetworkManager -y

 

3、所有的主机安装docker

yum install docker-1.13.1 -y

 

4、配置docker使用的存储

echo DEVS=/dev/sdb > /etc/sysconfig/docker-storage-setup

echo VG=DOCKER >> /etc/sysconfig/docker-storage-setup

echo SETUP_LVM_THIN_POOL=yes >> /etc/sysconfig/docker-storage-setup

echo DATA_SIZE="100%FREE">> /etc/sysconfig/docker-storage-setup

 

rm -rf /var/lib/docker

 

wipefs --all /dev/sdb

docker-storage-setup

 

5、配置docker镜像加速

选择阿里云的镜像服务器进行加速,修改 /etc/docker/daemon.json 文件,如下所示:

[[email protected] ~]# more /etc/docker/daemon.json

{

"registry-mirrors": ["https://换成自己的地址.mirror.aliyuncs.com"]

}

配置完成之后,所有主机启动docker,命令如下:

systemctl enable docker

systemctl start docker

 


三、在Master主机上执行Ansible集群安装

1、启用EPEL仓库以安装Ansible

#install epel

yum -y install epel-release

 

# Disable the EPEL repository globally so that is not accidentally used during later steps of the installation

sed -i -e "s/^enabled=1/enabled=0/" /etc/yum.repos.d/epel.repo

 

yum -y --enablerepo=epel install ansible pyOpenSSL #3.9必须2.5版本

2、从 github 上clone openshift-ansible 3.9版本

git clone -b release-3.9 https://github.com/openshift/openshift-ansible

说明:最近通过本blog重新安装openshift集群时,发现总是出现各种各样的问题,如 /etc/dnsmasq.d/origin-upstream-dns.conf 、/etc/origin/node/resolv.conf 等文件缺失,因此将原来从github上clone源代码,修改为下载已经release的版本。

 

2、从github上下载openshift-ansible已经release的版本

wget https://github.com/openshift/openshift-ansible/archive/openshift-ansible-3.9.32-1.zip

下载完成之后,进行解压并重命为 openshift-ansible。

 

3、修改软件源

由于目前OpenShift-ansible还没有添加3.9的源,所以需要自行修改下,方法如下:

  • 进行openshift-ansible/roles/openshift_repos/templates/ 复制一份 CentOS-OpenShift-Origin37.repo.j2 为 CentOS-OpenShift-Origin39.repo.j2。
  • 修改CentOS-OpenShift-Origin39.repo.j2中的源修改为国内的,比如阿里云。

[centos-openshift-origin39]

name=CentOS OpenShift Origin

baseurl=http://mirrors.aliyun.com/centos/7/paas/x86_64/openshift-origin39/

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-PaaS

 

[centos-openshift-origin39-testing]

name=CentOS OpenShift Origin Testing

baseurl=http://buildlogs.centos.org/centos/7/paas/x86_64/openshift-origin39/

enabled={{ 1 if openshift_repos_enable_testing else 0 }}

gpgcheck=0

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-PaaS

 

[centos-openshift-origin39-debuginfo]

name=CentOS OpenShift Origin DebugInfo

baseurl=http://debuginfo.centos.org/centos/7/paas/x86_64/

enabled=0

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-PaaS

 

[centos-openshift-origin39-source]

name=CentOS OpenShift Origin Source

baseurl=http://vault.centos.org/centos/7/paas/Source/openshift-origin39/

enabled=0

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-PaaS

 

4、配置 ansible inventory 文件,保存到 /etc/ansible/inventory.ini文件中。

# 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

#使用origin社区版

openshift_deployment_type=origin

#指定安装版本

openshift_release=3.9

 

#指定默认域名,访问的时候需要使用该域名,没有dns服务器,需要手动添加本地hosts文件

openshift_master_default_subdomain=apps.192.168.40.161.nip.io

 

#禁止磁盘、内存和镜像检查

openshift_disable_check=disk_availability,docker_storage,memory_availability,docker_image_availability

 

#disk_availability:报错信息是推荐的master磁盘空间剩余量大于40GB。测试环境无法满足,跳过检测。

#memory_availability:报错信息是推荐的master内存为16GB,node内存为8GB,测试环境无法满足,跳过检测。

#docker_image_availability:报错信息是需要的几个镜像未找到,选择跳过,装完集群后,在使用的时候再自行下载。

#docker_storage:报错信息是推荐选择一块磁盘空间存储镜像,这里选择跳过。采用docker默认的方式存储镜像。

 

 

# 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'}]

 

#ntp时间同步

openshift_clock_enabled=true

 

#节点配额

openshift_node_kubelet_args={'pods-per-core': ['10']}

 

# host group for masters

[masters]

master openshift_schedulable=True

 

# host group for nodes, includes region info

[nodes]

master openshift_node_labels="{'region': 'infra'}"

node1 openshift_node_labels="{'region': 'infra', 'zone': 'default'}"

node2 openshift_node_labels="{'region': 'infra', 'zone': 'default'}"

 

[etcd]

master

5、修改脚本问题

openshift-ansible/roles/lib_utils/filter_plugins/openshift_master.py 的第487行

OpenShift 3.9 多节点集群(Ansible)安装

注释掉图片中框出来的两行。

 

6、开始安装

ansible-playbook -i /etc/ansible/inventory.ini openshift-ansible/playbooks/prerequisites.yml

ansible-playbook -i /etc/ansible/inventory.ini openshift-ansible/playbooks/deploy_cluster.yml

安装过程是完全自动化的,无需手动干预。在绝大多数情况下,Ansible的脚本Playbook是可以反复执行的。

第一条语句的运行结果:

OpenShift 3.9 多节点集群(Ansible)安装

第二条语句的运行结果:

OpenShift 3.9 多节点集群(Ansible)安装

 

7、检查

安装完成后,执行oc get nodes 检查当前集群的成员列表以及它们的状态。

OpenShift 3.9 多节点集群(Ansible)安装

其实在安装完成之后 第二个节点和第三个节点的roles类型为空,需要将其打上compute标签,命令如下:

oc label node node1.192.168.40.162.nip.io node-role.kubernetes.io/compute=true

 

 


四、OpenShift系统配置

1、创建用户

安装的时候,在Ansible的hosts文件中定义了HTPasswd文件作为后端的用户身份信息库。

 

安装程序自动生成了数据文件/etc/origin/master/htpasswd。但是此时该文件还是一个空文件,并没有任何用户信息。

 

需要通过htpasswd命令来创建用户。创建账号为dev密码为dev的用户。

[[email protected] ~]# htpasswd -b /etc/origin/master/htpasswd dev dev

 

2、给dev添加集群管理员权限

oc adm policy add-cluster-role-to-user cluster-admin dev

 

4、重启服务

systemctl restart origin-master-api

 

5、访问页面https://master.192.168.40.161.nip.io:8443

OpenShift 3.9 多节点集群(Ansible)安装

 

 


五、测试过程中的问题处理

1、无法通过github下载源代码

Cloning "https://github.com/gshipley/simplephp.git " ...

error: fatal: unable to access 'https://github.com/gshipley/simplephp.git/': Peer's certificate issuer has been marked as not trusted by the user.

解决方法:

原因是在 /etc/resolv.conf 中多了search *** (专业术语:FQDN),将其注释掉即可,但是当NetworkManager服务重新启动之后,之前的配置又会被覆盖,方法如下:

chattr +i /etc/resolv.conf

 

2、无法进行docker的注册

error: build error: Failed to push image: After retrying 6 times, Push image still failed due to error: Get https://docker-registry.default.svc:5000/v1/_ping: dial tcp 192.168.40.163:5000: getsockopt: connection refused

解决方法:

通过观察docker-registry的pod界面可知

OpenShift 3.9 多节点集群(Ansible)安装

 

,其绑定的IP地址为 172.30.135.115,因此在 /etc/hosts 中添加了

OpenShift 3.9 多节点集群(Ansible)安装