k8s:The connection to the server localhost8080 was refused - did you specify the right host or port

Kubernetes-kubectl命令出现错误The connection to the server localhost:8080 was refused - did you specify the right host or port?

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

    root@k8s-master1:~# kubectl get nodes
    The connection to the server localhost:8080 was refused - did you specify the right host or port?
    
    

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

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

立即生效

source ~/.bash_profile

接着再运行kubectl命令就OK了

root@k8s-master1:~# echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
root@k8s-master1:~# source ~/.bash_profile
root@k8s-master1:~# kubectl get nodes
NAME          STATUS   ROLES    AGE   VERSION
k8s-master1   Ready    master   33h   v1.18.3
k8s-master2   Ready    master   32h   v1.18.3
k8s-node1     Ready       32h   v1.18.3
k8s-node2     Ready       32h   v1.18.3
k8s-node3     Ready       32h   v1.18.3

你可能感兴趣的:(#,K8s)