<p>I installed <code>kubectl</code> and <code>k3d</code> after following these official documentations (<a href="https://k3d.io/v5.4.9/" rel="nofollow noreferrer">k3d</a> and <a href="https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/" rel="nofollow noreferrer">kubectl</a>).<br />
I created a cluster with the following command:</p>
<pre><code>k3d cluster create mycluster
</code></pre>
<p>Then I ran this command:</p>
<pre><code>kubectl cluster-info
</code></pre>
<p>Which gave me this error message:<br />
<code>The connection to the server localhost:8080 was refused - did you specify the right host or port?</code></p>
<p>After searching I found that the file <code>/etc/kubernetes</code> wasn't created (which means no <code>admin.conf</code> file was created), and the folder <code>~/.kube</code> also doesn't exist.<br />
PS: see <a href="https://stackoverflow.com/a/52262765/15368012">this answer</a> to understand</p>
<p>Here are the versions of <code>k3d</code> and <code>kubectl</code></p>
<pre><code>$ k3d version
k3d version v5.4.9
k3s version v1.25.7-k3s1 (default)
</code></pre>
<pre><code>$ kubectl version --short
Client Version: v1.25.2
Kustomize Version: v4.5.7
</code></pre>

arrmani88
<p>Check Kubeadm was properly installed or not?. The command <code>kubeadm version</code> helps you to know the running status of kubeadm.</p>
<p><strong>Note :</strong> If you can see the kubeadm version number, your kubeadm was installed properly.</p>
<p>And also run <code>kubeadm init</code> to initialize the control plane on your machine and create the necessary configuration files. See <a href="https://discuss.kubernetes.io/t/facing-connection-issue-to-localhost-8080-while-using-the-cmd-kubectl-version/22644" rel="nofollow noreferrer">Kubernetes Community forum</a> issue for more information.</p>
<blockquote>
<p>You may haven’t set the kubeconfig environment variable and the
<code>.kube/config</code> file is not exported to the user $HOME directory.</p>
</blockquote>
<p>See <strong>Nijo Luca’s</strong> <a href="https://k21academy.com/docker-kubernetes/the-connection-to-the-server-localhost8080-was-refused/" rel="nofollow noreferrer">blog</a> on <strong>k21 academy</strong>  for more information, which may help to resolve your issue.</p>
