Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The connection to the server 10.0.x.x:6443 was refused after restarting the VM where kubernetes master was installed using kubeadm

I installed a Kubernetes master using kubeadm sucessfully on a VM (VirtualBox). The problem is that if I stop the machine and restart it the master node seems to be down:

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

How can I make sure it will always be up after restarting the VM?

UPDATE:

After restarting VM this is what I have to do to make the master node start:

sudo swapoff -a
sudo systemctl restart kubelet.service

Why? How can I fix it so that it starts without having to input that?

like image 830
codependent Avatar asked May 17 '18 08:05

codependent


People also ask

How do I enable port 6443?

1. Install nmap " sudo apt-get install nmap " 2. listen to port 6443 "nc -l 6443" 3. open a another terminal/window and connect to 6443 port "nc -zv 192.168.


1 Answers

The problem is that if I stop the machine and restart it the master node seems to be down

  • Since it was kubeadm installation that worked properly before restarts, seems like Env var is missing after restart. Try to run this before kubectl get nodes:

    export KUBECONFIG=/etc/kubernetes/admin.conf
    

    If it starts normally, then you need to make sure that KUBECONFIG environment variable is properly configured upon restart either adding it to .bashrc or similar...

Edited:

Why? How can I fix it so that it starts without having to input that?

  • Ah, swap file is teasing you. By default kubelet will not start if swap is enabled. You have two options:

    • Remove swap: That's easy, just disable it as you already listed but make it permanent by commenting swap line in /etc/fstab file. Add # before line creating swap mount point and next time you restart you won't have it.
    • Allow kubelet to run with swap enabled: I know, not recommended by documentation, but if you like to live dangerous, you can add/edit in /etc/systemd/system/kubelet.service.d/10-kubeadm.conf following line:

      Environment="KUBELET_EXTRA_ARGS=--fail-swap-on=false"
      

      and next restart you will be able to run kubelet with swap enabled.

like image 102
Const Avatar answered Oct 20 '22 12:10

Const