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

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.


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/


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.