Unable to connect to the server: dial tcp [::1]:8080: connectex: No connection could be made because the target machine actively refused it
Asked Answered
R

21

58

Am working on Azure Kubernates where we can store Docker Images in Azure. Here am trying to check my kubectl version, then am getting

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

For this I followed MSDN:uilding Microservices with AKS and VSTS – Part 2 and MSDOCS:Kubernetes on windows

So, can you please suggest me “How to resolve for this issue?”

Raychel answered 23/5, 2018 at 14:19 Comment(1)
I am getting the same issue on kubectl cluster-infoMartres
A
39

I think you might missed out to configure the cluster, for that you need to run the below command in your command prompt.

az aks get-credentials --resource-group myResourceGroup --name myAKSCluster

The above CLI command creates .config file with complete cluster and nodes details in your local machine.

After that you run kubectl get nodes command in your command prompt, then you can get the list of nodes inside the cluster like in the below image.

enter image description here For reference follow this Deploy an Azure Kubernetes Service (AKS) cluster.

Ankylose answered 30/5, 2018 at 12:49 Comment(1)
I ran the az login --scope https://management.core.windows.net//.default and logged in to my account. Next, I executed the az aks ... and the kubectl get nodes command. However, I still get tls: failed to verify certificate: x509 error. What am I missing?Dick
L
57

I am on windows 10, and for me I did not enable kubernetes on Docker Desktop.

As you can see here, there are no contexts available.

docker-desktop kubernetes context

So go to settings of docker desktop and enable it as follows.

docker-desktop enable kubernetes

Now run a command as follows.

kubectl config get-contexts

Ensure you see something like this.

kubectl contexts on command line

Also you can also try listing the nodes as follows.

kubectl get nodes

enter image description here

Latinize answered 8/8, 2021 at 13:45 Comment(2)
Enabling Kubernetes results with a bunch of new docker images. For example docker/desktop-storage-provisioner:v2.0, registry.k8s.io/kube-apiserver:v1.25.9, hubproxy.docker.internal:5555/docker/..., and alike. After disabling the settings, the docker images are not deleted. How to delete all kubernetes docker images automatically if I would like to disable it?Dick
If you want to delete the docker images/containers that are created then follow these steps. First, delete the docker-desktop node by executing kubectl drain docker-desktop --ignore-daemonsets --delete-local-data --force and kubectl delete node docker-dekstop commands. Second, disable Kubernetes by unchecking the "Enable Kubernetes" option. After that, go to the "Images" plane and delete all the docker image. Docker image start with docker/desktop..., hubproxy.docker...., and registry.k8s.io/... name.Dick
A
39

I think you might missed out to configure the cluster, for that you need to run the below command in your command prompt.

az aks get-credentials --resource-group myResourceGroup --name myAKSCluster

The above CLI command creates .config file with complete cluster and nodes details in your local machine.

After that you run kubectl get nodes command in your command prompt, then you can get the list of nodes inside the cluster like in the below image.

enter image description here For reference follow this Deploy an Azure Kubernetes Service (AKS) cluster.

Ankylose answered 30/5, 2018 at 12:49 Comment(1)
I ran the az login --scope https://management.core.windows.net//.default and logged in to my account. Next, I executed the az aks ... and the kubectl get nodes command. However, I still get tls: failed to verify certificate: x509 error. What am I missing?Dick
C
18

If you can see that your config file is correctly configured by going to $HOME/.kube/config - Linux or %UserProfile%/.kube/config - Windows but you are still receiving the error message - try running command line as an administrator.

More information on the config file can be found here: https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/

Cindiecindra answered 30/4, 2019 at 9:43 Comment(4)
For Windows 10: running command line as an administrator resolved the issue.Teena
The first part was enough for me. The config file was missing completely.Ennead
This is actually the right one for me. I was running another context mini-kubeKienan
This solves the problem for me on Windows (PowerShell) - make sure the user C:\Users\<admin-user> has the config file. In my case I found and copied it from a non-admin user C:\Users\<non-admin-user>\.kube\configStability
T
9

In my case, I was shuffling between az aks k8s cluster and local docker-desktop.

So every time I change the cluster context I need to restart the docker, else I get the same described error.

