Rancher搭建
1.拉取镜像(2.0版本,rancher的2.0和1.0差别有些大)
docker pull rancher/rancher
2.查看镜像信息
docker inspect rancher/rancher:latest
3.执行以下命令,在宿主机创建两个挂载目录,以便持久化数据
mkdir -p /water/runfile/docker_volume/rancher_home/rancher
mkdir -p /water/runfile/docker_volume/rancher_home/auditlog
4.使用挂载到指定的主机目录方式来进行数据卷的持久化同时启动rancher
(如果宿主机的内存过小,则会导致启动失败,建议调制2GB+)
docker run --privileged -d --restart=unless-stopped -p 80:80 -p 443:443 \
-v /water/runfile/docker_volume/rancher_home/rancher:/var/lib/rancher \
-v /water/runfile/docker_volume/rancher_home/auditlog:/var/log/auditlog \
--name rancher -e JAVA_OPTS="-Xmx4096m" rancher/rancher
docker run -dti --restart=unless-stopped --network=host --name rancher -v /data/rancher:/var/lib/rancher/ -v /etc/localtime:/etc/localtime rancher/rancher:stable
5.登录rancher,新建kubernetes集群
注意每台主机的hostname 一定不能相同
6.修改静态IP
具体配置见网络配置文档
7.安装时间同步插件
yum install ntp ntpdate -y
ntpd服务端:
vi /etc/ntp.conf
restrict 192.168.181.0 mask 255.255.255.0 nomodify notrap
#文件自带的server xxxx注释掉
server 0.cn.pool.ntp.org
server 1.cn.pool.ntp.org
server 2.cn.pool.ntp.org
server 3.cn.pool.ntp.org
restrict 0.cn.pool.ntp.org nomodify notrap noquery
restrict 1.cn.pool.ntp.org nomodify notrap noquery
restrict 2.cn.pool.ntp.org nomodify notrap noquery
restrict 3.cn.pool.ntp.org nomodify notrap noquery
server 127.0.0.1 # local clock
fudge 127.0.0.1 stratum 10
systemctl restart ntpd
ntpq -p 和 ntpstat 查看
ntpd客户端
vi /etc/ntp.conf
server 192.168.181.224
restrict 192.168.181.224 nomodify notrap noquery
server 127.0.0.1 # local clock
fudge 127.0.0.1 stratum 10
systemctl restart ntpd 需要等待10分钟左右 然后使用 ntpq -p 和 ntpstat 查看
8.在rancher上新建k8s集群
新建自定义k8s集群, 然后复制启动命令, 在本机上执行时要勾选上
如果出现错误:
client's certificate: x509: certificate signed by unknown authorit
删除/etc/kubernets
9.安装成功后,在集群其他机器上继续安装
执行开放防火墙端口:
firewall-cmd --add-port=2379/tcp --permanent
firewall-cmd --add-port=2380/tcp --permanent
firewall-cmd --add-port=6443/tcp --permanent
firewall-cmd --add-port=10250/tcp --permanent
firewall-cmd --reload
报错解决
错误:
docker run -d --restart=unless-stopped -p 8882:80 -p 8443:443 rancher/rancher
容器状态 一直是restarting,之后看了下日志
rancher must be ran with the --privileged flag when running outside of kubernetes
大概意思就是要在k8s外运行rancher 需要特权(英语不好就这么翻译吧)。重点就是 --privileged 。
其实就是启动命令改下
修改后:
sudo docker run --privileged -d --restart=unless-stopped -p 8882:80 -p 8444:443 rancher/rancher
privileged 的作用其实就是启动的 container内的root拥有真正的root权限!!!