Kubernetes-kubectl:The connection to the server localhost:8080 was refused

Running on the primary node Kubernetes command] [kubectl following error occurred

[root@k8s-master kubernetes]# kubectl get pod
The connection to the server localhost:8080 was refused - did you specify the right host or port?

This problem occurs because the command requires kubectl kubernetes-admin to run.
Solutions are as follows, copy master node /etc/kubernetes/admin.conf] [files to the same directory from the node, and then configure the environment variables:
main node:

scp -r /etc/kubernetes/admin.conf ${master}:/etc/kubernetes/admin.conf

From the node:

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

Example:
Master

 $ scp -r /etc/kubernetes/admin.conf ${k8s-node1}:/etc/kubernetes/admin.conf

Worker

$ echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
$ source ~/.bash_profile
Released six original articles · won praise 0 · Views 1065

Guess you like

Origin blog.csdn.net/weixin_43394724/article/details/96478642