运行 kubectl get namespace时报错:
[root@ip-10-0-0-8 ~]# kubectl get namespace
E0320 07:39:20.866425 32422 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused
....
The connection to the server localhost:8080 was refused - did you specify the right host or port?
原因:kubectl命令需要使用kubernetes-admin来运行,需要admin.conf文件;而admin.conf 文件是通过 “kubeadmin init” 命令在 /etc/kubernetes 中创建的,从节点没有该配置文件;因此需要将admin.conf复制到从节点
复制配置文件并解决此问题:
sudo mkdir ~/.kube
sudo cp /etc/kubernetes/admin.conf ~/.kube/
cd ~/.kube
sudo mv admin.conf config
sudo service kubelet restart
或者按以下方式指定配置文件:
kubectl --kubeconfig ~/.kube/config get nodes
或者配置环境变量
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
source ~/.bash_profile
技术性分享,转载请注明出处!文章来源:https://www.toymoban.com/news/detail-520130.html
欢迎互相交流,共同进步!文章来源地址https://www.toymoban.com/news/detail-520130.html
到了这里,关于已解决—The connection to the server localhost:8080 was refused - did you specify the right host or port的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!