kubectl: Connection to server was refused

In my case, working with minikube I had not started minikube. Starting minikube with

minikube start

fixed it.


In most cases, this means a missing kubeconfig file. kubectl is trying to use the default values when there is no $HOME/.kube/config. You must create or copy a valid config file to solve this problem. For example if you are using kubeadm you can solve this with:

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

Alternatively you can also export KUBECONFIG variable like this:

export KUBECONFIG=/etc/kubernetes/admin.conf