I have set up a kubernetes cluster with a master node and a worker node. I am facing below error whenever I run a kubectl command-
The connection to the server x.x.x.:6443 was refused - did you specify the right host or port? Kubernetes
To resolve this- I have followed below steps:
sudo -i
swapoff -a
exit
strace -eopenat kubectl version
But this solution resolves the error only for sometime ( temporary solution ), after few minutes I get the same error. What can I do ?
Try restarting services as they may have gone stale.
sudo systemctl restart kubelet
sudo systemctl restart kube-apiserver
sudo systemctl restart kube-scheduler
sudo systemctl restart kube-controller-manager
Also check if there are any firewall rules that may be blocking port 6443. If all else fails, you may need to restart the master node. Attached is a good read for kubernetes networking that may help your use case.[1]
[1]
https://kubernetes.io/docs/concepts/cluster-administration/networking/