我已经把nifi.properties写成了Kubernetes ConfigMap。当我部署NiFi (作为一个StatefulSet)时,我想让我刚刚部署的NiFi使用这个nifi.properties文件。为此,我为ConfigMap添加了一个卷,并将其挂载到容器中。关联的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/conf/nifi.properties
volumes:
- name: 'nifi-config'
configMap:
name: 'nifi-config'
...我认为这不起作用,因为NiFi已经在运行,服务锁定了nifi.properties文件。无法创建吊舱,我得到一个错误:...Device or resource is busy。我也尝试过使用bootstrap.conf文件,但我认为NiFi服务不会识别其中的更改,因为它必须重新启动。
对于部署在纯Docker上的NiFi,我已经遇到了同样的问题,在那里,我通过停止容器、复制文件和启动容器来完成工作;不是很漂亮,而是工作。
使用环境变量来更改NiFi中的值(如声明的这里 )也不是一个选项,因为在那里更改参数的可能性非常有限。
这个问题不仅发生在NiFi上。我认为,在很多情况下,有人想要更改运行在Kubernetes中的系统的配置,所以我希望有任何解决方案来解决这个问题。
发布于 2018-08-14 11:43:06
我在这个舵机档案的帮助下解决了这个问题,但做了一些改动。实际上,这与佩波夫给出的答案几乎是一样的,但正如我在评论中所说的,我得到了一个CrashLoopBackOff。这也与图像版本无关,因为我使用了基于NiFi 1.6.0的自己的映像,该映像也包含一些自定义处理器。
因此,我的解决方案是使用Kubernetes的postStart处理程序。问题是不能保证在入口点(看见)之前调用这个处理程序。但在这种情况下,吊舱会崩溃并重新启动,最终会恢复正常;现在我还没有遇到这个问题,所以现在看来还不错。
我将configMap的内容复制到一个专用文件夹中,并将它们复制到postStart处理程序中相关联的NiFi文件夹中。
这是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/conf
volumes:
- name: 'nifi-config'
configMap:
name: 'nifi-config'
...发布于 2018-08-11 19:56:43
上面的设置有两个问题:
为了解决第二个问题,您可以简单地将configmap项挂载为单独的文件(nifi.properties.tmp),并通过使用自定义命令包装容器入口点将其复制到目的地。
...
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 run
volumes:
- name: 'nifi-config'
configMap:
name: 'nifi-config'
...https://stackoverflow.com/questions/51786114
复制相似问题