KasperT
KasperT

Reputation: 125

No connection could be made because the target machine actively refused it. "Kubernetes on Docker for Windows"

I have installed the Edge version of Docker for Windows 18.05.0-ce (Windows 10 Hyper-V) and enabled Kubernetes afterwards.
On my other machine a kubectl context was created automatically, but on this new machine it was not.

> kubectl config get-contexts
CURRENT   NAME      CLUSTER   AUTHINFO   NAMESPACE
> kubectl version
Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.3", GitCommit:"2bba0127d85d5a46ab4b778548be28623b32d0b0", GitTreeState:"clean", BuildDate:"2018-05-21T09:17:39Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"windows/amd64"}
Unable to connect to the server: dial tcp [::1]:8080: connectex: No connection could be made because the target machine actively refused it.

Can i some how make Docker for Windows create the context?
Or can I set it up manually?
I am a little unsure how to get the infomation needed for the kubectl config set-context command.

I can run docker containers outside of Kubernetes.
I see the Kubernetes containers running inside Docker.

> docker ps
CONTAINER ID        IMAGE                            COMMAND
8285ca0dd57a        353b8f1d102e                     "kube-scheduler --ad…"
3b25fdb0b7a6        40c8d10b2d11                     "kube-controller-man…"
e81db90fa68e        e03746fe22c3                     "kube-apiserver --ad…"
2f19e723e0eb        80cc5ea4b547                     "/kube-dns --domain=…"
etc...

Upvotes: 5

Views: 22048

Answers (5)

alwaysalive
alwaysalive

Reputation: 21

Apart from the above answers, there's a prerequisite to this, which might be your case too if you're using Docker Desktop. Took me some time to figure out and resolve. Just enable Kubernetes in the Docker Desktop settings. [Ignore if you already have] From 'settings' icon, you'll find 'Kubernetes'.

Executing the below command,

kubectl get nodes -v=10

gave me insight into the error

HTTP Trace: DNS Lookup for localhost resolved to [{::1 } {127.0.0.1 }]
HTTP Trace: Dial to tcp:[::1]:8080 failed: dial tcp [::1]:8080: connectex: No connection could be made because the target machine actively refused it.

With reference to this, Docker engine installs kubectl, and it will add it to the PATH, if I'm not wrong. So, the steps mentioned in some of the Kubernetes forums to manually create ~/.kube/config will not be advisable.

Upvotes: 1

Nicholas Namacha
Nicholas Namacha

Reputation: 19

When i had this issue it was because minikube was not running. Ensure minikube is up and running.

Upvotes: -2

jaxxstorm
jaxxstorm

Reputation: 13301

There is an issue with docker for windows when the HOMEDRIVE is set by a corporate policy.

If you set the $KUBECONFIG environment variable to C:\Users\my_username\.kube\config (make sure the $HOME environment variables expand, don't use $HOME itself.), it should work.

Further info: https://github.com/docker/for-win/issues/1651

Upvotes: 5

Neeraj Singh Negi
Neeraj Singh Negi

Reputation: 363

Run commands to overcome (connectex: No connection could be made because the target machine actively refused it) issue.

minikube delete 
minikube start

Upvotes: -2

KasperT
KasperT

Reputation: 125

I found that Docker for Windows correctly updated my kubectl config file, but on Windows 10 Enterprise there is no environment variable called "HOME".

So kubectl cant find the config file, C:\users\{userid}\.kube\config

Adding environment variable HOME=C:\users\{userid} solved the issue on my machine.

See: https://github.com/docker/for-win/issues/2066

Upvotes: 4

Related Questions