ConfigMap挂载导致容器目录覆盖的问题解决
问题表现:
- 将configmap的配置项挂载到指定的容器目录中,导致容器的被挂载目录下的所有文件不可见,只可见通过configmap挂载的文件
解决办法:
1、volumes中设置path
2、volumeMounts中这是subPath
ConfigMap
apiVersion: v1
kind: ConfigMap
metadata:
name: smartcity-frontend-config
namespace: portal-frontend
data:
config-js: | xxxx自定义文件内容
log4j-js-json: | xxxx自定义文件内容
Deployment(正确挂载方式)
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: smartcity-frontend
namespace: portal-frontend
spec:
replicas: 2
selector:
matchLabels:
app: smartcity-frontend
template:
metadata:
labels:
app: smartcity-frontend
spec:
containers:
- name: node
image: hub.cloud.pub/frontend/node:2.12.4
imagePullPolicy: Always
ports:
- containerPort: 8080
volumeMounts:
- name: smartcity-frontend-config
mountPath: /opt/frontend/config.js
subPath: path/to/config.js
- name: smartcity-frontend-config
mountPath: /opt/frontend/log4js.json
subPath: path/to/log4js.json
volumes:
- name: smartcity-frontend-config
configMap:
name: smartcity-frontend-config
items:
- key: config-js
path: path/to/config.js
- key: log4j-js-json
path: path/to/log4js.json