Docker-搭建rancher及rancher常见错误

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权限!!!

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值