Kubernetes-kubectl命令出现错误【The connection to the server localhost:8080 was refused - did you specif...

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

[root@k8snode1 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】文件拷贝到从节点相同目录下,

[root@k8s-node01 kubernetes]# echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
[root@k8s-node01 kubernetes]# source ~/.bash_profile
[root@k8s-node01 kubernetes]# kubectl get pod -o wide
NAME                                READY   STATUS    RESTARTS   AGE   IP              NODE           NOMINATED NODE   READINESS GATES
nginx-deployment-76b9f6868b-528md   1/1     Running   0          18m   10.244.85.200   k8s-node01     <none>           <none>
nginx-deployment-76b9f6868b-bnqlh   1/1     Running   0          18m   10.244.58.201   k8s-node02     <none>           <none>
nginx-deployment-76b9f6868b-dtmcp   1/1     Running   0          18m   10.244.32.139   k8s-master01   <none>           <none>
posted @ 2019-12-31 00:14  天宇轩-王  阅读(3622)  评论(0编辑  收藏  举报