bash
volumeMounts:
- name: cfg-vol
mountPath: /etc/grafana/provisioning/datasources
- name: cfg-ini
mountPath: /usr/share/grafana/conf/sample.ini
subPath: sample.ini
- name: cfg-temp
mountPath: /usr/share/grafana/conf/test.json
subPath: test.json
bash
volumes:
- name: cfg-vol
configMap:
name: cm-grafana-yaml
- name: cfg-ini
configMap:
name: cm-grafana-ini
- name: cfg-temp
configMap:
name: cm-grafana-temp
需求
将一个configmap 内的两个文件挂载在一个pod的不同目录下
- /app/conf/grafanaoracle.properties
- /app/start-timeshift.sh
创建一个configmap
bash
kind: ConfigMap
apiVersion: v1
metadata:
labels:
app.kubernetes.io/managed-by: Helm
name: test-config
data:
grafanaoracle.properties: |
name=kevin
nage=19
start-timeshift.sh: |
#!/bin/sh
cd /app/influxdb-timeshift-proxy
INFLUXDB=nms-influxdb:8086 /usr/bin/npm run start
创建一个deploy
bash
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
zcm-app: test-configmap
name: test-configmap
spec:
replicas: 1
selector:
matchLabels:
zcm-app: test-configmap
template:
metadata:
labels:
zcm-app: test-configmap
spec:
containers:
- env:
- name: CLOUD_APP_NAME
value: paas_test-configmap
image: nginx
imagePullPolicy: IfNotPresent
name: test-configmap
ports:
- containerPort: 9999
name: http-oracle
protocol: TCP
volumeMounts: # 关键代码 开始
- mountPath: /app/start-timeshift.sh
name: properties
readOnly: true
subPath: start-timeshift.sh
- mountPath: /app/conf/grafanaoracle.properties
name: properties
readOnly: true
subPath: grafanaoracle.properties
dnsPolicy: ClusterFirst
restartPolicy: Always
volumes:
- configMap:
defaultMode: 420
items:
- key: grafanaoracle.properties # key 和 path 同名即可
path: grafanaoracle.properties
- key: start-timeshift.sh
path: start-timeshift.sh
name: test-configmap
name: properties # 关键代码 结束