Trying to run Kubernetes on multiple nodes under WSL2 but how to deal with the unreachable ip addresses in WSL2?

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

Trying to run Kubernetes on multiple nodes under WSL2 but how to deal with the unreachable ip addresses in WSL2?

问题

尝试在WSL2内运行控制平面,而在其他机器上的WSL2内运行工作节点。因为它们在WSL2内,它们只能找到自己的IP地址并认为要使用这些IP地址,但这将不起作用,因为其他节点无法访问那些私有的WSL2 IP地址。

我尝试使用netsh interface portproxy...在控制主机上设置端口转发,并配置控制平面使用主机IP地址,但它仍然会发送配置给工作节点,要求其使用私有IP。在找到一些配置文件仍然包含WSL2虚拟IP并将其更改为指向主机IP之后,我会在系统日志中看到很多错误消息:“无法验证节点IP:节点IP:“192.168.0.100”未在主机的网络接口中找到”,因为在WSL2内,该IP地址是未知的。

是否有办法使这个工作?

请注意,我正在寻找在WSL2中解决此问题的方法,因为在WSL中网络工作方式不同。

英文:

Trying to run the control plane inside WSL2 and worker nodes under WSL2 on other machines. Because they're inside WSL2, they're going to only find their own IP addresses and think to use those, which will not work because other nodes cannot reach those private WSL2 ip addresses.

I tried setting up port forwarding with netsh interface portproxy... calls on the control host and configuring the control plane to use the host ip address, but it would still send configuration to the worker nodes to use the private ip. After finding a few config files that still had the WSL2 virtual IP and changing them to point to the host IP, I would then see a lot of errors in syslog: "failed to validate nodeIP: node IP: \"192.168.0.100\" not found in the host's network interfaces because inside WSL2, that ip address is unknown.

Is there a way to make this work?

Note, I'm looking for a solution in WSL2 where the networking works differently from WSL.

答案1

得分: 0

这实际上涉及两个问题。对于 Kubernetes 方面,答案可能是:

  1. 可能应该考虑像 microk8s 和 k3s 这样的简化版本,特别是在本地环境中。这样会简单得多。
  2. 否则,可以参考 Kubernetes the Hard Way,相关信息可能在那里。

至于 WSL2 方面的问题,此问题上有一些答案,可能可以配置 WSL2 拥有其独立的局域网可达 IP 地址。

更新:

microk8s 在控制节点和工作节点上都非常容易安装。

上面链接的另一个 stackoverflow 页面介绍了如何处理网络配置。安装 Hyper-V 并将 WSL 虚拟开关修改为外部。我猜那些无法使其工作的人可能遇到了一些细节问题:

  1. WSL 必须在上次启动后已运行过,但所有实例必须被终止(wsl --terminate {实例名称})。
  2. 必须以管理员身份运行 Hyper-V。
  3. 在终止 WSL 后必须启动 Hyper-V。

因此,如果不起作用,请确保 WSL 被终止,然后以管理员身份重新启动 Hyper-V。有时在终止 WSL 后运行 Hyper-V 前可能需要一定的延迟。我认为这可以自动化,参见:https://superuser.com/a/1790350/35726。

英文:

This turns out to be sort of two questions. For the kubernetes side of it, the answer is probably:

  1. Probably should consider simplified versions like microk8s and k3s for the local case. It's a lot simpler.
  2. Otherwise, go through Kubernetes the Hard Way, and the info is probably in there.

And for the WSL2 side of the question, there are a number of answers on this question that may be able to configure the WSL2 to have its own LAN reachable IP address.

Update:

microk8s was very straightforward to install both on control nodes and worker nodes.

The link above to the other stackoverflow is how to deal with the networking. Install Hyper-V and modify the WSL virtual switch as external. I'm guessing the people who couldn't get it to work might have run into some fiddly details to get it to work:

  1. WSL must have already been run after last boot, but all instances must be terminated (wsl --terminate {instancename})
  2. Must run hyper-v as adminstrator
  3. hyper-v must be started AFTER you terminated WSL.

So, if it doesn't work, make sure WSL is terminated, and then restart hyper-v as admin. And sometimes there needs to be a certain delay after terminating WSL before running hyper-v. I think this can be automated, see: https://superuser.com/a/1790350/35726

答案2

得分: 0

这是用于学习还是生产?

  • 生产:运行 Linux 机器。据我所知,没有人在生产环境中使用 WSL2 来运行 Kubernetes 集群。这样会增加额外的 Windows 运行时和许可成本,非常昂贵。
  • 开发:在 WSL2 中运行 Kind,它允许你在单台机器上运行多节点的 Kubernetes 集群。
英文:

Is this for learning or for production?

  • Production: Run Linux machines. No one, that I know of, uses WSL2 in production for a Kubernetes cluster. That would get pretty expensive with the extra Windows runtime and licensing overhead.
  • Development: Run Kind in WSL2 It lets you run multi-node Kubernetes clusters on a single machine.

huangapple
  • 本文由 发表于 2023年5月26日 11:03:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76337400.html
匿名

发表评论

匿名网友

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

确定