Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes error: Unable to connect to the server: dial tcp 127.0.0.1:8080

I'm seeing the following error when running kubectl get pods:

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

This was working when I ran it two weeks ago. My config file in the ~/.kube/config directory looks as follows:

apiVersion: v1
clusters:
- cluster:
    insecure-skip-tls-verify: true
    server: https://zld05687.vci.co.com
  name: dev-cluster
- cluster:
    insecure-skip-tls-verify: true
    server: https://zlt20087.vci.co.com
  name: perf-cluster
- cluster:
    insecure-skip-tls-verify: true
    server: https://zlt17291.vci.co.com
  name: test-cluster
contexts:
- context:
    cluster: dev-cluster
    namespace: com-co-acp-dev
    user: default-user
  name: default-context
- context:
    cluster: perf-cluster
    namespace: com-co-acp-perf
    user: default-user
  name: perf-context
- context:
    cluster: test-cluster
    namespace: com-co-acp-test
    user: default-user
  name: test-context
current-context: perf-context
kind: Config
preferences: {}
users:
- name: default-user
  user:
    token: myusername:enc:23hfeu39393yd223944uekd

What caused this error, and how can I fix it?

like image 796
kramsiv94 Avatar asked Jan 02 '19 20:01

kramsiv94


3 Answers

If you have kubectl already installed and pointing to some other environment, such as minikube or a GKE cluster, be sure to change context so that kubectl is pointing to docker-desktop:

  1. kubectl config get-contexts

  2. kubectl config use-context docker-desktop

like image 176
Jeff Avatar answered Oct 19 '22 02:10

Jeff


It looks like the Kubernetes is not running on your machine. As your question doesn't mention the environment. I had similar issues with the following setup.

Windows 7 with Docker Toolbox 18.09.6

Kubernetes v1.14.3

minikube v1.1.1.

You would need to start Kubernetes and check if it displays the cluster information correctly before getting the pods. Run the following commands to setup & display cluster info.

minikube start

kubectl cluster-info

kubectl get pods

enter image description here

enter image description here

like image 4
ekhanna Avatar answered Oct 19 '22 04:10

ekhanna


Not sure if it applies to your environment, but I was having similar issue - any kubectl commands were returning: Unable to connect to the server: dial tcp [::1]:8080: connectex: No connection could be made because the target machine actively refused it.

127.0.0.1 is local host (IPV4), [::1] is the IPV6 equivalent.

kubectl appears to set up a local connection proxy on localhost to the cluster controller. In my case on a Windows10 pc, running the session ( in my case it was a powershell window) as administrator resolved the issue. Anyway, that was the fix for my environment.

like image 3
Mark A Avatar answered Oct 19 '22 04:10

Mark A