阅读陈同学 博客原文,格式更佳
Rancher 是一个容器管理平台,最新2.0版本已经内嵌k8s
一个新产品临近上线,全部采购了腾讯云ECS服务器,安装了Rancher 1.6.17做容器编排。在添加主机到服务器集群时,rancher的 healthcheck 容器和自定义的 loadbalance 容器无法启动,一直处于Initializing
状态
查看healthcheck和lb容器的日志,并没发现什么特别的信息。因本身没有使用k8s,因此k8s相关的日志也只是普通提示信息
Failed to initialize Kubernetes controller: KUBERNETES_URL is not set, CATTLE_ACCESS_KEY is not set, skipping init of Rancher LB provider
Starting Rancher LB service
LB controller: rancher
LB provider: haproxy
starting rancher controller
Healthcheck handler is listening on :10241
Initializing event router" workerCount=25
Connection established
Starting websocket pings
-- starting haproxy\n * Starting haproxy haproxy\n ...done.\n
-- reloading haproxy config with the new config changes\n * Reloading haproxy haproxy\n[WARNING] 147/162016 (61) : config : 'option forwardfor' ignored for proxy 'default' as it requires HTTP mode.\n[WARNING] 147/162016 (63) : config : 'option forwardfor' ignored for proxy 'default' as it requires HTTP mode.\n ...done.\n
这种问题最头疼,没有日志,全看经验,日志甚至会错误引导。
在rancher github的Issues #9916 中发现了点蛛丝马迹,有两个有用的回答:
回答1:
LB not working might be a different issue, this error message shouldn't affect the behavior. If the LB gets stuck in initializing state, in most of the cases - especially when there are multiple hosts in the system - it means that the healthcheck for LB is failing due to cross hosts communication failures.
经验证,发现集群只有一台机器时,没有发生任何问题;当集群超过一台机器时,出现问题。
回答2:
This is becoming an aggregation of issues, while the log message is not telling us anything. I marked this an enhancement.
For other issues, please ensure cross host networking is working properly (http://rancher.com/docs/rancher/v1.6/en/faqs/troubleshooting/#cross-host-communication). If this is the case, please file a new issue describing what isn't working as expected with all the relevant versions and information to reproduce.
经验证,发现不同机器上的容器之间无法ping通,此时焕然大悟,是机器之间的网络出问题了。
因为往机器中添加机器时,若不设置IP,会默认读取机器的公网IP,如下图:
因为是云服务器,基于安全考虑,除了开放80/443/22等必要端口外,其他进入公网流量全部被拒绝。因为Rancher上添加机器时没有指定内网IP,所以不同机器上的容器之间无法通讯。
添加主机时指定内网IP即可,指定后healthcheck和lb容器均恢复正常
以下资料来自rancher官网英文文档:CROSS HOST COMMUNICATION
本小节记录关于 跨主机通讯
如果不同主机上的容器相互无法ping通,可能由以下常见的场景导致:
查看healthcheck
容器的状态,如果状态是active
,那么跨主机通讯一切正常。
每隔一段时间,会使用docker的桥接IP替换主机的IP(不会使用机器的实际IP),这些IP通常是172.17.42.1或从172.17.x.x开始。如果是这种情况,你需要在docker run
命令中设置CATTLE_AGENT_IP
并重新注册主机。
如果你启用了UFW
,你可以禁用UFW
或者把/etc/default/ufw
设置为:
DEFAULT_FORWARD_POLICY="ACCEPT"
Load Balancers会自动启动健康检查,如果它们一直是这个状态,则很有可能是跨主机通讯出了问题。
处理这个问题需要了解Rancher的healthcheck和lb,知道这两个点的人一眼就能看出问题。算是涨经验了。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。