新建configmap:
apiVersion: v1
kind: ConfigMap
metadata:
name: front-conf
namespace: tsp
data:
baseUrl.js: |
window.baseUrl = 'http://xxx.com/'
window.websocketUrl = 'ws://xxx:8090/ws'
创建configmap的几种形式:
# 使用目录创建(--fromfile 指定在目录下的所有文件都会被用在ConfigMap里面创建一个键值对,键的名字就是文件名,值就是文件的内容)
kubectl create configmap [configmap名称] --from-file={目录}
# 使用文件创建(--fromfile 这个参数可以使用多次,你可以使用两次分别指定上个实例中的那两个配置文件,效果就跟指定整个目录是一样的)
kubectl create configmap [configmap名称] --from-file=[文件]
# 从字面值创建
kubectl create configmap [configmap名称] --from-literal=[键值对]
在deployment挂载配置文件:
...
deployment.spec
volumes:
- name: front-config
configMap:
name: front-conf
containers:
- name: app
image: xxx.docker.com/project/myapp:myversion
...
volumeMounts:
- name: front-config
mountPath: /mx-nodejs/dist/
启动deployment后,便可在应用容器内发现/mx-nodejs/dist/baseUrl.js文件(可见简单理解为在mountPath目录中挂载configMap.data中的多个文件),