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

5/17/2018

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?

-- codependent
kubeadm
kubectl
kubernetes
virtualbox

3 Answers

1/27/2020

I encountered a similar issue where the kubectl commands are working in my master node but the same executed in slave node give me this error:

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

The solution that worked for me is as below:

I copied the $KUBECONFIG file of Master and places in the slave nodes .kube/ location and it worked (I have only 2 nodes, one master and one slave.)

-- Santhosh Kumar
Source: StackOverflow

11/11/2018

I got my problem fixed by clearing some space on the HDD. It seems that the space is low. Then, I restarted the server and it fixed my problem.

-- Jay
Source: StackOverflow

5/17/2018

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.

-- Const
Source: StackOverflow