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

ぃ、小莉子 提交于 2021-02-18 11:45:15

问题


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?


回答1:


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




回答2:


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.




回答3:


The Kubernetes server API seems invalid:

curl -LIk https://zlt20087.vci.co.com
HTTP/1.1 301 Moved Permanently
Date: Wed, 02 Jan 2019 21:43:24 GMT
Server: Apache
Location: https://registry.co.com
Content-Type: text/html; charset=iso-8859-1

HTTP/1.1 403 Forbidden
Date: Wed, 02 Jan 2019 21:43:24 GMT
Server: Apache
Vary: User-Agent
Accept-Ranges: bytes
Content-Type: text/html

Are you sure the URL is correct?




回答4:


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



来源:https://stackoverflow.com/questions/54012973/kubernetes-error-unable-to-connect-to-the-server-dial-tcp-127-0-0-18080

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!