kubectl- The connection to the server x.x.x.:6443 was refused - did you specify the right host or port?

1k Views Asked by At

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:

  1. sudo -i

  2. swapoff -a

  3. exit

  4. 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 ?

1

There are 1 best solutions below

0
Ray John Navarro On

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/