I'm trying to configure Nginx container on Openshift. My final goal is to overwrite Nginx config file. I know it's possible using config maps. Because any failure with modifying Nginx config directories is crashing the container, temporarily my goal is to just create an index.html file in /opt/app-root/src directory.
I'm facing two problems depends on the configuration
Config map:
apiVersion: v1
data:
index: |-
<html>
<body>
yo yo!
</body>
</html>
kind: ConfigMap
metadata:
creationTimestamp: '2020-01-16T12:53:25Z'
name: index-for-nginx
namespace: some-namespace
Deployment config (part, related to the topic):
spec:
containers:
- image: someimage
...
volumeMounts:
- mountPath: /opt/app-root/src/index.html
name: index
volumes:
- configMap:
defaultMode: 420
name: index-for-nginx
name: index
When:
volumeMounts:
- mountPath: /opt/app-root/src/index.html
It creates index.html directory and index file (with proper content) in /opt/app-root/src
When:
volumeMounts:
- mountPath: /opt/app-root/src/
It overwrites /opt/app-root/src directory
My question is - how should I configure it to create index.html file in /opt/app-root/src without overwriting the directory?
You can do the following, taken from this GitHub issue
containers:
- volumeMounts:
- name: config-volumes
mountPath: /opt/app-root/src/index.html
subPath: index
volumes:
- name: config-volumes
configMap:
name: index-for-nginx
Note: A container using a ConfigMap as a subPath volume will not receive ConfigMap updates.
You can use subPath
to mount the single file you want.
volumeMounts:
- mountPath: /opt/app-root/src/index.html
subPath: index
name: index
https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath