我是靠谱客的博主 贤惠天空,最近开发中收集的这篇文章主要介绍K8s中The connection to the server localhost:8080 was refused- did you specify the right host or port?,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

问题描述:
K8s中,主节点init结束后,执行kubectl get nodes时,出现The connection to the server localhost:8080 was refused- did you specify the right host or port?报错

#以主节点为例:
queena@queena-Lenovo:~$ sudo kubeadm init --apiserver-advertise-address=192.168.31.245 --pod-network-cidr=10.244.0.0/16
--kubernetes-version=v1.22.3
...
Your Kubernetes control-plane has initialized successfully!
...
queena@queena-lenovo:~$ kubectl get nodes
The connection to the server localhost:8080 was refused - did you specify the right host or port?
#出现此报错.

解决方法:
K8s没有与本机绑定,需要设置在本机的环境变量,即可解决问题。

#设置环境变量
queena@queena-lenovo:~$ sudo su
root@queena-lenovo: echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> /etc/profile
#使其生效
root@queena-lenovo: source /etc/profile
#再次执行kubectl get nodes,不会报错了.
root@king-ubuntu:/etc/kubernetes# kubectl get nodes
NAME
STATUS
ROLES
AGE
VERSION
queena-lenovo
Ready
control-plane,master
24h
v1.22.3

至此,问题得以解决!

最后

以上就是贤惠天空为你收集整理的K8s中The connection to the server localhost:8080 was refused- did you specify the right host or port?的全部内容,希望文章能够帮你解决K8s中The connection to the server localhost:8080 was refused- did you specify the right host or port?所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(42)

评论列表共有 0 条评论

立即
投稿
返回
顶部