<p>I want to setup a in-cluster NFS-Server in Kubernetes to provide shares for my pods (nginx webroot etc.).</p>

<p>In theory there should be a persistent volume, a volume claim and the NFS-Server, which, as I understand is a deployment.</p>

<p>To use the PV and PVC I need to assign the NFS-Server's IP-Adress, which I don't know, because it automatically generated when I expose the NFS-Server with a service.</p>

<p>The same problem appears if I want to deploy the nfs-server deployment itself, because I am using the PVC as volumes. But I can't deploy the PV and PVCs without giving them the NFS-Server IP.</p>

<p>I think I am lost, maybe you can help me.</p>

<ol>
<li>PV</li>
</ol>

<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-nfs-pv1
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteMany
  nfs:
    path: "/exports/www"
    server: SERVER_NAME:PORT
</code></pre>

<ol start="2">
<li>PVC</li>
</ol>

<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pv-nfs-pv1
  labels:
    type: local
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 500Mi
</code></pre>

<ol start="3">
<li>NFS-Deployment</li>
</ol>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nfs-server
spec:
  replicas: 1
  selector:
    matchLabels:
      role: nfs-server
  template:
    metadata:
      labels:
        role: nfs-server
    spec:
      containers:
        - name: nfs-server
          image: gcr.io/google_containers/volume-nfs:0.8
          ports:
            - name: nfs
              containerPort: 2049
            - name: mountd
              containerPort: 20048
            - name: rpcbind
              containerPort: 111
          securityContext:
            privileged: true
          volumeMounts:
            - mountPath: /exports/www
              name: pv-nfs-pv1
      volumes:
        - name: pv-nfs-pv1
          gcePersistentDisk:
            pdName: pv-nfs-pv1
#            fsType: ext4
</code></pre>

<p>1) You create NFS-server deployment.</p>

<p>2) You expose NFS-server deployment by creating service, say "nfs-server", exposing TCP port 2049 (assuming you use NFSv4). </p>

<p>3) You create PV with the following information:</p>

<pre><code>  nfs:
    path: /exports/www
    server: nfs-server
</code></pre>

<p>4) You create PVC and mount it wherever you need it.</p>
