[kubernetes/出错] kubectl 返回 The connection to the server 192.168.X.X:6443 was refused

问题描述

[root@k8s-master ~]# kubectl ...
The connection to the server 192.168.X.X:6443 was refused - did you specify the right host or port?

master:6443是k8s kube-apiserver的端口
192.168.X.X是本机网卡地址,每个人设置的不同。

解决方法

检查发现port 6443有监听,与网上的结果都不同:

netstat -tunlp 6443 # 从返回列表看,6443 status 为 LISTEN

由于是刚开机就遇到的问题,并且以前没问题,所以直接重启计算机。成功。

附录:尝试

# docker活着
[root@k8s-master ~]# docker image ls
REPOSITORY                                                        TAG                 IMAGE ID            CREATED             SIZE
kubernetes-hugo                                                   latest              ac0a5b9f5c85        22 hours ago        258MB
my-kube-scheduler                                                 1.0                 6f252786ffbd        46 hours ago        40.4MB

# 监听也在
[root@k8s-master ~]# netstat -tunlp 6443
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1184/master         
...
tcp6       0      0 :::6443                 :::*                    LISTEN      2044/kube-apiserver


[root@k8s-master ~]# kubectl edit clusterrole system:kube-scheduler
The connection to the server 192.168.X.X:6443 was refused - did you specify the right host or port?
[root@k8s-master ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
...
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
...
    inet 192.168.X.X/24 brd 192.168.X.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
...
[root@k8s-master ~]# kubectl get po
The connection to the server 192.168.X.X:6443 was refused - did you specify the right host or port?
[root@k8s-master ~]# ping 192.168.X.X
PING 192.168.X.X (192.168.X.X) 56(84) bytes of data.
64 bytes from 192.168.X.X: icmp_seq=1 ttl=64 time=0.014 ms

你可能感兴趣的:(kubernetes,容器,云原生)