Longhorn CSI on K3s

Requirements

  • Kubernetes v1.11 or higher.
  • Longhorn v0.4.1 or higher.
  • open-iscsi or iscsiadm installed on the node.

As long as these three prerequisites are met, there should be no further configuration required to use Longhorn on K3s.

Troubleshooting

Common issues

This error is due to Longhorn cannot detect where is the root dir setup for Kubelet, so the CSI plugin installation failed.

User can override the root-dir detection by manually setting argument kubelet-root-dir here: https://github.com/rancher/longhorn/blob/master/deploy/longhorn.yaml#L329

How to find root-dir?

Run ps aux | grep k3s and get argument --data-dir or -d on k3s node.

e.g.

$ ps uax | grep k3s
root      4160  0.0  0.0  51420  3948 pts/0    S+   00:55   0:00 sudo /usr/local/bin/k3s server --data-dir /opt/test/kubelet
root      4161 49.0  4.0 259204 164292 pts/0   Sl+  00:55   0:04 /usr/local/bin/k3s server --data-dir /opt/test/kubelet

You will find data-dir in the cmdline of proc k3s. By default it is not set and /var/lib/rancher/k3s will be used. Then joining data-dir with /agent/kubelet you will get the root-dir. So the default root-dir for K3S is /var/lib/rancher/k3s/agent/kubelet.

If K3S is using a configuration file, you would need to check the configuration file to locate the data-dir parameter.