<p>Is there a way to load any kernel module ("modprobe nfsd" in my case) automatically after starting/upgrading nodes or in GKE?  We are running an NFS server pod on our kubernetes cluster and it dies after every GKE upgrade</p>

<p>Tried both cos and ubuntu images, none of them seems to have nfsd loaded by default.</p>

<p>Also tried something like this, but it seems it does not do what it is supposed to do:</p>

<pre><code>kind: DaemonSet
apiVersion: extensions/v1beta1
metadata:
  name: nfsd-modprobe
  labels:
    app: nfsd-modprobe
spec:
  template:
    metadata:
      labels:
        app: nfsd-modprobe
    spec:
      hostPID: true
      containers:
        - name: nfsd-modprobe
          image: gcr.io/google-containers/startup-script:v1
          imagePullPolicy: Always
          securityContext:
            privileged: true
          env:
          - name: STARTUP_SCRIPT
            value: |
              #! /bin/bash

              modprobe nfs
              modprobe nfsd
              while true; do sleep 1; done
</code></pre>

Palko
<p>I faced the same issue, existing answer is correct, I want to expand it with working example of <code>nfs</code> pod within kubernetes cluster which has capabilities and libraries to load required modules.</p>
<p>It has two important parts:</p>
<ul>
<li>privileged mode</li>
<li>mounted <code>/lib/modules</code> directory within the container to use it</li>
</ul>
<p><code>nfs-server.yaml</code></p>
<pre><code>kind: Pod
apiVersion: v1
metadata:
  name: nfs-server-pod
spec:
  containers:
    - name: nfs-server-container
      image: erichough/nfs-server
      securityContext:
        privileged: true
      env:
      - name: NFS_EXPORT_0
        value: &quot;/test *(rw,no_subtree_check,insecure,fsid=0)&quot;
      volumeMounts:
      - mountPath: /lib/modules # mounting modules into container
        name: lib-modules
        readOnly: true # make sure it's readonly
      - mountPath: /test
        name: export-dir
  volumes:
  - hostPath: # using hostpath to get modules from the host
      path: /lib/modules
      type: Directory
    name: lib-modules
  - name: export-dir
    emptyDir: {}
</code></pre>
<p>Reference which helped as well - <a href="https://github.com/ehough/docker-nfs-server/blob/develop/doc/feature/auto-load-kernel-modules.md" rel="nofollow noreferrer">Automatically load required kernel modules</a>.</p>
