Search code examples
kubernetesnfs

How to have multiple pods access an existing NFS folder in Kubernetes?


I have a folder of TFRecords on a network that I want to expose to multiple pods. The folder has been exported via NFS.

I have tried creating a Persistent Volume, followed by a Persistent Volume Claim. However, that just creates a folder inside the NFS mount, which I don't want. Instead, I want to Pod to access the folder with the TFRecords.

I have listed the manifests for the PV and PVC.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs-tfrecord-pv
spec:
  capacity:
    storage: 30Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  nfs:
    path: /media/veracrypt1/
    server: 1.2.3.4
    readOnly: false
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nfs-tfrecord-pvc
  namespace: default
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: nfs-tfrecord
  resources:
    requests:
      storage: 1Gi

Solution

  • I figured it out. The issue was I was looking at the problem the wrong way. I didn't need any provisioning. Instead, what was need was to simply mount the NFS volume within the container:

    kind: Pod
    apiVersion: v1
    metadata:
      name: pod-using-nfs
    spec:
      containers:
        - name: app
          image: alpine
          volumeMounts:
          - name: data
            mountPath: /mnt/data
          command: ["/bin/sh"]
          args: ["-c", "sleep 500000"]
      volumes:
      - name: data
        nfs:
          server: 1.2.3.4
          path: /media/foo/DATA