Couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused

Asking for help? Comment out what you need so we can get more information to help you!

Cluster information: 1 master node 1 worker node

root@k8s-master1:~/.kube# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master1 Ready control-plane 152m v1.28.2
k8s-worker01 Ready 150m v1.28.2

Kubernetes version: v1.28.2
Cloud being used: (put bare-metal if not on a public cloud)
Installation method: on vmware workstation , 1 master node 1 worker node
Host OS: Ubuntu 22.04.2 LTS
CNI and version:
CRI and version:

only getting this error on worker node
root@k8s-worker01:~# kubectl get nodes
E0919 14:57:21.242964 414467 memcache.go:265] couldn’t get current server API group list: Get “http://localhost:8080/api?timeout=32s”: dial tcp 127.0.0.1:8080: connect: connection refused
E0919 14:57:21.243436 414467 memcache.go:265] couldn’t get current server API group list: Get “http://localhost:8080/api?timeout=32s”: dial tcp 127.0.0.1:8080: connect: connection refused
E0919 14:57:21.245295 414467 memcache.go:265] couldn’t get current server API group list: Get “http://localhost:8080/api?timeout=32s”: dial tcp 127.0.0.1:8080: connect: connection refused
E0919 14:57:21.246960 414467 memcache.go:265] couldn’t get current server API group list: Get “http://localhost:8080/api?timeout=32s”: dial tcp 127.0.0.1:8080: connect: connection refused
E0919 14:57:21.248726 414467 memcache.go:265] couldn’t get current server API group list: Get “http://localhost:8080/api?timeout=32s”: dial tcp 127.0.0.1:8080: connect: connection refused

I am also facing the same issue.

I am also facing the same issue. Is it an environmental issue?

E1002 09:52:24.327737 9431 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

You have to set KUBECONFIG environment variable with the path of the k8s config file

$ echo $KUBECONFIG
empty

$ kubectl get pods
E1002 10:16:21.854341  105845 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

$ KUBECONFIG=$HOME/.kube/config

$ kubectl get pods
No resources found in default namespace.