Changing configuration in running Kubernetes Pod
There are two problems with the above setup:
- You have to specify the subpath to tell which item you mount from the configmap as a single file, see: https://github.com/kubernetes/kubernetes/issues/44815#issuecomment-297077509
- 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: https://github.com/kubernetes/kubernetes/issues/62099#issuecomment-378809922
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.
...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" > "${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 runvolumes:- name: 'nifi-config' configMap: name: 'nifi-config'...
I solved this with the help of this helm file, but changed it a bit. Actually it is nearly the same as the answer that pepov has given, but as stated in my comment, I got a CrashLoopBackOff
. This also had nothing to do with the image version, because I used my own image that is based on NiFi 1.6.0 also containing some custom processors.
So my solution is to use the postStart
handler of Kubernetes. Problem is that it is not guaranteed that this handler is called before the ENTRYPOINT (see). But in this case the pod would crash and restart, eventually getting it right; right now I haven't had this problem, so it seems to be good for now.
I copy the content of the configMap
into a dedicated folder and copy them in the associated NiFi folder in the postStart
handler.
So here is the statefulset.yaml
:
...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/kubeconfig lifecycle: postStart: exec: command: - bash - -c - | cp -a /opt/nifi/nifi-1.6.0/kubeconfig/. /opt/nifi/nifi-1.6.0/confvolumes:- name: 'nifi-config' configMap: name: 'nifi-config'...