solved run k8s in wsl2

When I use wsl2 join my k8s cluster, I have some problem. It can be start, but pod is not runing.

1
2
3
4
Normal   Scheduled               95m                default-scheduler  Successfully assigned longhorn-system/longhorn-csi-plugin-bvnmk to company-wsl-1
Warning FailedCreatePodSandBox 4m kubelet Failed to create pod sandbox: rpc error: code = Unknown desc = failed to setup network for sandbox "a13a250444d61af44800db054a047059c66202ab9d8a47732748c7c4d380131b": plugin type="multus" failed (add): Multus: [longhorn-system/longhorn-csi-plugin-bvnmk/2203cd9f-608d-42b1-82b9-dad186a9b5cb]: error waiting for pod: Get "https://[10.43.0.1]:443/api/v1/namespaces/longhorn-system/pods/longhorn-csi-plugin-bvnmk?timeout=1m0s": dial tcp 10.43.0.1:443: i/o timeout
Normal SandboxChanged 2m (x3 over 8m1s) kubelet Pod sandbox changed, it will be killed and re-created.
Warning FailedCreatePodSandBox 2m kubelet Failed to create pod sandbox: rpc error: code = Unknown desc = failed to reserve sandbox name "longhorn-csi-plugin-bvnmk_longhorn-system_2203cd9f-608d-42b1-82b9-dad186a9b5cb_2": name "longhorn-csi-plugin-bvnmk_longhorn-system_2203cd9f-608d-42b1-82b9-dad186a9b5cb_2" is reserved for "a13a250444d61af44800db054a047059c66202ab9d8a47732748c7c4d380131b"

Looks like network problem, but when I open journal in wsl2, I see iptables-restore can not runing.

1
2
3
4
5
6
7
Mar 01 11:26:59 DESKTOP-TH5NA7O k3s[223]: E0301 11:26:59.262472     223 proxier.go:1521] "Failed to execute iptables-restore" err=<
Mar 01 11:26:59 DESKTOP-TH5NA7O k3s[223]: exit status 2: iptables-restore v1.8.7 (nf_tables): Couldn't load match `recent':No such file or directory
Mar 01 11:26:59 DESKTOP-TH5NA7O k3s[223]:
Mar 01 11:26:59 DESKTOP-TH5NA7O k3s[223]: Error occurred at line: 145
Mar 01 11:26:59 DESKTOP-TH5NA7O k3s[223]: Try `iptables-restore -h' or 'iptables-restore --help' for more information.
Mar 01 11:26:59 DESKTOP-TH5NA7O k3s[223]: >
Mar 01 11:26:59 DESKTOP-TH5NA7O k3s[223]: I0301 11:26:59.262516 223 proxier.go:801] "Sync failed" retryingTime="30s"

Now let’s fix!

build before install depends.

1
apt install -y git build-essential flex bison libssl-dev libelf-dev bc dwarves python3
  1. clone wsl2 kernel code.
1
git clone --depth 1 https://github.com/microsoft/WSL2-Linux-Kernel.git && cd WSL2-Linux-Kernel
  1. enable xt_recent.
1
sed -i 's/# CONFIG_NETFILTER_XT_MATCH_RECENT is not set/CONFIG_NETFILTER_XT_MATCH_RECENT=y/' Microsoft/config-wsl
  1. build kernel.
1
make -j2 KCONFIG_CONFIG=Microsoft/config-wsl
  1. cp kernel to some path.
1
2
3
4
5
6
7
8
cp arch/x86/boot/bzImage /mnt/c/Users/<your-user-name>/wsl-kernel
``

5. Create a .wslconfig file in C:\Users\<your-user-name>\

```text
[wsl2]
kernel=C:\\Users\\<your-user-name>\\wsl-kernel
  1. reboot wsl
1
2
3
wsl --shutdown

wsl

solved run k8s in wsl2
https://blog.justforlxz.com/2024/03/01/solved-run-k8s-in-wsl2/
作者
小竹
发布于
2024年3月1日
许可协议