K8s(Minikube/Kind) with rootless Podman on WSL2

Running Kubernetes with rootless podman is documented on both kind and minikube but to get it up and running on WSL2 requires some additional tweaks as by default WSL2 uses init daemon, instead of systemd and you have to enable cgroupv2 explicitly.

To run a local Kubernetes cluster with minikube/kind and rootless podman on WSL2 with Ubuntu:

  1. Enable systemd in WSL2. Link

    • Create a file /etc/wsl.conf using sudo for admin permissions and add these lines to the file.

    • Close the terminal tab and open Powershell and execute the below command to Reboot WSL.

      wsl --shutdown
  2. Enable cgroupv2 support. Link

    • Create %UserProfile%\.wslconfig file with the following content:
      kernelCommandLine = cgroup_no_v1=all
    • Reboot the WSL
    • Start WSL and edit the /etc/fstab file with the following content:
      cgroup2 /sys/fs/cgroup cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate 0 0
    • Reboot the WSL
  3. Enable CPU, CPUSET, and I/O delegation. Link

    • Allow delegation to the above mentioned controllers
      $ sudo mkdir -p /etc/systemd/system/user@.service.d
      $ cat <<EOF | sudo tee /etc/systemd/system/user@.service.d/delegate.conf
      Delegate=cpu cpuset io memory pids
      $ sudo systemctl daemon-reload
    • Reboot the WSL
  4. Install kubectl and minikube or kind following the instructions in the docs.

  5. Start the cluster as per documentation. (minikube, kind)