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.
- Remove swap: That's easy, just disable it as you already listed but make it permanent by commenting swap line in
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.
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.)