Kubernetes error: Unable to connect to the server: dial tcp 127.0.0.1:8080
If you have kubectl already installed and pointing to some other environment, such as minikube or a GKE cluster, be sure to change context so that kubectl is pointing to docker-desktop:
kubectl config get-contexts
kubectl config use-context docker-desktop
Not sure if it applies to your environment, but I was having similar issue - any kubectl commands were returning:Unable to connect to the server: dial tcp [::1]:8080: connectex: No connection could be made because the target machine actively refused it.
127.0.0.1 is local host (IPV4), [::1] is the IPV6 equivalent.
kubectl appears to set up a local connection proxy on localhost to the cluster controller. In my case on a Windows10 pc, running the session ( in my case it was a powershell window) as administrator resolved the issue. Anyway, that was the fix for my environment.
It looks like the Kubernetes is not running on your machine. As your question doesn't mention the environment. I had similar issues with the following setup.
Windows 7 with Docker Toolbox 18.09.6
Kubernetes v1.14.3
minikube v1.1.1.
You would need to start Kubernetes and check if it displays the cluster information correctly before getting the pods. Run the following commands to setup & display cluster info.
minikube startkubectl cluster-infokubectl get pods