李锋镝的博客

  • 首页
  • 时间轴
  • 说说
  • 读书观影
  • 系列
  • AI工具集
  • 论坛
  • 友圈
    • 友链
    • 朋友圈
    • 游客中心
  • 留言
    • 留言
    • 走心评论
  • 关于
    • 关于本站
    • Now
    • 每日心情
    • 网站地图
    • 网站统计
    • 赞助
  • 星球穿梭
  • 🚇开往
静亦定 动亦定
惟坚韧者始能遂其志
  1. 首页
  2. 原创
  3. 正文

使用OpenShift搭建k8s集群

2020年4月16日 254 0 2
本文最后更新于 2020年4月16日,距今已 2395 天,其中的信息可能已经发生变化,请注意甄别。

硬件准备

服务器 hostname
192.168.30.170 master-test-k8s
192.168.30.171 node1-test-k8s
192.168.30.172 node2-test-k8s
192.168.30.173 node3-test-k8s
192.168.30.174 node4-test-k8s
192.168.30.175 infra1-test-k8s
192.168.30.176 infra2-test-k8s

初始化配置

以下如无特殊说明则只安装master节点

Hosts配置

[root@localhost ~]# vim /etc/hosts
192.168.30.171 master-test-k8s
192.168.30.170 node1-test-k8s
192.168.30.172 node2-test-k8s
192.168.30.173 node3-test-k8s
192.168.30.174 node4-test-k8s
192.168.30.175 infra1-test-k8s
192.168.30.176 infra2-test-k8s

修改主机名(所有节点)

[root@localhost ~]# hostnamectl set-hostname master-test-k8s

关闭防火墙

# 如果安装过程中有提示,则修改对应的SELINUX,否则不需要修改
[root@localhost ~]# vim /etc/selinux/config
SELINUX=permissive
SELINUXTYPE=targeted

# 关闭防火墙
[root@localhost ~]# systemctl stop firewalld && systemctl disable firewalld

免密钥登录

[root@localhost ~]# ssh-keygen -b 4096 -f ~/.ssh/id_rsa -N ""
[root@localhost ~]# cat ~/.ssh/id_rsa.pub | tee -a ~/.ssh/authorized_keys
[root@localhost ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub <user>@<node_ip_address>

安装基础包

[root@localhost ~]# yum install wget git net-tools bind-utils yum-utils iptables-services bridge-utils bash-completion kexec-tools sos psacct glusterfs-fuse -y
[root@localhost ~]# yum update
[root@localhost ~]# reboot

到这一步出问题了,reboot之后一直连不上服务器了,原因是SELINUX=enforcing之后导致的。

安装docker(所有节点都安装)

[root@localhost ~]# yum install docker-1.13.1 -y
[root@localhost ~]# rpm -V docker-1.13.1
[root@localhost ~]# docker version
# systemctl enable docker 设置docker开机启动
[root@localhost ~]# systemctl start docker

安装 epel 套件

[root@localhost ~]# yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@localhost ~]# yum -y --enablerepo=epel install pyOpenSSL

安装指定版本的ansible

[root@localhost ~]# yum --showduplicates list ansible
[root@localhost ~]# yum install ansible-2.7.4-1.el7ae -y
[root@localhost ~]# ansible --version
ansible 2.9.6
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Aug  7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]

准备高可用部署

# 在两台infra节点上进行
[root@localhost ~]# yum -y install keepalived

# 第一个infra节点
# 直接删除原内容 使用下边的替换
[root@localhost ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state MASTER
    interface enp3s0
    virtual_router_id 55
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 123456
    }
    virtual_ipaddress {
        192.168.30.176
    }
}

# 第二个infra节点
[root@localhost ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state BACKUP
    interface enp3s0
    virtual_router_id 55
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 123456
    }
    virtual_ipaddress {
        192.168.30.176
    }
}
# 在两个基础设施节点上都启用并启动 Keepalived:
[root@localhost ~]# systemctl enable keepalived
[root@localhost ~]# systemctl start keepalived
[root@localhost ~]# journalctl -u keepalived

