kubectl: Connection to server was refused kubectl: Connection to server was refused docker docker

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/.kubesudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/config

Alternatively you can also export KUBECONFIG variable like this:

export KUBECONFIG=/etc/kubernetes/admin.conf


I really don't know much about kubectl... But the various reasons you have a connection refused to localhost I know of are as follows

  • 1) Make sure you can resolve and ping your local host with the IP(127.XX.XX.XX) and also "localhost" if using a DNS or host file.

  • 2) Make sure the service trying to access the localhost has enough permissions to run as root if trying to use localhost.

  • 3) Check the ports with netstat and check for the appropriate flags you need amongst the "Plantu" flags, Look up the meaning of each of the flags as it would apply to your situation. If the service you are trying to access on localhost is listening on that port, netstat would let you know.

  • 4) Check if you have admin or management settings in your application that needs permissions to access your localhost in the configuration parameters of your application.

  • 5) According to the statement that says did you specify the right host or port, this means that either your "kubectl" run is not configured to run as localhost instead your primary DNS server hostname or IP, Check what host is configured to run your application and like I said check for the appropriate ports to use, You can use telnet to check this port and further troubleshoot form there.

My two cents!