docker desktop k8s错误Unable to connect to the server: EOF

发布时间 2023-03-30 20:01:50作者: 徐风吟

问题

当使用 Docker Desktop 开启 Kubernetes 之后,在终端执行命令 kubectl get nodes 时,出现以下错误:

Unable to connect to the server: EOF

根因分析

终端执行命令 kubectl cluster-info,输出如下:

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
error: Get "https://kubernetes.docker.internal:6443/api?timeout=32s": net/http: TLS handshake timeout - error from a previous attempt: EOF

说明现在没法访问到 kubernetes.docker.internal,查看一下本机 hosts 文件发现新增了以下配置:

# Added by Docker Desktop
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal

这个时候问题就显而易见了,由于我本机 Shell 使用了 proxy 配置,而代理没有忽略 Docker 的这个特殊域名。

解决方案

kubernetes.docker.internal 添加到 NO_PROXY 环境变量中。

image


image