在k8s集群节点执行命令报:The connection to the server localhost:8080 was refused - did you specify the right host or port?

在非master节点上执行k8s命令时提示:The connection to the server localhost:8080 was refused - did you specify the right host or port?

[root@devops-k8s17-36 ~]# kubectl get nodes
The connection to the server localhost:8080 was refused - did you specify the right host or port?

问题原因:kubernetes master没有与本机绑定,集群初始化的时候没有绑定,此时设置在本机的环境变量即可解决问题。

 

解决办法:

1.将主节点(master节点)中的  /etc/kubernetes/admin.conf 文件拷贝到从节点相同目录下:

(文件名不一定叫admin.config,不同的版本文件名可能不一样)

2.配置环境变量

[root@devops-k8s17-36 kubernetes]# vim admin.conf
[root@devops-k8s17-36 kubernetes]# echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> /etc/profile
[root@devops-k8s17-36 kubernetes]# source /etc/profile
[root@devops-k8s17-36 kubernetes]# kubectl get nodes
NAME              STATUS   ROLES                      AGE     VERSION
devops-k8s17-35   Ready    controlplane,etcd,worker   3d17h   v1.17.5
devops-k8s17-36   Ready    worker                     3d17h   v1.17.5
devops-k8s17-37   Ready    worker                     3d17h   v1.17.5
[root@devops-k8s17-36 kubernetes]#

  

posted @ 2021-06-08 10:56  为什么要取名字  阅读(380)  评论(0编辑  收藏  举报