<p>In a docker container I want to run k8s. </p>

<p>When I run <code>kubeadm join ...</code> or <code>kubeadm  init</code> commands I see sometimes errors like </p>

<blockquote>
  <p>\"modprobe: ERROR: ../libkmod/libkmod.c:586 kmod_search_moddep() could
  not open moddep file
  '/lib/modules/3.10.0-1062.1.2.el7.x86_64/modules.dep.bin'. 
  nmodprobe:<br>
  FATAL: Module configs not found in directory
  /lib/modules/3.10.0-1062.1.2.el7.x86_64", 
  err: exit status 1</p>
</blockquote>

<p>because (I think) my container does not have the expected kernel header files.</p>

<p>I realise that the container reports its kernel <strong>based on the host that is running the container</strong>; and looking at <a href="https://gitlab.cncf.ci/kubernetes/kubernetes/blob/06cdb02fcacc06bbc36d290ce99720856191ff27/test/e2e_node/system/kernel_validator.go" rel="nofollow noreferrer">k8s code</a>  I see </p>

<pre><code>// getKernelConfigReader search kernel config file in a predefined list. Once the kernel config
// file is found it will read the configurations into a byte buffer and return. If the kernel
// config file is not found, it will try to load kernel config module and retry again.
func (k *KernelValidator) getKernelConfigReader() (io.Reader, error) {
    possibePaths := []string{
        "/proc/config.gz",
        "/boot/config-" + k.kernelRelease,
        "/usr/src/linux-" + k.kernelRelease + "/.config",
        "/usr/src/linux/.config",
    }
</code></pre>

<p>so I am bit confused what is simplest way to run k8s inside a container such that it consistently past this getting the kernel info. </p>

<p>I note that running <code>docker run -it     solita/centos-systemd:7        /bin/bash</code> on a macOS host I see :</p>

<pre><code># uname -r
4.9.184-linuxkit
# ls -l /proc/config.gz 
-r--r--r-- 1 root root 23834 Nov 20 16:40 /proc/config.gz
</code></pre>

<p>but running exact same on a Ubuntu VM I see :</p>

<pre><code>#  uname -r
4.4.0-142-generic
# ls -l /proc/config.gz 
ls: cannot access /proc/config.gz
</code></pre>

<p>[Weirdly I don't see this <code>FATAL: Module configs not found in directory</code> error every time, but I guess that is a separate question!]</p>

<p><strong>UPDATE 22/November/2019. I see now that k8s DOES run okay in a container. Real problem was weird/misleading logs.  I have added an answer to clarify.</strong> </p>

k1eran
<p>I do not believe that is possible given the nature of containers.</p>

<p>You should instead test your app in a docker container then deploy that image to k8s either in the cloud or locally using minikube.</p>

<p>Another solution is to run it under kind which uses docker driver instead of VirtualBox</p>

<p><a href="https://kind.sigs.k8s.io/docs/user/quick-start/" rel="nofollow noreferrer">https://kind.sigs.k8s.io/docs/user/quick-start/</a></p>
