This error The connection to the server <server_ip>:6443 was refused - did you specify the right host or port,
it seems it cannot locate the API at port 6443, indicating that the API and the Docker container that is running it are the causes of this error. Therefore, this kind of error will be thrown if docker is down or if anything that is preventing access to docker is interrupted.
As explained in this doc by Greek Diary ‘admin’ which explains how to fix error
1.The kubectl should be executed on the Master Node.
2.Current user must have Kubernetes cluster configuration environment variable (Details of how to are listed under section Preparing to Use
Kubernetes as a Regular User), e.g.:
$ env | grep -i kube
KUBECONFIG=/root/.kube/config
3.The docker service must be running:
$ systemctl status docker
4.The kubelet service must be running:
$ systemctl status kubelet
5.TCP port 6443 should be listed as listening port:
# netstat -pnlt | grep 6443
tcp6 0 0 :::6443 :::* LISTEN 4546/kube-apiserve
If TCP port 6443 is not available, check firewall/iptables rules
matching requirements:
$ firewall-cmd --list-all
Also check kubelet logs:
# journalctl -xeu kubelet
6.Try restarting Kubernetes cluster which will also do some basic checks
$ kubeadm-setup.sh restart
You can also refer to this doc written by David O'Dell for more information about Troubleshoot kubectl connection refused.