0
votes

I've successfully managed to create an NFS Persistent Volume and a Persistent Volume claim which when I run my deployment does what it's supposed to and mounts my apps data folder on the NFS volume. All good.

In docker there is the ability to run

-v <host dir>:<container dir>

How do I tell Kubernetes in my deployment not to use /kubernetes but to use /kubernetes/ for example?

The current working code is: nfs-pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs-pv
spec:
  capacity:
    storage: 10Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Recycle
  storageClassName: nfs
  mountOptions:
    - hard
  nfs:
    path: /Dev1Partition1/kubernetes
    server: 192.168.40.202

nfs-pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nfs-pvc
spec:
  storageClassName: nfs
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi

The above works when I run the following deployment the data I expect appears in the Kubernetes folder I specified.

The Deployment looks like this deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    run: n8n-server
  name: n8n-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      run: n8n-deployment
  template:
    metadata:
      labels:
        run: n8n-deployment
    spec:
      volumes:
        - name: n8n-pv-storage
          persistentVolumeClaim:
            claimName: nfs-pvc
      containers:
      - image: 192.168.40.43:8081/dockercontainers/library/n8n:latest
        name: n8n-server
        volumeMounts:
          - mountPath: "/root/.n8n"
            name: n8n-pv-storage
      imagePullSecrets:
        - name: progercred

I tried adding under volumes:

hostPath: path: n8n (and /n8n) 
type: Directory

This throws up

spec.template.spec.volumes[0].persistentVolumeClaim: Forbidden: may not specify more than 1 volume type

spec.template.spec.containers[0].volumeMounts[0].name: Not found: "n8n-pv-storage"

I'm guessing because hostPath is for emptyDir?

Help?

Am i thinking about this right?

1
Where did you exactly add type: Directory ? In the PersistentVolume definition? If I understand well, you created a PersistentVolume mapped to a directory. And in your Deployment you want tell your pod to use another folder than the one mapped by the PersistentVolume ?Flo
I'd like the deployment to create an application directory under the directory created by PersistentVolume.. from what i've been reading it seems that I've misunderstood PersistentVolume/NFS and I need to create a persistentvolume per App? would that be right? Seems a bit counterintuitive to not be able to create a volume of storage and then have access for the application to create an application specific folder on that blob of storage.David Field

1 Answers

0
votes

The thing just about NONE of the "helpful" PV/PVC/NFS sites mention is subPath

So in the containers section of the deployment.yaml change so it has

volumeMounts:
  - mountPath: "/root/.n8n"
    name: n8n-pv-storage
    subPath: n8n

the subPath directive will create a subdirectory on the PV/PVC mountpoint of n8n which is persistent across nodes.

References:

How to mount the sub path of PVC to the specific path in container https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath