'microk8s Connection to port 16443 was refused

I'm getting following error message:

root@master-1:~# microk8s.kubectl get no
The connection to the server 127.0.0.1:16443 was refused - did you specify the right host or port?

Even microk8s.kubectl cluster-info dump fails with message above. When I run microk8s start it still the same.



Solution 1:[1]

iptables were provisioned by ansible which were messing with microk8s iptables configuration

Solution 2:[2]

It is hard to tell exactly what might went wrong here but there are few things that you could do in order to fix your issue:

  • .kube/config is missing or not configured correctly. Create or copy a valid kubeconfig file to solve this.

  • You have swap not turned off. With swap enabled, kubelet service will not start. Execute: sudo swapoff -a in order to make sure it is disabled.

  • kubelet might be down. Check kubelet logs and make sure that kube-apiserver is up and running.

  • Check which ports are appropriate to use with the telnet command.

Solution 3:[3]

check your /etc/ hosts file there should be these lines

127.0.0.1 localhost 127.0.1.1 name you servers

Solution 4:[4]

For me Ubuntu 20.04.4 LTS (Focal Fossa), this two commands save my day:

sudo microk8s.refresh-certs --cert ca.crt

and

sudo microk8s.refresh-certs --cert server.crt

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 hejkerooo
Solution 2 Wytrzymały Wiktor
Solution 3 ??????? ?
Solution 4 Ali