<p>I have written the <code>nifi.properties</code> into a <code>Kubernetes ConfigMap</code>. When I deploy NiFi (as a <code>StatefulSet</code>) I want to have this <code>nifi.properties</code> file to be used by the NiFi I just deployed. To do so I added a volume for the <code>ConfigMap</code> and mounted it in the Container. The associated <code>statefulset.yaml</code> looks like this:</p>

<pre><code>...
containers:
- name: 'myName'
  image: 'apache/nifi:latest'
  ports:
    - name: http
      containerPort: 8080
      protocol: TCP
    - name: http-2
      containerPort: 1337
      protocol: TCP
  volumeMounts:
    - name: 'nifi-config'
      mountPath: /opt/nifi/nifi-1.6.0/conf/nifi.properties
volumes:
- name: 'nifi-config'
  configMap:
    name: 'nifi-config'
...
</code></pre>

<p>This doesn't work, I think it is, because NiFi is already running and the <code>nifi.properties</code> file is locked by the service. The pod cannot be created, I get an error: <code>...Device or resource is busy</code>. I also tried that with the <code>bootstrap.conf</code> file, which works, but I don't think that changes in there are recognized by the NiFi service because it would have to be restarted.  </p>

<p>I already had the same issue with NiFi deployed on pure Docker, where I worked around by stopping the container, copying the files and starting the container; not very pretty, but working. </p>

<p>Using environment variables to change values in NiFi as stated <a href="https://github.com/apache/nifi/tree/master/nifi-docker/dockerhub" rel="nofollow noreferrer">here</a> is also not an option, because the possibility of changing parameters there are very limited.</p>

<p>This problem doesn't occurs for NiFi only. I think that there are many situations where someone want's to change the configuration for a system running within <code>Kubernetes</code>, so I hope there is any solution to handle this issue.</p>

Simon Linder
<p>There are two problems with the above setup:</p>

<ul>
<li>You have to specify the subpath to tell which item you mount from the configmap as a single file, see: <a href="https://github.com/kubernetes/kubernetes/issues/44815#issuecomment-297077509" rel="nofollow noreferrer">https://github.com/kubernetes/kubernetes/issues/44815#issuecomment-297077509</a></li>
<li>You cannot mount a configmap item as a readwrite volume by default on 1.9.6 and above, so the start script won't be able to replace properties in it, see: <a href="https://github.com/kubernetes/kubernetes/issues/62099#issuecomment-378809922" rel="nofollow noreferrer">https://github.com/kubernetes/kubernetes/issues/62099#issuecomment-378809922</a> </li>
</ul>

<p>To workaround the second issue you can simply mount the configmap item as a separate file (nifi.properties.tmp) and copy it to the destination by wrapping the container entry point with a custom command.</p>

<pre><code>...
containers:
- name: 'myName'
  image: 'apache/nifi:latest'
  ports:
    - name: http
      containerPort: 8080
      protocol: TCP
    - name: http-2
      containerPort: 1337
      protocol: TCP
  volumeMounts:
    - name: 'nifi-config'
      mountPath: /opt/nifi/nifi-1.6.0/conf/nifi.properties.tmp
      subPath: nifi.properties
  command:
  - bash
  - -c
  - |
    cat "${NIFI_HOME}/conf/nifi.properties.tmp" &gt; "${NIFI_HOME}/conf/nifi.properties"
    exec "${NIFI_BASE_DIR}/scripts/start.sh
    # or you can do the property edits yourself and skip the helper script:
    # exec bin/nifi.sh run
volumes:
- name: 'nifi-config'
  configMap:
    name: 'nifi-config'
...
</code></pre>