# 查看运行状态
[root@infra1 ~]# ps -ef|grep keep
root      1635     1  0 14:58 ?        00:00:00 /usr/sbin/keepalived -D
root      1636  1635  0 14:58 ?        00:00:00 /usr/sbin/keepalived -D
root      1637  1635  0 14:58 ?        00:00:00 /usr/sbin/keepalived -D
root      1693  1589  0 14:59 pts/0    00:00:00 grep --color=auto keep
[root@infra1 ~]# ip address show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 34:97:f6:87:6f:a3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.30.175/22 brd 192.168.31.255 scope global noprefixroute enp3s0
       valid_lft forever preferred_lft forever
    inet 192.168.30.176/32 scope global enp3s0
       valid_lft forever preferred_lft forever
    inet6 fe80::727c:db96:f863:82c1/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

OpenShift安装配置文件准备

# 使用 Openshift-ansible 安裝方式
[root@master-test-k8s ~]# cd ~
[root@master-test-k8s ~]# git clone https://github.com/openshift/openshift-ansible
[root@master-test-k8s ~]# cd openshift-ansible
[root@master-test-k8s ~]# git checkout release-3.11

[root@master-test-k8s ~]# pwd
/root/openshift-ansible/inventory
[root@master-test-k8s ~]# cp hosts.example hosts

# 编辑配置文件
[masters]
master-test-k8s

[etcd]
master-test-k8s

[nodes]
master-test-k8s openshift_node_group_name="node-config-master"
infra1-test-k8s openshift_node_group_name="node-config-infra"
infra2-test-k8s openshift_node_group_name="node-config-infra"
node1-test-k8s openshift_node_group_name="node-config-compute"
node2-test-k8s openshift_node_group_name="node-config-compute"
node3-test-k8s openshift_node_group_name="node-config-compute"
node4-test-k8s openshift_node_group_name="node-config-compute"

[nfs]
master-test-k8s

[lb]
infra1-test-k8s
infra2-test-k8s

# Create an OSEv3 group that contains the masters and nodes groups
[OSEv3:children]
masters
nodes
etcd
lb
nfs

[OSEv3:vars]
ansible_user=root

openshift_deployment_type=origin
openshift_release="3.11"

openshift_master_default_subdomain=infra1-test-k8s
openshift_master_cluster_method=native

openshift_master_cluster_hostname=infra1-test-k8s
openshift_master_cluster_public_hostname=infra1-test-k8s

debug_level=2

openshift_master_identity_providers=[{'name': 'htpasswd_auth', 'login': 'true', 'challenge': 'true', 'kind': 'HTPasswdPasswordIdentityProvider'}]
openshift_disable_check=memory_availability,disk_availability,docker_storage,docker_image_availability

openshift_hosted_registry_storage_kind=nfs
openshift_hosted_registry_storage_access_modes=['ReadWriteMany']
openshift_hosted_registry_storage_nfs_directory=/exports
openshift_hosted_registry_storage_nfs_options='*(rw,root_squash)'
openshift_hosted_registry_storage_volume_name=registry
openshift_hosted_registry_storage_volume_size=200Gi
openshift_clock_enabled=true
openshift_enable_unsupported_configurations=True

DNS下发(Master节点执行)

# 将hosts复制到/etc/ansible/下
[root@master-test-k8s ~]# cp ~/openshift-ansible/inventory/hosts /etc/ansible/hosts
[root@master-test-k8s ~]# ansible all -m copy -a "src=/etc/hosts dest=/etc/hosts "

Docker启动(Master节点执行)

[root@master-test-k8s ~]# ansible all -a 'systemctl start docker';ansible all -a 'systemctl enable docker'

执行安装(Master节点执行)

# 理论上 下边两条ansible-playbook的命令是可以反复执行的
[root@master-test-k8s ~]# cd openshift-ansible/
[root@master-test-k8s openshift-ansible]# ansible-playbook -i inventory/hosts playbooks/prerequisites.yml
[root@master-test-k8s openshift-ansible]# ansible-playbook -i inventory/hosts playbooks/deploy_cluster.yml

# 部署结束后, 创建用户
[root@master-test-k8s openshift-ansible]# htpasswd -cb /etc/origin/master/htpasswd admin admin

# OpenShift卸载命令:
[root@master-test-k8s openshift-ansible]# ansible-playbook ./playbooks/adhoc/uninstall.yml
本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可
分享到

使用OpenShift搭建k8s集群

也可使用浏览器菜单中的「分享」功能

微信扫一扫分享

标签: docker K8s OpenShift
最后更新:2020年4月16日

