If you encounter similar error below, it could be that your kubeconfig is using an incorrect port number. In error below, we can see it’s using 4380. Usually, the controlplane node’s port is 6443, which is the default port. To fix that, check your kubeconfig file.
k get all --kubeconfig=/root/kubeconfig
E1014 12:28:32.975277 40532 memcache.go:265] "Unhandled Error" err="couldn't get current server API group list: Get \"https://controlplane:4380/api?timeout=32s\": dial tcp 192.168.42.137:4380: connect: connection refused"
E1014 12:28:32.977458 40532 memcache.go:265] "Unhandled Error" err="couldn't get current server API group list: Get \"https://controlplane:4380/api?timeout=32s\": dial tcp 192.168.42.137:4380: connect: connection refused"
E1014 12:28:32.979648 40532 memcache.go:265] "Unhandled Error" err="couldn't get current server API group list: Get \"https://controlplane:4380/api?timeout=32s\": dial tcp 192.168.42.137:4380: connect: connection refused"
E1014 12:28:32.981320 40532 memcache.go:265] "Unhandled Error" err="couldn't get current server API group list: Get \"https://controlplane:4380/api?timeout=32s\": dial tcp 192.168.42.137:4380: connect: connection refused"
E1014 12:28:32.982866 40532 memcache.go:265] "Unhandled Error" err="couldn't get current server API group list: Get \"https://controlplane:4380/api?timeout=32s\": dial tcp 192.168.42.137:4380: connect: connection refused"
The connection to the server controlplane:4380 was refused - did you specify the right host or port?
Reference: