我有Apache Nifi在Kubernetes工作。我已经用yaml文件部署了它。我有几个Python脚本,我想调用Apache Nifi。
我使用这个yaml文件来部署Apache Nifi:
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: "NIFI_SENSITIVE_PROPS_KEY"
value: "..."
- name: ALLOW_ANONYMOUS_LOGIN
value: "no"
- name: SINGLE_USER_CREDENTIALS_USERNAME
value: XXX
- name: SINGLE_USER_CREDENTIALS_PASSWORD
value: XXX
- name: NIFI_WEB_HTTPS_HOST
value: "0.0.0.0"
- name: NIFI_WEB_HTTPS_PORT
value: "8443"
- name: NIFI_WEB_PROXY_HOST
value: 0.0.0.0:8443
- name: HOSTNAME
value: "nifi1"
- name: NIFI_ANALYTICS_PREDICT_ENABLED
value: "true"
- name: NIFI_ELECTION_MAX_CANDIDATES
value: "1"
- name: NIFI_ELECTION_MAX_WAIT
value: "20 sec"
- name: NIFI_JVM_HEAP_INIT
value: "3g"
- name: NIFI_JVM_HEAP_MAX
value: "4g"
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
解决方案:
- 将这些脚本作为配置映射注入,这样Apache Nifi容器就可以访问这些脚本。
如何使用配置映射?
要注入脚本作为配置映射,您应该:
- 创建kubernetes ConfigMap并粘贴需要的python脚本
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')
- 将此ConfigMap作为卷附加到部署中的pod
在volumes:
部分添加
- configMap:
name: pyhton-scripts-cofigmap
name: pyhton-scripts-volume
它将是look
volumes:
- name: pv-01
persistentVolumeClaim:
claimName: pv-01-claim
- configMap:
name: pyhton-scripts-cofigmap
name: pyhton-scripts-volume
,在volumeMounts:
段添加
- mountPath: /path/to/scripts
name: pyhton-scripts-volume
readOnly: true
看起来就像
volumeMounts:
- name: pv-01
mountPath: /opt/nifi/nifi-current/data
subPath: data
- mountPath: /path/to/scripts
name: pyhton-scripts-volume
readOnly: true
你可以单独创建ConfigMap或者像这样添加到你的yaml中:
---
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
...
---