K8S volumn 挂载文件
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
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
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
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 # 关键代码 结束
原文地址:https://blog.csdn.net/loveLifeLoveCoding/article/details/142390924
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!