rancher “Failed to connect to proxy“ error=“websocket: bad handshake“

rancher “Failed to connect to proxy” error=“websocket: bad handshake”

度娘有两种说法

参考:https://www.wulaoer.org/?p=2127
一、跑Rancher 的机器Docker和K8S Docker容器网段相同!
昨天因为需求,所以需要部署新的环境,然后就创建了kubenetes,想着还是使用rancher来管理来着,但是在导入rancher的时候总是报错:websocket: bad handshake,百度了很久,有的说是因为插件的问题,有的说是计算机名的问题,还有的说是rancher的底层问题。但是我前段时间确实使用的同一个版本的rancher和kubenetes做导入是没有任何问题的。都正常了。没办法,只能一个一个的找了,我发现kubenetes中的pod无法和我node节点同一个网段的节点通信,这个就比较出来了,原来pod不是跟所有node节点,只是和rancher这个服务的节点不能通行,其他都正常,而且rancher客户端的日志出现内容如下:

time="2021-07-01T02:50:54Z" level=info msg="Connecting to proxy" url="wss://172.16.199.10/v3/connect"
time="2021-07-01T02:50:54Z" level=error msg="Failed to connect to proxy. Response status: 200 - 200 OK. Response body: node.management.cattle.io \"c-v9vms/m-f6d72960ed8a\" not found" error="websocket: bad handshake"
time="2021-07-01T02:50:54Z" level=error msg="Remotedialer proxy error" error="websocket: bad handshake"
time="2021-07-01T02:51:04Z" level=info msg="Connecting to wss://172.16.199.10/v3/connect with token xhhl6gdnj7849r4fqgbdkr56z24ck6kxkn8hkcmktdk2fklg98b94g"
time="2021-07-01T02:51:04Z" level=info msg="Connecting to proxy" url="wss://172.16.199.10/v3/connect"
time="2021-07-01T02:51:04Z" level=error msg="Failed to connect to proxy. Response status: 200 - 200 OK. Response body: node.management.cattle.io \"c-v9vms/m-f6d72960ed8a\" not found" error="websocket: bad handshake"
time="2021-07-01T02:51:04Z" level=error msg="Remotedialer proxy error" error="websocket: bad handshake"
time="2021-07-01T02:51:14Z" level=info msg="Connecting to wss://172.16.199.10/v3/connect with token xhhl6gdnj7849r4fqgbdkr56z24ck6kxkn8hkcmktdk2fklg98b94g"
time="2021-07-01T02:51:14Z" level=info msg="Connecting to proxy" url="wss://172.16.199.10/v3/connect"
time="2021-07-01T02:51:14Z" level=error msg="Failed to connect to proxy. Response status: 200 - 200 OK. Response body: node.management.cattle.io \"c-v9vms/m-f6d72960ed8a\" not found" error="websocket: bad handshake"
time="2021-07-01T02:51:14Z" level=error msg="Remotedialer proxy error" error="websocket: bad handshake"
time="2021-07-01T02:51:24Z" level=info msg="Connecting to wss://172.16.199.10/v3/connect with token xhhl6gdnj7849r4fqgbdkr56z24ck6kxkn8hkcmktdk2fklg98b94g"
time="2021-07-01T02:51:24Z" level=info msg="Connecting to proxy" url="wss://172.16.199.10/v3/connect"
time="2021-07-01T02:51:24Z" level=error msg="Failed to connect to proxy. Response status: 200 - 200 OK. Response body: node.management.cattle.io \"c-v9vms/m-f6d72960ed8a\" not found" error="websocket: bad handshake"
time="2021-07-01T02:51:24Z" level=error msg="Remotedialer proxy error" error="websocket: bad handshake"
time="2021-07-01T02:51:34Z" level=info msg="Connecting to wss://172.16.199.10/v3/connect with token xhhl6gdnj7849r4fqgbdkr56z24ck6kxkn8hkcmktdk2fklg98b94g"
time="2021-07-01T02:51:34Z" level=info msg="Connecting to proxy" url="wss://172.16.199.10/v3/connect"
time="2021-07-01T02:51:34Z" level=error msg="Failed to connect to proxy. Response status: 200 - 200 OK. Response body: node.management.cattle.io \"c-v9vms/m-f6d72960ed8a\" not found" error="websocket: bad handshake"
time="2021-07-01T02:51:34Z" level=error msg="Remotedialer proxy error" error="websocket: bad handshake"

