<p>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:</p>

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

<p>How can I make sure it will always be up after restarting the VM?</p>

<p><strong>UPDATE:</strong></p>

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

<pre><code>sudo swapoff -a
sudo systemctl restart kubelet.service
</code></pre>

<p>Why? How can I fix it so that it starts without having to input that?</p>

codependent
<blockquote>
  <p>The problem is that if I stop the machine and restart it the master node seems to be down</p>
</blockquote>

<ul>
<li><p>Since it was kubeadm installation that worked properly before restarts, seems like Env var is missing after restart. Try to run this before <code>kubectl get nodes</code>:</p>

<pre><code>export KUBECONFIG=/etc/kubernetes/admin.conf
</code></pre>

<p>If it starts normally, then you need to make sure that <code>KUBECONFIG</code> environment variable is properly configured upon restart either adding it to <code>.bashrc</code> or similar...</p></li>
</ul>

<h3>Edited:</h3>

<blockquote>
  <p>Why? How can I fix it so that it starts without having to input that?</p>
</blockquote>

<ul>
<li><p>Ah, swap file is teasing you. By default kubelet will not start if swap is enabled. You have two options:</p>

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

<pre><code>Environment="KUBELET_EXTRA_ARGS=--fail-swap-on=false"
</code></pre>

<p>and next restart you will be able to run kubelet with swap enabled.</p></li>
</ul></li>
</ul>
