root@k3s-server:~# modprobe overlay
modprobe: ERROR: ../libkmod/libkmod.c:586 kmod_search_moddep() could not open moddep file '/lib/modules/4.18.0-21-generic/modules.dep.bin'
modprobe: FATAL: Module overlay not found in directory /lib/modules/4.18.0-21-generic
root@k3s-server:~#
Actually into the LXC container the “/lib/modules/” directory is empty
How can I load kernel modules inside the container?
the concept of containers is a virtualization sharing the same kernel instance. for the majority of use cases, sharing the same kernel is sufficient and a virtual machine is not needed. for the cases where differences must exist between kernels, where these differences are not specifically provided for in cgroups/namespaces, a virtual machine is needed.
The LXC/LXD system containers do not load kernel modules for their own use.
What you do, is get the host it load the kernel module, and this module could be available in the container.
The overlay kernel module is available in system containers, if it is loaded (on the host).
You can setup your container to auto-load specific kernel modules when the container starts. This helps you so that you do not have to manually load kernel modules yourself.
I know how to do this with LXD,
lxc config set mycontainer linux.kernel_modules overlay
But if you check the documentation link that you just gave, it also sets linux.kernel_modules to load specific modules.