Kubectl command error The connection to the server localhost:8080 was refused

Hello there,

I have one master and two worker nodes (they’re all in my laptop using VirtualBox). The issue is when I run a command like kubectl get pods or kubectl run nginx --image=nginx, I get the below error:

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

I searched regarding this issue but almost all of the solutions were for the master node, but I’m in a worker node.

Would you please help me how to solve it?

Hey, @saeed
If you want to access your cluster from worker node then you have to run a few steps:
Worker node

  mkdir -p $HOME/.kube
  cp -i /etc/kubernetes/admin.conf $HOME/.kube/config   --> In this case, you have to use a `scp` command to copy `config` file from `master` to `worker` node. 
  chown $(id -u):$(id -g) $HOME/.kube/config