The connection to the server localhost:8080 was refused - did you specify the right host or port?
遇到如下问题:
[root@k8s-node1 ~]# kubectl get pod
The connection to the server localhost:8080 was refused - did you specify the right host or port?
解决方式:
cd /etc/kubernetes/
查看到有个文件:kubelet.conf
(你们的有可能是admin.conf)
执行命令
echo "export KUBECONFIG=/etc/kubernetes/kubelet.conf" >> /etc/profile
source /etc/profile
再次查看 kubectl get pod 已经正常。
原因: kubernetes master没有与本机绑定,集群初始化的时候没有绑定,此时设置在本机的环境变量即可解决问题。