Unable to connect to the server: dial tcp 127.0.0.1:6443: connectex: No connection could be made because the target machine actively refused it.

enter image description here

PS: make sure your cluster is started as shown in this picture showing (Stop local cluster)

Transalpine answered 15/6, 2020 at 17:58 Comment(1)
This error pops up for me only when I try to do a curl or HTTP requests. When I try executing kubectl get pods it works fine for me. Any suggestions on what can I do to make it work for HTTP requests?Heterocyclic
B
7

Essentially this problem occurs if your minikube or kind isn't configured. Just try to restart your minikube or kind. If that doesn't solve your problem then try to restart your hypervisor which minikube uses.

minikube start

This command solved my issue.

Baggy answered 28/1, 2021 at 15:31 Comment(0)
A
5

For me it appeared to be due to Windows not having a HOME environment variable set. According to the docs kubectl will use the config file $(HOME)/.kube/config. But since this variable isn't set on Window it can't locate the file.

I created a HOME variable with the same value as USERPROFILE and it started working.

Andrade answered 10/4, 2019 at 12:34 Comment(0)
B
5

Check docker is running and you started minikube or whichever cloud kube you using. my issue resolved after running "minikube start --driver=docker"

Barrera answered 14/7, 2020 at 13:42 Comment(0)
A
4

I'm using Hyper-V on Local Windows and I met this error because I didn't configure minikube.

(I know the question is about Azure, not minikube. But this article is on the top for the error message. So, I've put the solution here.)

1. enable Hyper-V.

Type in systeminfo on your Terminal. If you can find the line below,

Hyper-V Requirements:     A hypervisor has been detected. Features required for Hyper-V will not be displayed.

Hyper-V works correctly.

If you can't, enable it from settings.

2. Create Hyper-V Network Switch

Open Hyper-V manager. (Searching it is the fastest way.)

Next, click your PC name on the left.

Then, you can find Virtual Switch Manager menu on the right.

Click it and choose External Virtual Switch with name: "Minikube Switch"

Click apply to create it.

3. start minikube

Go back to terminal and type in:

minikube start --vm-driver hyperv --hyperv-virtual-switch "Minikube Switch"

For more information, check the steps in this article.

Aquiver answered 16/8, 2019 at 21:47 Comment(0)
P
3

I was facing the same error while firing the command "kubectl get pods"

The issue has been resolved by having following steps below:

a) First find out current-context

kubectl config get-contexts
CURRENT   NAME      CLUSTER   AUTHINFO   NAMESPACE

b) if no context is set then set it manually by using

kubectl config set-context <Your context>

Hope this will help you.

Payment answered 18/1, 2019 at 7:23 Comment(2)
what context should i set?Pediatrics
when you answer, please provide enough details, what is the significance of context ?? What should the context be set to ??Neomaneomah
B
3

If you're facing this error on windows, its possible that your docker instance is not running.

These are the steps I followed to replicate the above error;

  1. Stopped docker and then tried to start-up an nginx-deployment. Doing this caused the mentioned error above to happen.

enter image description here

How did I solve it?

  1. Check if minikube is running in my case this was not running enter image description here

  2. Start minikube enter image description here

  3. Retry applying your configuration above. In my case see the screenshot below

enter image description here

  1. When you see that your deployment has been created, then all should be fine.
Bezique answered 4/11, 2021 at 22:10 Comment(0)
A
2

I faced the same issue after enabling kubenetes from the Docker Desktop running on Windows 10 Professional. I followed the instruction here https://www.ntweekly.com/2018/05/08/kubernetes-windows-error-unable-connect-server-dial-tcp-16445-connectex-no-connection-made-target-machine-actively-refused/ and it solved my issue. In summary,

  1. I opened powershell as admin and ran [Environment]::SetEnvironmentVariable("KUBECONFIG", $HOME + ".kube\config", [EnvironmentVariableTarget]::Machine).
  2. Next I went to Docker Desktop settings and reset kubenetes. That solved it. enter image description here
Asocial answered 16/4, 2023 at 15:41 Comment(0)
N
1

I had exactly the same problem even after having correct config (by running an azure cli command).

It seems that kubectl expects HOME env.variable set but it did not exist for me. There is however a solution:

If you add a KUBECONFIG environmental variable that will point to config it will start working.

Example:

setx KUBECONFIG %UserProfile%\.kube\config

When the variable is present kubectl has no troubles reading from file.

P.S. It is an alternative to setting a HOME variable as suggested in another answer.

Nnw answered 12/9, 2019 at 14:16 Comment(0)
E
1

Azure self-hosted agent doesn't have the permission to access Kubernates cluster:

Remove Azure self-hosted agent -  .\config.cmd Remove
configure again ( .\config.cmd) with a user have permission to access Kubernates cluster
Everetteverette answered 6/1, 2021 at 11:57 Comment(0)
F
1

I was facing the same issue in windows.
After changing the Kubernetes running from minikube to docker-desktop, my problem was resolved.
enter image description here

ps: if you haven't enabled kubernetes in docker-desktop, please enable it first.

Faber answered 6/3, 2023 at 19:2 Comment(0)
D
0

I encountered similar problem:

> kubectl cluster-info
"To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
Unable to connect to the server: dial tcp xxx.x.x.x:8080: connectex: No connection could be made because the target machine actively refused it."

> kubectl cluster-info dump
Unable to connect to the server: dial tcp xxx.0.0.x:8080: connectex: No connection could be made because the target machine actively refused it.

This setup was working fine until Docker for Desktop bought it's own copy of kubectl. There are 2 ways to overcome this situation:

1 - Quit / Stop Docker for Desktop while using the cluster

2 - Set KUBECONFIG file path

I tried both the options and they worked.

Found a good source for .kube/config, sending it over here for quick reference:

apiVersion: v1
clusters:
- cluster:
    certificate-authority: fake-ca-file
    server: https://1.2.3.4
  name: development
- cluster:
    insecure-skip-tls-verify: true
    server: https://5.6.7.8
  name: scratch
contexts:
- context:
    cluster: development
    namespace: frontend
    user: developer
  name: dev-frontend
- context:
    cluster: development
    namespace: storage
    user: developer
  name: dev-storage
- context:
    cluster: scratch
    namespace: default
    user: experimenter
  name: exp-scratch
current-context: ""
kind: Config
preferences: {}
users:
- name: developer
  user:
    client-certificate: fake-cert-file
    client-key: fake-key-file
- name: experimenter
  user:
    password: some-password
    username: exp

Reference: https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/
Deel answered 26/8, 2020 at 9:47 Comment(0)
G
0

Following @ilya-chernomordik, I've added my config path to the System Variable by doing

setx KUBECONFIG "D:\Minikube\Minikube.minikube\config"

I have changed the default Location from C: Drive to D: Drive as i have less space in C.

Now the problem is fixed.

edit: after 5 mins, the api server again stopped. It's been more than 5-6 hours i'm trying to solve this issue. I'm not sure why this problem is happening, even after adding the coreect path.

Gentianella answered 5/12, 2020 at 12:26 Comment(0)
U
0

On Rancher Desktop, make sure context is correctly choosen

enter image description here

Unbridled answered 29/9, 2022 at 9:35 Comment(0)
H
0

For wsl on Windows.

If your k8s cluster is running on wsl and you are getting this error from your ide on windows or windows command line, copy over your kubeconfig from wsl to your .kube folder inside C:/Users/<your_username>

and recheck.

Hebert answered 4/5, 2023 at 4:52 Comment(0)
R
0

I just tried

minikube stop

and

minikube start

this will solve this issue.

Randolphrandom answered 16/5 at 15:50 Comment(0)
D
0
minikube start

will fix the error, but make sure that the minikube container is running and not paused.

Daman answered 27/5 at 10:40 Comment(0)
B
-1

In my situation, I'm in windows with docker desktop in a simple scenario just for studies, but the case is:

In the docker version in 20.10 or above, it come with kubernetes installed. Then it doesn't necessary installed a cluster adm like minikube. Then, when it just need to enable kubernetes in Docker Desktop configuration. Like:

Go to Docker Desktop: settings > kubernetes > check the box inside section Enable kubernetes and then click in Restart Kubernetes Cluster

When we do this, the docker provide all needed to works Kubernetes properly.

Referenced by: Blog

Barolet answered 8/6, 2022 at 0:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.