我尝试着在pod里去ping一下rancher的节点ip,不能通信,和其他的节点正常,这个问题就比较明显了,rancher这个节点有问题。下面继续分析,在rancher这个服务上的docker的ip地址和node节点的ip地址是一个网段的,有冲突了。修改一下docker的节点ip端。

vim /etc/docker/daemon.json
{
    "bip":"192.168.0.1/24"
}

我这里docker默认的网断和宿主机是一个网段的,这里做一下修改,然后重启一下docker,在重新试一下问题解决。

二、rancher初始化k8s由于主机名不规范导致异常
部署rancher/rancher
通过rancher-ui初始化k8s

rancher-agent //logs

INFO: Arguments: --server https://172.16.1.69 --token REDACTED --ca-checksum 5e5f7cbe78a0a34e3df0c31c6b2c9bc2421e1f11469f4d29b8523b64d0073630 --etcd --controlplane --worker
INFO: Environment: CATTLE_ADDRESS=172.16.0.140 CATTLE_INTERNAL_ADDRESS= CATTLE_NODE_NAME=pet_k8s_master CATTLE_ROLE=,etcd,worker,controlplane CATTLE_SERVER=https://172.16.1.69 CATTLE_TOKEN=REDACTED
INFO: Using resolv.conf: nameserver 223.5.5.5 nameserver 172.16.0.2 nameserver 8.8.8.8
INFO: https://172.16.1.69/ping is accessible
INFO: Value from https://172.16.1.69/v3/settings/cacerts is an x509 certificate
time="2020-09-07T10:34:04Z" level=info msg="Rancher agent version v2.4.5 is starting"
time="2020-09-07T10:34:04Z" level=info msg="Option requestedHostname=pet_k8s_master"     //主机名不规范,不符合dns域名规范
time="2020-09-07T10:34:04Z" level=info msg="Option customConfig=map[address:172.16.0.140 internalAddress: label:map[] roles:[etcd worker controlplane] taints:[]]"
time="2020-09-07T10:34:04Z" level=info msg="Option etcd=true"
time="2020-09-07T10:34:04Z" level=info msg="Option controlPlane=true"
time="2020-09-07T10:34:04Z" level=info msg="Option worker=true"
time="2020-09-07T10:34:04Z" level=info msg="Listening on /tmp/log.sock"
time="2020-09-07T10:34:04Z" level=info msg="Connecting to wss://172.16.1.69/v3/connect with token cb8m9szbwjp2v8ddk5mmg26d64dphc4f9fsn5g7h5nrztfkrc5xcck"
time="2020-09-07T10:34:04Z" level=info msg="Connecting to proxy" url="wss://172.16.1.69/v3/connect"
time="2020-09-07T10:34:04Z" level=error msg="Failed to connect to proxy. Response status: 200 - 200 OK. Response body: node.management.cattle.io \"c-tmsv8/m-0edc6a1b0eff\" not found" error="websocket: bad handshake"
time="2020-09-07T10:34:04Z" level=error msg="Remotedialer proxy error" error="websocket: bad handshake"
time="2020-09-07T10:34:14Z" level=info msg="Connecting to wss://172.16.1.69/v3/connect with token cb8m9szbwjp2v8ddk5mmg26d64dphc4f9fsn5g7h5nrztfkrc5xcck"
time="2020-09-07T10:34:14Z" level=info msg="Connecting to proxy" url="wss://172.16.1.69/v3/connect"
time="2020-09-07T10:34:14Z" level=error msg="Failed to connect to proxy. Response status: 200 - 200 OK. Response body: node.management.cattle.io \"c-tmsv8/m-0edc6a1b0eff\" not found" error="websocket: bad handshake"
time="2020-09-07T10:34:14Z" level=error msg="Remotedialer proxy error" error="websocket: bad handshake"

问题解决#
修改主机名及host

hostnamectl set-hostname pet-k8s-master

vi /etc/hosts
x.x.x.x  pet-k8s-master

删除本地运行的agent重新执行

注意image要加速使用国内加速地址

参考网址:http://t.zoukankan.com/xiaochina-p-13630571.html

你可能感兴趣的:(k8s,websocket,docker,网络协议)