<p>I have Apache Nifi working in Kubernetes. I have deployed it with yaml file.
I have several Python scripts I would like to call on Apache Nifi.</p>
<p>I used this yaml file to deploy Apache Nifi:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-nifi
  namespace: test-namespace
  labels:
    name : test-nifi
    app : test-nifi
spec:
  replicas: 2
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: test-nifi
  template:
    metadata:
      labels:
        app: test-nifi
    spec:
      restartPolicy: Always
      containers:
      - name: nifi1
        image: XXX
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8443
          name: nifi1
        env:
        - name: &quot;NIFI_SENSITIVE_PROPS_KEY&quot;
          value: &quot;...&quot;
        - name: ALLOW_ANONYMOUS_LOGIN
          value: &quot;no&quot;
        - name: SINGLE_USER_CREDENTIALS_USERNAME 
          value: XXX
        - name: SINGLE_USER_CREDENTIALS_PASSWORD 
          value: XXX
        - name: NIFI_WEB_HTTPS_HOST
          value: &quot;0.0.0.0&quot;
        - name: NIFI_WEB_HTTPS_PORT
          value: &quot;8443&quot;
        - name: NIFI_WEB_PROXY_HOST
          value: 0.0.0.0:8443
        - name: HOSTNAME
          value: &quot;nifi1&quot;
        - name: NIFI_ANALYTICS_PREDICT_ENABLED
          value: &quot;true&quot;
        - name: NIFI_ELECTION_MAX_CANDIDATES
          value: &quot;1&quot;
        - name: NIFI_ELECTION_MAX_WAIT
          value: &quot;20 sec&quot;
        - name: NIFI_JVM_HEAP_INIT
          value: &quot;3g&quot;
        - name: NIFI_JVM_HEAP_MAX
          value: &quot;4g&quot;
        volumeMounts:
          - name: pv-01
            mountPath: /opt/nifi/nifi-current/data
            subPath: data
        livenessProbe:
          exec:
            command:
              - pgrep
              - java
          initialDelaySeconds: 60
          periodSeconds: 30
          timeoutSeconds: 10
          failureThreshold: 3
          successThreshold: 1
        readinessProbe:
          tcpSocket:
              port: 8443
          initialDelaySeconds: 240
          periodSeconds: 30
          timeoutSeconds: 10
          failureThreshold: 3
          successThreshold: 1
        resources:
          requests:
            cpu: 400m
            memory: 4Gi
          limits:
            cpu: 500m
            memory: 4Gi
      imagePullSecrets:
      - name: repo-secret
      volumes:
        - name: pv-01
          persistentVolumeClaim:
            claimName: pv-01-claim
</code></pre>
<p>Solution I have :</p>
<ul>
<li>Inject these scripts as config maps, this way the Apache Nifi container will have access to scripts.</li>
</ul>
<p>How can I do it with config maps ?</p>

<p>To inject scripts as config map you should:</p>
<ol>
<li>Create kubernetes ConfigMap and paste python script you want to have</li>
</ol>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: pyhton-scripts-cofigmap
data:
  python_script_1.py: |
    import foo from bar
    
    foo()

  python_script_2.py: |
    print('Hello World')
</code></pre>
<ol start="2">
<li>Attach this ConfigMap as volume to pod in your Deployment</li>
</ol>
<p>in <code>volumes:</code> section of your deployment add</p>
<pre class="lang-yaml prettyprint-override"><code>- configMap:
      name: pyhton-scripts-cofigmap
  name: pyhton-scripts-volume
</code></pre>
<p>it will be look</p>
<pre class="lang-yaml prettyprint-override"><code>volumes:
  - name: pv-01
    persistentVolumeClaim:
       claimName: pv-01-claim
  - configMap:
       name: pyhton-scripts-cofigmap
    name: pyhton-scripts-volume
</code></pre>
<p>and in <code>volumeMounts:</code> section add</p>
<pre><code>- mountPath: /path/to/scripts
  name: pyhton-scripts-volume
  readOnly: true
</code></pre>
<p>it will be look like</p>
<pre class="lang-yaml prettyprint-override"><code>volumeMounts:
   - name: pv-01
     mountPath: /opt/nifi/nifi-current/data
     subPath: data
   - mountPath: /path/to/scripts
     name: pyhton-scripts-volume
     readOnly: true
</code></pre>
<p>You can create ConfigMap separately or add to your yaml like this:</p>
<pre class="lang-yaml prettyprint-override"><code>---
apiVersion: v1
kind: ConfigMap
metadata:
  name: pyhton-scripts-cofigmap
data:

...

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-nifi
  namespace: test-namespace
  labels:
    name : test-nifi
    app : test-nifi

...

---

</code></pre>
