Unable to connect to the server: dial tcp [::1]:8080: connectex: No connection could be made because the target machine actively refused it
Solution 1
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.
For reference follow this Deploy an Azure Kubernetes Service (AKS) cluster.
Solution 2
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/
Solution 3
I am on windows 10, and for me I did not enable kubernetes.
As you can see here, there are no contexts available.
So go to settings of docker desktop and enable it as follows.
Now run a command as follows.
kubectl config get-contexts
Ensure you see something like this.
Also you can also try listing the nodes as follows.
kubectl get nodes
Solution 4
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.
PS: make sure your cluster is started as shown in this picture showing (Stop local cluster)
Solution 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.
Comments
-
Mani over 2 years
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?”
-
user1769790 about 4 yearswhat context should i set?
-
Steven Van Dorpe about 4 yearsFor Windows 10: running command line as an administrator resolved the issue.
-
sunny arya almost 4 yearswhen you answer, please provide enough details, what is the significance of context ?? What should the context be set to ??
-
Manolis Pap over 2 yearsThe first part was enough for me. The
config
file was missing completely. -
sxddhxrthx over 2 yearsThis 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?