Search code examples
dockerkubernetesdocker-desktop

Docker for Desktop Kubernetes Unable to connect to the server: dial tcp [::1]:6445


I am using Docker for Desktop on Windows 10 Professional with Hyper-V, also I am not using minikube. I have installed Kubernetes cluster via Docker for Desktop, as shown below:

enter image description here

It shows the Kubernetes is successfully installed and running.

When I run the following command:

kubectl config view

I get the following output:

apiVersion: v1
clusters:
- cluster:
  insecure-skip-tls-verify: true
  server: https://localhost:6445
  name: docker-for-desktop-cluster
contexts:
 - context:
   cluster: docker-for-desktop-cluster
   user: docker-for-desktop
   name: docker-for-desktop
   current-context: docker-for-desktop
kind: Config
preferences: {}
users:
- name: docker-for-desktop
user:
  client-certificate-data: REDACTED
  client-key-data: REDACTED

However when I run the

kubectl cluster-info

I am getting the following error:

Unable to connect to the server: dial tcp [::1]:6445: connectex: No connection could be made because the target machine actively refused it.

It seems like there is some network issue, I am not sure how to resolve this.


Solution

  • I know this is an old question but the following helped me to resolve a similar issue. The root cause was that I had minikube installed previously and that was being used as my default context. I was getting following error:

    Unable to connect to the server: dial tcp 192.168.1.8:8443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
    

    In the power-shell run the following command:

    > kubectl config get-contexts
    CURRENT   NAME                 CLUSTER          AUTHINFO         NAMESPACE
          docker-desktop       docker-desktop   docker-desktop
          docker-for-desktop   docker-desktop   docker-desktop
    *     minikube             minikube         minikube
    

    this will list all the contexts and see if there are multiple. If you had installed minikube in the past, that will show a * mark as currently selected default context. You can change that to point to docker-desktop context like follows:

    > kubectl config use-context docker-desktop
    

    Run the get-contexts command again to verify the * mark.

    Now, the following command should work:

    > kubectl get pods