岁月同一天 11 月 7 日

回望过去的今天,你在写什么

  • AI
    1 年前 2025年11月7日
    DeepSeek本地部署全攻略:从环境搭建到高级应用,打造专属 AI 助手

    DeepSeek 作为国产开源大模型的佼佼者,凭借出色的推理能力、代码生成效率和中文支持,成为很多开发者本地部署的首选。…

相关文章
  • k8s部署服务到集群中的指定节点2020年7月6日
  • Docker打包部署示例2019年10月31日
  • Dockerfile指令详解之COPY和ADD2020年6月5日
  • 解决kubectl exec -it xxxx-service-bfbd45bb9-ktvzj bash -n bit error: exec [POD] [COMMAND] is not supported anymore. Use exec [POD] -- [COMMAND] instead See 'kubectl exec -h' for help and examples2025年4月22日
  • K8S + docker部署war包项目2020年5月11日

李锋镝

既然选择了远方,便只顾风雨兼程。

打赏 点赞
< 上一篇
下一篇 >
1234567891112131415161718192021222324252627282930313233343536373839404142434446474849505152535455575859606162636465666769727476777879808182858687909293949596979899
取消回复
…

文章评论

  • peacherLv 1

    求问Linux版本?

    macOSmacOSChrome 81.0.4044.138Chrome 81.0.4044.138中国中国-北京
    2020年5月25日
    00 回复
    • 李锋镝博主

      @peacher 操作系统版本信息:Linux version 3.10.0-1062.18.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) ) #1 SMP Tue Mar 17 23:49:17 UTC 2020
      操作系统发行版信息:CentOS Linux release 7.7.1908 (Core)

      WindowsWindowsChrome 81.0.4044.138Chrome 81.0.4044.138中国中国-北京
      2020年5月25日
      00 回复
  • 我亦飘零久,十年来,深恩负尽,死生师友。

    听点儿音乐吧 朋友~
    文章目录
    最新 热点 随机
    最新 热点 随机
    给服务器加了WAF 又一个逆天改命的人:小小徐 AI的生成能力等于生产力吗? NGINX严重漏洞(CVE-2026-15176、CVE-2026-93479、CVE-2026-97205) Kratos-plus v1.1.27更新说明 php2shell远程执行漏洞修复(CVE-2026-109618 和 CVE-2026-109619)
    给主题增加了游客中心功能心气没了,干什么都不得劲我觉得是时候公布我的导航网站了给服务器加了WAF游本昌去世关于主题加载速度优化的一点儿小演进
    为什么 Spring 不建议使用 @Autowired?@Resource 才是王道 JAVA设计模式-抽象工厂模式 为什么关于香菜的评价这么两极? Navicat Premium数据库账号密码解密 缓存架构实战指南:6大核心缓存技术深度解析与落地方案 开发者必懂的 AI 向量入门:从数学基础到实战应用
    最近评论
    fairy 发布于 17 小时前(11月06日) 机器人快来我这里吧!
    李锋镝 发布于 17 小时前(11月06日) 都是机器人,防不住
    李锋镝 发布于 17 小时前(11月06日) 是的,太烦了
    李锋镝 发布于 17 小时前(11月06日) 可以同一台服务器
    fairy 发布于 19 小时前(11月06日) 这流量,好厉害啊。我一年都没那么多
    标签聚合
    多线程 K8s 分布式 WordPress JAVA 数据库 SpringBoot Spring AI SQL JVM AI编程 Claude IDEA ElasticSearch Redis MySQL 日常 架构 Theme
    友情链接
    • 林羽凡
    • 彬红茶日记
    • 知向前端
    • lijie blog
    • Serendipity
    • 韩小韩博客
    • 瓦匠个人小站
    • 皮皮社
    • 老张博客
    • 志文工作室
    • 哥斯拉
    • 懋和道人
    • 韩情脉脉
    • Honesty
    • 刘永博客
    • sssr7844的博客
    • 搬砖日记
    • 九仞之行
    • Mr.Sun的博客

    COPYRIGHT © 2016-2026 lifengdi.com. ALL RIGHTS RESERVED.

    lifengdi.com 十年之约虫洞

    Domain age badge for lifengdi.com

    Theme Kratos-plus By Dylan Li

    津ICP备2024022503号-3

    京公网安备11011502039375号