Before we will apply desired configuration, this is default nginx configuration /usr/share/nginx/html:
root@ng:/usr/share/nginx/html# ls -la
total 16
drwxr-xr-x 2 root root 4096 Aug 14 00:36 .
drwxr-xr-x 3 root root 4096 Aug 14 00:36 ..
-rw-r--r-- 1 root root 494 Aug 11 14:50 50x.html
-rw-r--r-- 1 root root 612 Aug 11 14:50 index.html
Example custom configuration:
wget https://kubernetes.io/examples/configmap/game.properties
wget https://kubernetes.io/examples/configmap/ui.properties
kubectl create configmap game --from-file=game.properties --from-file=ui.properties
apiVersion: v1
kind: Pod
metadata:
name: my
spec:
containers:
- name: nginx
image: nginx
volumeMounts:
- mountPath: /usr/share/nginx/html/index.html
name: data
subPath: game # make a reference to existing CM Key
- mountPath: /usr/share/nginx/html/ui.properties.txt
name: data
subPath: ui.properties.txt # make a reference to existing CM Key
volumes:
- name: data
configMap:
name: game
items:
- key: game.properties
path: game
- key: ui.properties
path: ui.properties.txt
After pod deploy kubectl apply -f <your_pod_yaml>
root@my:/usr/share/nginx/html# ls -la
total 24
drwxr-xr-x 1 root root 4096 Aug 17 12:26 .
drwxr-xr-x 1 root root 4096 Aug 14 00:36 ..
-rw-r--r-- 1 root root 494 Aug 11 14:50 50x.html
-rw-r--r-- 1 root root 157 Aug 17 12:26 index.html
-rw-r--r-- 1 root root 83 Aug 17 12:26 ui.properties.txt
verify index.html
root@my:/usr/share/nginx/html# curl localhost
enemies=aliens
lives=3
enemies.cheat=true
enemies.cheat.level=noGoodRotten
secret.code.passphrase=UUDDLRLRBABAS
secret.code.allowed=true
secret.code.lives=30
verify ui.properties.txt
root@my:/usr/share/nginx/html# cat ui.properties.txt
color.good=purple
color.bad=yellow
allow.textmode=true
how.nice.to.look=fairlyNice
While sourcing your different files from ConfigMap make sure you are referencing proper keys