《Kubernetes 排错指南-008》The connection to the server localhost:8080 was refused
Ubuntu 20.04 LTS 在 Node 节点上成功添加到集群后,会出现如下提示:This node has joined the cluster:* Certificate signing request was sent to apiserver and a response was received.* The Kubelet was informed of the new secur
·
系统环境:
- Ubuntu 20.04 LTS
- Docker 20.10.8
- Kubernetes 1.22.1
- Node: master、work
执行命令:
$ 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
配置项,Master
节点才有 admin.conf
配置项。
root@k8s-master-03:/etc/kubernetes# ls -l
total 12
-rw------- 1 root root 1910 Jul 6 09:52 kubelet.conf
drwxr-xr-x 2 root root 4096 Jul 6 09:41 manifests
drwxr-xr-x 2 root root 4096 Jul 6 09:52 pki
所以需要将 admin.conf
配置项替换为 kubelet.conf
配置项后重新执行配置即可。
$ mkdir -p $HOME/.kube
$ cp -i /etc/kubernetes/kubelet.conf $HOME/.kube/config
$ chown $(id -u):$(id -g) $HOME/.kube/config
更多推荐
所有评论(0)