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

问题描述:

在调用kubectl命令时,出现以下错误:
The connection to the server localhost:8080 was refused - did you specify the right host or port?
在这里插入图片描述

原因分析:

在执行kubectl时,首先进行本地封装,然后调用kube-apiserver执行对应命令,在这个过程中需要获取k8s集群的配置,默认为当前用户下.kube目录的config,但此时获取不到配置。

解决方案:

1)如果是k8s集群的master节点,且为root用户,可以执行以下命令:

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

如果非root用户,可以执行以下命令:

 
 

你可能感兴趣的:(Linux,Kubernetes,kubernetes,linux,docker)