Docker Desktop on Windows11: kubectl get pods gives error on my laptop: The connection to the server 127.0.0.1:49994 was refused

huangapple go评论51阅读模式
英文:

Docker Desktop on Windows11: kubectl get pods gives error on my laptop: The connection to the server 127.0.0.1:49994 was refused

问题

我想在本地运行Kubernetes,以便我可以在我编写的一个小Java程序上尝试它。

我在我的Windows 11笔记本电脑上安装了WSL2,Docker Desktop,并在Docker设置中启用了Kubernetes。

有许多与相同错误相关的Stack Overflow问题,但我没有看到其中任何一个涉及Windows 11和Docker Desktop的问题。

我打开一个终端,键入wsl以打开Linux终端。然后我输入以下命令:

$ kubectl get pods
无法连接到服务器127.0.0.1:49994 - 您是否指定了正确的主机或端口?

但是我看到了下面的图片:

Docker Desktop on Windows11: kubectl get pods gives error on my laptop: The connection to the server 127.0.0.1:49994 was refused

英文:

I want to run Kubernetes locally so I can try it out on a small Java program I have written.

I installed WSL2 on my Windows 11 laptop, Docker Desktop, and enabled Kubernetes in Docker Settings.

There are a number of SO questions with the same error but I do not see any of them regarding Windows 11 and Docker Desktop.

I open a terminal, type wsl to open a linux terminal. Then I issue the command:

$ kubectl get pods
The connection to the server 127.0.0.1:49994 was refused - did you specify the right host or port?

but I see

Docker Desktop on Windows11: kubectl get pods gives error on my laptop: The connection to the server 127.0.0.1:49994 was refused

答案1

得分: 1

使用Docker Desktop和Kubernetes在Linux Ubuntu上,我遇到了相同的错误,但也因为我已经在我的机器上安装了Docker而导致Docker Desktop无法正常启动,结果是docker上下文被设置为默认的Docker环境,而不是所需的Docker Desktop。

首先确认以下内容:

  1. 确保kubectl**已正确安装,并且~/.kube/config文件存在并在您的机器上正确配置,因为它包含集群信息的配置和连接端口,这两者都被kubectl使用。

  2. 使用以下命令检查上下文:

    kubectl config view

  3. 如果未设置为current-context:docker-desktop,例如:

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: DATA+OMITTED
    server: https://kubernetes.docker.internal:6443
  name: docker-desktop
contexts:
- context:
    cluster: docker-desktop
    user: docker-desktop
  name: docker-desktop
current-context: docker-desktop
kind: Config
preferences: {}
users:
- name: docker-desktop
  user:
    client-certificate-data: REDACTED
    client-key-data: REDACTED

然后将docker上下文设置为您的机器上的Docker Desktop

kubectl config use-context docker-desktop

如果这不能解决您的问题,也许您需要检查特定于Windows 11 Docker Desktop Kubernetes配置/功能

还要检查:
Docker Desktop Windows常见问题解答

英文:

Using Docker Desktop and Kubernetes on Linux Ubuntu, I got the same error, but also with Docker Desktop being unable to start normally because I already had a Docker Installation on my machine, resulting in the docker context being set to the default Docker environment instead of the required Docker Desktop.

Confirm the following first:

  1. Make sure kubectl is correctly installed and ~/.kube/config file exists and is correctly configured on your machine because it holds the configuration of the cluster info and the port to connect to, which both are used by kubectl.

  2. Check the context with

    kubectl config view

  3. If not set to current-context: docker-desktop, for example

   apiVersion: v1
   clusters:
   - cluster:
       certificate-authority-data: DATA+OMITTED
       server: https://kubernetes.docker.internal:6443
     name: docker-desktop
   contexts:
   - context:
       cluster: docker-desktop
       user: docker-desktop
     name: docker-desktop
   current-context: docker-desktop
   kind: Config
   preferences: {}
   users:
   - name: docker-desktop
     user:
       client-certificate-data: REDACTED
       client-key-data: REDACTED

then Set the docker context to Docker Desktop on your machine

kubectl config use-context docker-desktop

If that doesn't solve your issue maybe you have to check for specific Windows 11 Docker Desktop Kubernetes configuration/features

Check also:
Docker Desktop Windows FAQs

huangapple
  • 本文由 发表于 2023年2月18日 14:10:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75491546.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定