一、问题

The connection to the server localhost:8080 was refused - did you specify the right host or port?

Kubernetes kubectl The connection to the server localhost:8080 was refused - did you specify the rig_解决方法

 

二、原因

kubectl命令需要使用kubernetes-admin来运行,但是从节点没有这个文件

 

三、解决方法

1. 主节点将其【/etc/kubernetes/admin.conf】文件拷贝到从节点相同目录下

scp /etc/kubernetes/admin.conf root@192.168.18.133:/etc/kubernetes

Kubernetes kubectl The connection to the server localhost:8080 was refused - did you specify the rig_其他_02

Kubernetes kubectl The connection to the server localhost:8080 was refused - did you specify the rig_kubernetes_03

2.从节点配置环境变量

echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile

3. 使该文件立即生效

source ~/.bash_profile

4. 接着再运行kubectl命令就OK了

Kubernetes kubectl The connection to the server localhost:8080 was refused - did you specify the rig_文件拷贝_04

 

参考:https://www.jianshu.com/p/6fa06b9bbf6a