<p>I accidentally deleted the config file from ~/.kube/config. Every kubectl command fails due to config missing.</p>
<p>Example:</p>
<pre><code>kubectl get nodes
</code></pre>
<blockquote>
<p>The connection to the server localhost:8080 was refused - did you
specify the right host or port?</p>
</blockquote>
<p>I have already install k3s using:</p>
<pre><code>export K3S_KUBECONFIG_MODE=&quot;644&quot;
curl -sfL https://get.k3s.io | sh -s - --docker
</code></pre>
<p>and kubectl using:</p>
<pre><code>snap install kubectl --classic
</code></pre>
<p>Does anyone know how to fix this?</p>

<p>The master copy is available at /etc/rancher/k3s/k3s.yaml. So, copy it back  to ~/.kube/config</p>
<pre><code>cp /etc/rancher/k3s/k3s.yaml ~/.kube/config
</code></pre>
<p>Reference: <a href="https://rancher.com/docs/k3s/latest/en/cluster-access/" rel="nofollow noreferrer">https://rancher.com/docs/k3s/latest/en/cluster-access/</a></p>
