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

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.