Search code examples
kuberneteskubectlk3d

The connection to the server localhost:8080 was refused in kubectl


I installed kubectl and k3d after following these official documentations (k3d and kubectl).
I created a cluster with the following command:

k3d cluster create mycluster

Then I ran this command:

kubectl cluster-info

Which gave me this error message:
The connection to the server localhost:8080 was refused - did you specify the right host or port?

After searching I found that the file /etc/kubernetes wasn't created (which means no admin.conf file was created), and the folder ~/.kube also doesn't exist.
PS: see this answer to understand

Here are the versions of k3d and kubectl

$ k3d version
k3d version v5.4.9
k3s version v1.25.7-k3s1 (default)
$ kubectl version --short
Client Version: v1.25.2
Kustomize Version: v4.5.7

Solution

  • Check Kubeadm was properly installed or not?. The command kubeadm version helps you to know the running status of kubeadm.

    Note : If you can see the kubeadm version number, your kubeadm was installed properly.

    And also run kubeadm init to initialize the control plane on your machine and create the necessary configuration files. See Kubernetes Community forum issue for more information.

    You may haven’t set the kubeconfig environment variable and the .kube/config file is not exported to the user $HOME directory.

    See Nijo Luca’s blog on k21 academy for more information, which may help to resolve your issue.