【问题标题】:Unable to connect to the server: dial tcp [::1]:8080: connectex: No connection could be made because the target machine actively refused it无法连接服务器: dial tcp [::1]:8080: connectex: No connection could be made because the target machine主动拒绝
【发布时间】:2018-11-02 14:05:29
【问题描述】:

我正在开发 Azure Kubernates,我们可以在其中将 Docker 映像存储在 Azure 中。在这里我试图检查我的 kubectl 版本,然后我得到了

无法连接到服务器:dial tcp [::1]:8080: connectex: No 可以建立连接,因为目标机器主动拒绝 它。

为此,我关注了MSDN:uilding Microservices with AKS and VSTS – Part 2MSDOCS:Kubernetes on windows

那么,您能否建议我“如何解决此问题?”

【问题讨论】:

  • 我在kubectl cluster-info上遇到了同样的问题

标签: powershell azure azure-cli azure-container-service azure-aks


【解决方案1】:

如果您在 Windows 上遇到此错误,则可能是您的 docker 实例未运行。

这些是我复制上述错误所遵循的步骤;

  1. 停止 docker,然后尝试启动 nginx 部署。这样做会导致发生上述错误。

我是怎么解决的?

  1. 在我的情况下检查 minikube 是否正在运行,这没有运行

  2. 启动 minikube

  3. 重试应用上面的配置。就我而言,请参见下面的屏幕截图

  1. 当您看到您的部署已创建时,那么一切都应该没问题。

