用ansible2.5在Centos7.2上部署OpenShift3.9,转

1.环境:

主机名 ip 角色

master 10.2.1.198 master

node1 10.2.1.174 node

node2 10.2.1.165 node

在每一台的hosts添加解析记录

2.selinux

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

修改方式如下:

/etc/selinux/config

SELINUX=enforcing

SELINUXTYPE=targeted

3.在所有节点上生成密钥对

在master能免密码登录node1 ,node2

4.装依赖包

yum install -y update

重启后装包

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

5.安装docker

yum install docker-1.13.1 -y

6.配置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

7.配置docker镜像加速

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

[root@master ~]# more /etc/docker/daemon.json

{

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

}

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

systemctl enable docker

systemctl start docker

8.用tar.gz安装ansible, #3.9必须2.5版本

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 install pyOpenSSL

9.从github上下载openshift-ansible已经release的版本

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

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

10.修改软件源

由于目前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

11.配置 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

12.

修改脚本问题

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

注释掉红框中两行

用ansible2.5在Centos7.2上部署OpenShift3.9,转

13.开始安装

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

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

oc get nodes

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

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