Mounting ConfigMap as single file
Many guys who work with Kubernetes don’t know that you can mount ConfigMap into existing folder inside a Pod as a single file.
In order to do so, you have to specify subPath.
For example, to replace nginx’s config with one from ConfigMap:
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-config
...
data:
nginx.conf: |
...some raw config string...
---
apiVersion: apps/v1
kind: Deployment
spec:
...
template:
...
spec:
containers:
...
volumeMounts:
- name: nginx-config-volume
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
volumes:
- name: nginx-config-volume
configMap:
name: nginx-config
Comments