<p>I created a nfs server in a pod to use it as a volume. When creating another pod with a volume, the volume mount does work with the ip of the nfs pod. Since this ip is not guaranteed to stay the same, I added a service for my nfs pod and added a fixed cluster ip. When starting the container with the volume mount, it always fails with the following error:</p>

<blockquote>
  <p>Unable to mount volumes for pod "nginx_default(35ecd8ec-a077-11e8-b7bc-0cc47a9aec96)": timeout expired waiting for volumes to attach or mount for pod "default"/"nginx". list of unmounted volumes=[nfs-demo]. list of unattached volumes=[nfs-demo nginx-test-account-token-2dpgg] </p>
</blockquote>

<pre><code>    apiVersion: v1
    kind: Pod
    metadata:
      name: nfs-server
      labels:
        name: nfs-server
    spec:
      containers:
      - name: nfs-server
        image: my-nfs-server:v1
        args: ["/exports"]
        securityContext:
          privileged: true
    ---
    kind: Service
    apiVersion: v1
    metadata:
      name: nfs-service
    spec:
      selector:
        name: nfs-server
      clusterIP: "10.96.0.3"
      ports:
        - name: nfs
          port: 2049
          protocol: UDP
        - name: mountd
          port: 20048
          protocol: UDP   
        - name: rpcbind
          port: 111
          protocol: UDP
        - name: nfs-tcp
          port: 2049
          protocol: TCP
        - name: mountd-tcp
          port: 20048
          protocol: TCP
        - name: rpcbind-tcp
          port: 111
          protocol: TCP
</code></pre>

<p>My pod trying to mount the server:</p>

<pre><code>    apiVersion: v1
    kind: Pod
    metadata:
      name: nginx
      labels:
        name: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        volumeMounts:
        - mountPath: "/exports"
          name: nfs-demo
        securityContext:
          privileged: true
      securityContext:
        supplementalGroups: [100003]
      serviceAccountName: nginx-test-account
      volumes:
      - name: nfs-demo
        nfs:
          server: 10.96.0.3
          path: "/exports"
          readOnly: false
</code></pre>

<p>I used this as a base for my nfs server image: </p>

<p><a href="https://github.com/cpuguy83/docker-nfs-server" rel="noreferrer">https://github.com/cpuguy83/docker-nfs-server</a></p>

<p><a href="https://medium.com/@aronasorman/creating-an-nfs-server-within-kubernetes-e6d4d542bbb9" rel="noreferrer">https://medium.com/@aronasorman/creating-an-nfs-server-within-kubernetes-e6d4d542bbb9</a></p>

<p>Does anyone have an idea why the mount ist working with the pod ip but not with the service ip?</p>

albrr
<p>I found a new way to solve this problem ,you can set nfs-server port to be fixed ,then mount nfs-server by service . you can refer to <a href="https://wiki.debian.org/SecuringNFS" rel="nofollow noreferrer">https://wiki.debian.org/SecuringNFS</a></p>

<p><a href="https://i.stack.imgur.com/kh1SX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kh1SX.png" alt="enter image description here"></a>
<a href="https://i.stack.imgur.com/ASYrx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ASYrx.png" alt="enter image description here"></a></p>
