kubectl命令报错:Unable to connect to the server: dial tcp XXX:16443: connect: no route to host

简介: kubectl命令报错:Unable to connect to the server: dial tcp XXX:16443: connect: no route to host

前提

架构:keepalived+haproxy+kubernetes


问题说明

kubernetes集群好久不用了,今天打开集群执行一个kubectl get nodes命令,报错如下:

Unable to connect to the server: dial tcp 192.168.2.XXX:16443: connect: no route to host


分析原因

出现这个问题几种原因,

  1. 集群坏了:如果报错的IP是master1的节点IP或虚拟IP(vip)加16443端口号,执行kubectl命令还报上面的错误,说明集群坏了,需要逐步排查原因。
  2. /root/.kube/config中的IP地址错误:如果错误中的IP地址不是master1的节点IP或虚拟IP(vip)加16443端口号,需要修改配置文件中的IP。一般改为虚拟IP(vip)+16443端口号。
  3. haproxy:由于haproxy配置的是监听16443端口,也是集群的入口。因为报错的端口号是16443,所以要检查是否是haproxy的IP问题,如果是的话要修改haproxy配置文件,然后重启haproxysystemctl restart haproxy


解决问题

经排查,我的问题属于第二种,因为报错的意思是没有找不到192.168.2.XXX:16443这个路由,于是检查config文件:

vim /root/.kube/config


查看IP是否正确,经检查,我虚拟IP为:192.168.2.249,而这里显然不是,将IP修改为192.168.2.249:16443

892ee2b773a5462cbad25e4083c4c297.png

保存退出后再次查看节点状态,kubectl命令就可以正常使用了。

bda88e6ec2cf4a329afa07bdb2aa410a.png

另一中错误:Unable to connect to the server: dial tcp 123.56.91.155:6443: i/o timeout

Unable to connect to the server: dial tcp 123.56.91.155:6443: i/o timeout

刚开始爆出的错误是这个,一看这个IP就不是我当初创建集群时的IP,而是一个阿里云公网IP,其实进入config文件中修改成自己集群的IP就可以了。

相关文章
|
4天前
|
分布式计算 Hadoop 网络安全
[m1pro ] ssh: connect to host localhost port 22: Connection refused
[m1pro ] ssh: connect to host localhost port 22: Connection refused
|
8月前
|
关系型数据库 MySQL 数据库
成功解决错误1130- Host xxx is not allowed to connect to this MySQL server
成功解决错误1130- Host xxx is not allowed to connect to this MySQL server
|
4月前
|
Kubernetes Perl 容器
k8s创建完pod后报错: Failed connect to 10.244.36.90:8000; No route to host
k8s创建完pod后报错: Failed connect to 10.244.36.90:8000; No route to host
|
6月前
|
Linux 网络安全
ssh: connect to host 10.13.69.163 port 22: No route to host
ssh: connect to host 10.13.69.163 port 22: No route to host
|
8月前
|
网络协议 Linux 网络安全
使用frp时遇到的问题connect: connection refuseddial tcp xxxx:7000: connect: connection refused
最近在做的项目需要用到frp来做代理连接本地内网机,卡在最后启动客户端的时候,提示报错:login to server failed: dial tcp xxxx:7000: connect: connection refuseddial tcp xxxx:7000: connect: connection refused!!找了很多尝试的办法,现在给大家列一下希望对大家有帮助。
1504 0
|
Java 应用服务中间件 PHP
Nginx——*5 connect() failed (111: Connection refused) while connecting to upstream
Nginx——*5 connect() failed (111: Connection refused) while connecting to upstream
371 0
Nginx——*5 connect() failed (111: Connection refused) while connecting to upstream
|
10月前
|
Android开发
Error connecting to the service protocol failed to connect to错误
Error connecting to the service protocol failed to connect to错误
|
数据安全/隐私保护
记录curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused解决方案
关于这个错误其实遇到过好多次了,基本都是在每次换电脑之后执行
记录curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused解决方案
The connection to the server ip:6443 was refused - did you specify the right host or port
The connection to the server ip:6443 was refused - did you specify the right host or port