执行命令:
$ kubectl get nodes
报错如下:
The connection to the server localhost:8080 was refused - did you specify the right host or port?
报错说明:
这个错误在 master 和 node 节点上都有可能出现,报错是与服务器连接被拒绝。
解决方案:
master
$ mkdir -p $HOME/.kube
$ cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$ chown $(id -u):$(id -g) $HOME/.kube/config
不要被报错迷惑了,这个问题是需要执行 kubernetes 的配置文件,在 kubeadm init 完成时会有提示信息。
node
$ mkdir -p $HOME/.kube
$ cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$ chown $(id -u):$(id -g) $HOME/.kube/config
在 node 节点上执行 kubernetes 的配置结果报错,而且还多了一行报错:
W0706 10:27:55.181115 22817 loader.go:221] Config not found: /etc/kubernetes/admin.conf
The connection to the server localhost:8080 was refused - did you specify the right host or port?
进到 /etc/kubernetes/ 目录下,结果发现 Node 节点只有 kubelet.conf 配置项ÿ