Facing connection issue to localhost:8080 while using the CMD kubectl version

The connection to the server localhost:8080 was refused - did you specify the right host or port?

Hello team,

I have installed kubernetes in my mac arm64(m1).
After installation when i was checking the version with the below command.

kubectl version

I am getting the following error

The connection to the server localhost:8080 was refused - did you specify the right host or port?

then i also tried

mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

but still i am getting the error as follows

cp: /etc/kubernetes/admin.conf: No such file or directory

Can anyone please help me with this ?

The error message The connection to the server localhost:8080 was refused suggests that the Kubernetes control plane is not running or not reachable on your local machine.

The error message “cp: /etc/kubernetes/admin.conf: No such file or directory” suggests that there is no admin configuration file present in the directory /etc/kubernetes/. This could mean that the kubeadm tool which you used to install Kubernetes on your machine, did not complete the installation successfully.

Can you try these suggestions?

  1. Verify that the Kubernetes control plane components (kube-apiserver, kube-controller-manager, kube-scheduler) are running on your machine by running the command kubectl get pods --all-namespaces. You should see the control plane pods in the kube-system namespace if they are running.
  2. Verify that the Kubernetes API server is listening on the correct IP address and port by running the command kubectl cluster-info. You should see the correct endpoint for the API server.
  3. Verify that the kubeadm was installed properly, by running kubeadm version. If you don’t see the version number, it’s possible kubeadm is not installed on your machine.
  4. If kubeadm was not installed, you should install it, if it’s installed, try running kubeadm init again. This command will initialize the control plane on your machine and create the necessary configuration files.
  5. If you are running the Kubernetes cluster on the Apple M1 chip, it’s possible that your version of kubeadm is not compatible with the chip architecture, Try checking the Kubernetes documentation for any known issues or troubleshoot guides related to running on M1.