【讨论】:

    【解决方案2】:

    我在 Windows 10 上,对我来说,我没有启用 kubernetes。

    正如您在此处看到的,没有可用的上下文。

    所以进入 docker 桌面的设置并启用它,如下所示。

    现在运行如下命令。

    kubectl config get-contexts
    

    确保您看到类似这样的内容。

    您也可以尝试如下列出节点。

    kubectl get nodes
    

    【讨论】:

      【解决方案3】:

      如果您的 minikube 或 kind 未配置,基本上会出现此问题。只需尝试重新启动您的 minikube 或 kind。如果这不能解决您的问题,请尝试重新启动 minikube 使用的管理程序。

      minikube start
      

      这个命令解决了我的问题。

      【讨论】:

        【解决方案4】:

        Azure 自托管代理无权访问 Kubernetes 集群:

        Remove Azure self-hosted agent -  .\config.cmd Remove
        configure again ( .\config.cmd) with a user have permission to access Kubernates cluster
        

        【讨论】:

          【解决方案5】:

          在@ilya-chernomordik 之后, 我已经通过这样做将我的配置路径添加到系统变量中

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

          我已将默认位置从 C: Drive 更改为 D: Drive 因为我在 C 中的空间较小。

          现在问题解决了。

          编辑:5 分钟后,api 服务器再次停止。我试图解决这个问题已经超过 5-6 个小时。我不确定为什么会出现这个问题,即使添加了 coreect 路径。

          【讨论】:

            【解决方案6】:

            我遇到了类似的问题:

            > 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.
            

            在 Docker for Desktop 购买了它自己的 kubectl 副本之前,此设置运行良好。有两种方法可以克服这种情况:

            1 - 使用集群时退出/停止 Docker for Desktop

            2 - 设置 KUBECONFIG 文件路径

            我尝试了这两个选项,它们都奏效了。

            为 .kube/config 找到了一个很好的来源,将其发送到这里以供快速参考:

            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/
            

            【讨论】:

              【解决方案7】:

              检查 docker 是否正在运行,并且您启动了 minikube 或您使用的任何云 kube。 运行“minikube start --driver=docker”后我的问题解决了

              【讨论】:

                【解决方案8】:

                就我而言,我在 az aks k8s 集群和本地 docker-desktop 之间切换。

                所以每次我更改集群上下文时,我都需要重新启动 docker,否则我会得到相同的描述错误。

                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:确保您的集群已启动,如图所示(停止本地集群)

                【讨论】:

                • 只有当我尝试执行 curl 或 HTTP 请求时才会弹出此错误。当我尝试执行kubectl get pods 时,它对我来说很好。关于如何使其适用于 HTTP 请求的任何建议?
                【解决方案9】:

                即使在配置正确后(通过运行 azure cli 命令),我也遇到了完全相同的问题。

                似乎 kubectl 需要 HOME env.variable 集,但它对我来说并不存在。但是有一个解决方案:

                如果您添加一个指向 config 的 KUBECONFIG 环境变量,它将开始工作。

                例子:

                setx KUBECONFIG %UserProfile%\.kube\config
                

                当变量存在时,kubectl 从文件中读取没有问题。

                附:它是另一个答案中建议的设置 HOME 变量的替代方法。

                【讨论】:

                  【解决方案10】:

                  我在本地 Windows 上使用 Hyper-V,我遇到了这个错误,因为我没有配置 minikube。

                  (我知道问题是关于 Azure,而不是 minikube。但是这篇文章在错误消息的顶部。所以,我把解决方案放在这里。)

                  1.启用 Hyper-V。

                  在您的终端上输入systeminfo。如果你能找到下面的行,

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

                  Hyper-V 工作正常。

                  如果你不能,enable it from settings.

                  2。创建 Hyper-V 网络交换机

                  打开 Hyper-V 管理器。 (搜索是最快的方法。)

                  接下来,单击左侧的 PC 名称。

                  然后,您可以在右侧找到 Virtual Switch Manager 菜单。

                  单击它并选择名称为“Minikube Switch”的外部虚拟交换机

                  点击应用创建它。

                  3.启动 minikube

                  返回终端并输入:

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

                  更多信息,check the steps in this article

                  【讨论】:

                    【解决方案11】:

                    如果您可以通过转到 $HOME/.kube/config - Linux%UserProfile%/.kube/config - Windows 看到您的配置文件已正确配置,但您仍然收到错误消息- 尝试以管理员身份运行命令行。

                    关于配置文件的更多信息可以在这里找到:https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/

                    【讨论】:

                    • 对于 Windows 10:以管理员身份运行命令行解决了该问题。
                    • 第一部分对我来说已经足够了。 config 文件完全丢失。
                    【解决方案12】:

                    对我来说,这似乎是由于 Windows 没有设置 HOME 环境变量。根据文档kubectl 将使用配置文件$(HOME)/.kube/config。但由于此变量未在 Window 上设置,因此无法找到该文件。

                    我创建了一个与 USERPROFILE 具有相同值的 HOME 变量,它开始工作。

                    【讨论】:

                      【解决方案13】:

                      我在执行“kubectl get pods”命令时遇到了同样的错误

                      通过以下步骤解决了该问题:

                      a) 首先找出当前上下文

                      kubectl config get-contexts
                      CURRENT   NAME      CLUSTER   AUTHINFO   NAMESPACE
                      

                      b) 如果没有设置上下文,则使用手动设置它

                      kubectl config set-context <Your context>
                      

                      希望这会对你有所帮助。

                      【讨论】:

                      • 我应该设置什么上下文?
                      • 回答时,请提供足够的细节,上下文的意义是什么?上下文应该设置为什么??
                      【解决方案14】:

                      我认为您可能错过了配置集群,因为您需要在命令提示符下运行以下命令。

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

                      上述 CLI 命令会在您的本地计算机中创建包含完整集群和节点详细信息的 .config 文件。

                      之后在命令提示符下运行kubectl get nodes 命令,就可以得到集群内的节点列表,如下图所示。

                      参考Deploy an Azure Kubernetes Service (AKS) cluster

                      【讨论】:

                        猜你喜欢
                        • 2020-12-11
                        • 2018-12-16
                        • 2019-12-07
                        • 2020-07-05
                        • 2016-07-25
                        • 1970-01-01
                        • 2018-01-22
                        • 2022-01-23
                        • 2019-02-01
                        相关资源
                        最近更新 更多