nifikop icon indicating copy to clipboard operation
nifikop copied to clipboard

mount/use existing pvc on nifi nodes

Open teplydat opened this issue 4 years ago • 10 comments

Type of question

Are you asking about community best practices, how to implement a specific feature, or about general context and help around nifikop ? Best practice how to mount an existing pvc on nifi

Question

What did you do?

At first I created a pvc:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: fstp-pvc
  namespace: usecase
  labels:
    pvc: fstp
spec:
  storageClassName: "ceph-fs-storage"
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi

Then I tried to mount it via labels though the nificlusters.nifi.orange.com:

...
    storageConfigs:
      - mountPath: "/opt/fstp"
        name: fstp-pvc
        pvcSpec:
          accessModes:
            - ReadWriteMany
          selector:
            matchLabels:
              pvc: fstp
...

What did you expect to see? Nifi mounts the existing pvc.

What did you see instead? Under which circumstances?

No nifi node is scheduled by the operator.

logs from the operator:

PersistentVolumeClaim \"nifi-0-storagebb7tt\" is invalid: spec.resources[storage]: Required value","Request.Namespace":"usecase","Request.Name":"nifi"}

{"level":"error","ts":1603277145.6576192,"logger":"controller-runtime.controller","msg":"Reconciler error","controller":"nificluster-controller","request":"usecase/nifi","error":"failed to reconcile resource: creating resource failed: PersistentVolumeClaim \"nifi-0-storagebb7tt\" is invalid: spec.resources[storage]: Required value","errorVerbose":"creating resource failed: PersistentVolumeClaim \"nifi-0-storagebb7tt\" is invalid: spec.resources[storage]: Required value\nfailed to reconcile 

Environment

  • nifikop version:

image: orangeopensource/nifikop:v0.2.0-release

  • Kubernetes version information:

v1.16.7

  • Kubernetes cluster kind:

nificlusters.nifi.orange.com

  • NiFi version:

1.11.4

teplydat avatar Oct 21 '20 12:10 teplydat

As mentionned in the log error you didn't specify the spec.resources[storage]: Required value.

So If you want this to work, you "just" need to specify how much storage you want to allocate as follows :

    storageConfigs:
      - mountPath: "/opt/fstp"
        name: fstp-pvc
        pvcSpec:
          accessModes:
            - ReadWriteMany
          selector:
            matchLabels:
              pvc: fstp
          resources:
            requests:
              storage: 10Gi

erdrix avatar Oct 26 '20 11:10 erdrix

Hey @erdrix would this then mount an already existing PVC or try to create a new one?

Arttii avatar Oct 28 '20 12:10 Arttii

I tried with:

    storageConfigs:
      - mountPath: "/opt/fstp"
        name: fstp-pvc
        pvcSpec:
          accessModes:
            - ReadWriteMany
          selector:
            matchLabels:
              pvc: fstp
          resources:
            requests:
              storage: 1Gi

Error:

kubectl describe pod nifi-0-nodev7zws -n usecase 
  Warning  FailedScheduling  22s (x3 over 2m56s)  default-scheduler  pod has unbound immediate PersistentVolumeClaims (repeated 3 times)

It obviously tries to create a new pvc (but I need to reuse an existing one):

kubectl describe pod nifi-0-nodev7zws -n usecase 

  fstp-pvc:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  nifi-0-storagestq67
    ReadOnly:   false

I also found something in the official k8s documentation: https://kubernetes.io/docs/concepts/storage/persistent-volumes/#reserving-a-persistentvolume storageClassName: "" # Empty string must be explicitly set otherwise default StorageClass will be set

But even with using an emtpy string for the storageClass its the same behavior like above.

So how can I mount existing pvc's to nifi?

teplydat avatar Oct 28 '20 15:10 teplydat

This feature is not supported at this time, the StorageConfig object allows you to define PVC + volume mount via a single object. If you just want to add a volume mount, the easiest way is to use https://kubernetes.io/docs/tasks/inject-data-application/podpreset/.

This is the same advice we provided for configmap : https://github.com/Orange-OpenSource/nifikop/issues/32.

Is this solution right for you?

erdrix avatar Oct 28 '20 16:10 erdrix

Think we need to add support for this in the operator itself. Do you have ideas what would be the best place to start with this? I want to invest some time in this.

Arttii avatar Oct 29 '20 09:10 Arttii

Any updates here? We have similar case, in which i need to share a volume between all our nifi nodes. The cluster CRD makes it look like we can do it by referencing an existing pvc(1733-1768), but it doesn't work. Using pod preset is not an option because it is being deprecated. We are using nifi 1.12.1 and nifikop 0.5.2-release.

        - mountPath: "/var/lib/original"                                                                                                                                                           
          name: original-files                                                                                                                                                                        
          pvcSpec:                                                                                                                                                                                    
            accessModes:                                                                                                                                                                              
              - ReadWriteOnce                                                                                                                                                                         
            dataSource:                                                                                                                                                                               
              apiGroup: ""                                                                                                                                                                            
              kind: PersistentVolumeClaim                                                                                                                                                             
              name: test-shared-volume 

As a result, the operator just creates separate claim for every node, in stead of using the existing one

iordaniordanov avatar Mar 04 '21 11:03 iordaniordanov

Are there any alternative to use podpresets? That feature is not available on kubernetes 1.20. As an alternative, what is the best way with NifiKop to deal with backups and restore? We thought about using the same PV but it doesn't appear possible. Thanks for your support

riccardo-salamanna avatar Oct 14 '21 11:10 riccardo-salamanna

Looks like there isn't and alternative, what we did is we implemented our own podpreset and used it to modify the created nodes. It was actually fairly easy

iordaniordanov avatar Oct 14 '21 11:10 iordaniordanov

@iordaniordanov did you use https://github.com/redhat-cop/podpreset-webhook ?

riccardo-salamanna avatar Oct 14 '21 11:10 riccardo-salamanna

No we went with our own implementation

iordaniordanov avatar Oct 14 '21 11:10 iordaniordanov