三亩地 三亩地SAN MU DI · CODE DIARY
ARTICLE DETAIL

日记详情

真实记录编程学习的某一天,欢迎挑你感兴趣的翻一翻。

Rancher2.0搭建kubernetes(K8S)集群

Rancher2.0搭建kubernetes(K8S)集群

一、环境准备(4台都执行如下命令)
1.准备至少4台CentOS7版本服务器
# IP地址 主机名称

172.16.0.75 rancher 172.16.0.76 master 172.16.0.77 node1 172.16.0.78 node2

2.每台虚拟机上需要做的配置
1.安装Docker

yum install -y docker


2.设置hostname主机名

hostnamectl --static set-hostname rancher hostnamectl --static set-hostname master hostnamectl --static set-hostname node1 hostnamectl --static set-hostname node2


3.设置host域名映射

vim /etc/hosts

# 粘贴配置

172.16.0.75 rancher 172.16.0.76 master 172.16.0.77 node1 172.16.0.78 node2



4.关闭防火墙

systemctl disable firewalld.service systemctl stop firewalld.service



5.开启docker,可以不执行,默认docker已启动

systemctl start docker



到这里准备工作已完成

二、搭建rancher(在你主机名rancher上执行,不建议rancher和master配置在同一台机器上)
1.使用docker安装rancher

docker run -d --restart=unless-stopped -p 80:80 -p 443:443 rancher/rancher:stable 如果上面报错,使用docker logs -f 容器id ,查看容器错误日志 , 使用下面特权模式执行 docker run --privileged -d --restart=unless-stopped -p 80:80 -p 443:443 rancher/rancher:stable

2.查看rancher容器是否安装完成启动

docker ps


3.访问rancher

https://120.55.81.46/

dashboard

默认用户名是admin,密码通过登录页面提示的命令去服务器日志中查询

到这里rancher已经安装完成


三、新建集群

设置需要扩展的主节点和工作节点,

1. 只有master节点需要勾选etcd,Control,worker,然后copy对应命令到主节点服务器执行

2. 其他node节点只需勾选worker,然后copy对应命令到主节点服务器执行


四、部署Nginx

端口映射,选择节点端口,自动生成对应service,通过节点外网ip,直接访问nginx

nginx 访问地址:Welcome to nginx!

http://120.26.78.224:30008/

← 返回列表