<p>I have a kubernetes cluster running on google container engine that defines a Pod running a NFS-Server, which I want to access in other Pods via various <code>PersistentVolume</code>s.</p>

<p>What is the best way to configure the NFS Service, if it is in the same cluster?</p>

<p>According to various documentation ive found its not possible to rely on kube-dns for this, because the node starting the kubernetes pod is not configured to use it as its DNS.</p>

<p>So this is out of question (and really does not work - ive tested it, with various different hostname/FQDN...)</p>

<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: xxx-persistent-storage
  labels:
    app: xxx
spec:
  capacity:
    storage: 10Gi
  nfs:
    path: "/exports/xxx"
    server: nfs-service.default.svc.cluster.local  # &lt;-- does not work
</code></pre>

<p>I can start the NFS Server and check its ClusterIP via <code>kubectl describe svc nfs-service</code> and then hardcode its Endpoint-IP for the PV (this works):</p>

<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: xxx-persistent-storage
  labels:
    app: xxx
spec:
  capacity:
    storage: 10Gi
  nfs:
    path: "/exports/xxx"
    server: 10.2.1.7  # &lt;-- does work
</code></pre>

<p>But this feels wrong - as soon as I need to recreate the NFS-Service ill get a new IP and i have to reconfigure all the PVs based on it.</p>

<ul>
<li><p>What is the best-practice here? Im surprised i did not find any example for it, because i supposed thats quite a normal thing to do - isnt it?</p></li>
<li><p>Is it possible to set a kind of static IP for a service, so that i can rely on having always the same IP for the NFS service?</p></li>
</ul>

<p>You are on the right track. To make sure that your Service is using a static IP just add <code>clusterIP: 1.2.3.3</code> under the <code>spec:</code> section of the Service.</p>

<p>From the canonical <a href="https://github.com/kubernetes/kubernetes/blob/master/examples/volumes/nfs/README.md" rel="nofollow noreferrer">example</a>:</p>

<blockquote>
  <p>In the future, we'll be able to tie these together using the service names, but for now, you have to hardcode the IP.</p>
</blockquote>
