k8s kubectl the server localhost:8080 was refused

次时使用kubectl命令会提示错误

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

解决办法:

对于非root用户
 mkdir -p $HOME/.kube
 sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
 sudo chown $(id -u):$(id -g) $HOME/.kube/config

 对于root用户
 export KUBECONFIG=/etc/kubernetes/admin.conf
 也可以直接放到~/.bash_profile
 echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
原文地址:https://www.cnblogs.com/hzcya1995/p/13317354.html