Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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
like image 947
Benjamin Tan Wei Hao Avatar asked Aug 22 '19 10:08

Benjamin Tan Wei Hao


1 Answers

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
like image 135
Benjamin Tan Wei Hao Avatar answered Nov 15 '22 04:11

Benjamin Tan Wei Hao