Config map use case examples
spec:
containers:
- name: mycontainer
envFrom:
- configMapRef:
name: myConfigMap
spec:
containers:
- name: myContainer
env:
- name: VAR1
valueFrom:
configMapKeyRef:
name: myConfigMap
key: VAR1
- name: VAR2
valueFrom:
configMapKeyRef:
name: myConfigMap
key: VAR2
Given a config map with multiple keys that are filenames you can
spec:
containers:
- name: myContainer
volumeMounts:
- name: my-config
mountPath: /etc/somedir # absolute target DIRECTORY
volumes:
- name: my-config
configMap:
name: my-config-map
spec:
containers:
- name: myContainer
volumeMounts:
- name: my-config
mountPath: /etc/somedir/ # absolute target DIRECTORY
volumes:
- name: my-config
configMap:
name: my-config-map
items:
- key: somefile # <--- CM key reference
path: somefile
Note though about example will hide all contents of /etc/somedir despite only injecting a single file.
An alternative is to use subPath as shown below.
spec:
containers:
- name: myContainer
volumeMounts:
- name: my-config
mountPath: /etc/somedir/somefile # absolute target FILE
subPath: somefile # CM <--- key reference
volumes:
- name: my-config
configMap:
name: my-config-map
Note though the subPath has the disadvantage of not updating with ConfigMap changes.