Kubernetes-kubectl:The connection to the server localhost:8080 was refused

在Kubernetes的主节点上运行命令【kubectl】出现了如下错误

[root@k8s-master kubernetes]# kubectl get pod
The connection to the server localhost:8080 was refused - did you specify the right host or port?

出现这个问题的原因是kubectl命令需要使用kubernetes-admin来运行.
解决方法如下,将主节点中的【/etc/kubernetes/admin.conf】文件拷贝到从节点相同目录下,然后配置环境变量:
主节点:

scp -r /etc/kubernetes/admin.conf ${master}:/etc/kubernetes/admin.conf

在从节点:

echo “export KUBECONFIG=/etc/kubernetes/admin.conf” >> ~/.bash_profile
source ~/.bash_profile

Example:
Master

 $ scp -r /etc/kubernetes/admin.conf ${k8s-node1}:/etc/kubernetes/admin.conf

Worker

$ echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
$ source ~/.bash_profile
发布了6 篇原创文章 · 获赞 0 · 访问量 1065

猜你喜欢

转载自blog.csdn.net/weixin_43394724/article/details/96478642