[root@k8s-master ~]# kubectl get nodes
E0322 10:29:10.166586    8455 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
E0322 10:29:10.166882    8455 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
E0322 10:29:10.168298    8455 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
E0322 10:29:10.170502    8455 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
E0322 10:29:10.172351    8455 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
The connection to the server localhost:8080 was refused - did you specify the right host or port?

单从报错可以看出,kubectl 没有使用到证书与k8s api通信,在初始化集群的时候要想使用kubectl需要,申明证书变量 export KUBECONFIG=/etc/kubernetes/admin.conf ,重启之后 KUBECONFIG 变量失效了。所有需要重新声明,并加入过/etc/profile 全局变量文件。

echo "export KUBECONFIG=/etc/kubernetes/kubelet.conf" >> /etc/profile
source /etc/profile
[root@k8s-master ~]# kubectl get nodes
NAME         STATUS   ROLES           AGE   VERSION
k8s-master   Ready    control-plane   15m   v1.28.2
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