Openshift-生产环境部署

生产环境安装openshift

主机类型 主机名 IP地址 操作系统
Master节点 master.example.com 192.168.172.168 Centos 7.2
Node节点 node1.example.com 192.168.172.169 Centos 7.2
Node节点 node2.example.com 192.168.172.170 Centos 7.2

1.配置主机名

hostnamectl set-hostname master.example.com
配置相关域名解析,使主机名可解析到对应ip地址

192.168.172.168  master.example.com  
192.168.172.169  node1.example.com  
192.168.172.170  node2.example.com  

所有节点设置网络
查看网络链接
nmcli con show 打开链接
nmcli con up eth0
设置开机自启动
nmcli con mod eth0 connection.autoconnect yes
重启网络服务
systemctl restart NetworkManager

2.安装及配置软件包

所有节点安装openshift依赖软件包
yum install -y wget git net-tools bind-utils iptables-services bridge-utils bash-completion
所有节点安装容器引擎docker
yum install -y docker
修改配置存储
vim /etc/sysconfig/docker-storage-setup
添加 ENVS=/dev/sdb 执行docker-storage-setup

在Master节点启动EPEL安装ansible

yum -y install https://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm  
sed -i -e "s/^enabled=1/enabled=0/" /etc/yum.repos.d/epel.repo  
yum -y --enablerepo=epel install ansible pyopenSSL  

在Master节点生成SSH密钥
ssh-keygen -f /root/.ssh/id_rsa -N ''

Ansible基于Agentless架构实现,不需要在目标主机安装agent依赖ssh远程控制协议,所以需要配置master和node节点互信
在Master节点执行:

for host in master.example.com \
node1.example.com \
node2.example.com; \
do ssh-copy-id -i ~/.ssh/id_rsa.pub $host; \
done

在Master节点安装Openshift的ansible Playbook

wget https://github.com/openshift/openshift-ansible/archive/openshift-ansible-3.3.26-1.tar.gz  
tar zxf openshift-ansible-3.3.26-1.tar.gz  

安装单master可以不单独安装etcd,这里选择安装单节点的etcd,生产环境安装3节点的etcd集群,确保高可用

yum install -y etcd  
systemctl enable etcd  
systemctl start etcd  

配置ansible

备份原有ansible的host
cp /etc/ansible/hosts /etc/ansible/hosts-bk
修改hosts:

[OSEv3:children]
masters
nodes
etcd

[OSEv3:vars]
ansible_ssh_user=root
openshift_deployment_type=origin
openshift_release=1.3.0

openshift_master_identity_providers=[{'name': 'htpasswd_auth', 'login': 'true', 'challenge': 'true', 'kind': 'HTPasswdPasswordIdentityProvider', 'filename': '/etc/origin/master/htpasswd'}]

[masters]
openshift-test-master

[nodes]
master.example.com  
node1.example.com  
node2.example.com

[etcd]
openshift-test-master

执行安装
ansible-playbook ~/openshift-ansible-3.3.26-1/playbooks/byo/config.yml

执行完成以后,通过oc get node 查看节点状态

基础安装完毕以后,进行组件和功能的配置

  • 对接用户身份信息库
  • 导入Image Stream
  • 导入Template
  • 部署Router
  • 部署Registry
  • 部署度量收集组件
  • 部署日志聚合组件

用户身份信息库:
openshift_master_identity_providers=[{'name': 'htpasswd_auth', 'login': 'true', 'challenge': 'true', 'kind': 'HTPasswdPasswordIdentityProvider', 'filename': '/etc/origin/master/htpasswd'}]
定义了文件/etc/origin/master/htpasswd作为用户身份信息库,我们通过htpasswd -b /etc/origin/master/htpasswd dev dev来创建用户

is和template用ansible部署时默认已经部署上了

Router部署
Router是以容器的形式运行在Openshift平台,默认情况不知道容器运行在哪个node上
为node打上标签(Label),然后通过节点选择器(NodeSelector)指定容器运行的node
oc label node node1.example.com infra=yes
查看node节点
oc get node --show-labels
为Router使用的Service Account赋权

oadm policy add-scc-to-user privileged system:serviceaccount:default:router
oadm policy add-cluster-role-to-user cluster-reader system:serviceaccount:default:router

部署router
oadm router ose-router --replicas=1 --service-account=router --selector='infra=yes'

Registry部署
oadm registry --config='/etc/origin/master/admin.kubeconfig' --service-account=registry --selector='infra=yes' -n default

查看pod
oc get pod -n default|grep registry

打赏一个呗

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