如何在 Windows WSL2 中使用 kubernetes 集群?

How can I use kubernetes cluster in Windows WSL2?

我正在尝试在我的 WSl Ubuntu 中使用 this article 创建集群。但是它 returns 有一些错误。

错误:

yusuf@DESKTOP-QK5VI8R:~/aws/kubs2$ sudo systemctl daemon-reload
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
yusuf@DESKTOP-QK5VI8R:~/aws/kubs2$ sudo systemctl restart kubelet
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
yusuf@DESKTOP-QK5VI8R:~/aws/kubs2$ sudo kubeadm init --pod-network-cidr=10.244.0.0/16
[init] Using Kubernetes version: v1.21.1
[preflight] Running pre-flight checks
        [WARNING Service-Docker]: docker service is not enabled, please run 'systemctl enable docker.service'
        [WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
error execution phase preflight: [preflight] Some fatal errors occurred:
        [ERROR Port-6443]: Port 6443 is in use
        [ERROR Service-Docker]: docker service is not active, please run 'systemctl start docker.service'
        [ERROR Swap]: running with swap on is not supported. Please disable swap
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
To see the stack trace of this error execute with --v=5 or higher

使用sudo systemctl restart kubelet时不明白原因。出现这样的错误:

docker service is not enabled, please run 'systemctl enable docker.service'

当我使用:

yusuf@DESKTOP-QK5VI8R:~/aws/kubs2$ systemctl enable docker.service
Failed to enable unit, unit docker.service does not exist.

但我有 docker 个图像仍在运行:

在 WSL 中创建 Cluster Kubernetes 时出了什么问题?在WSL中创建集群有什么好的教程吗?

您正在学习的教程是为带有 Linux OS 的云虚拟机设计的(这很重要,因为 WSL 的工作方式有点不同)。 例如。 SystemD 未出现在 WSL 中,您当前面临的行为是 in development phase.

您需要遵循指定的 WSL 教程(在本例中为 WSL2)。另请参阅 docker 在 Windows 机器上设置并与 WSL 集成共享其功能。请找Kubernetes on Windows desktop tutorial(这里用的是KinD或者minikube,足够开发和测试了)

还有一个 part for enabling SystemD 可能会解决您所在州的问题(我没有对此进行测试,因为我没有 windows 机器)。