I am trying to map a configMap in JSON format to my docker image in Kubernetes I am using config npm package to fetch the configurations.
The idea is that I will have a file development.json in /config directory from there the config package will pick it up. This all works in localhost. The name of the config file is the same as the NODE_ENV variable, which I am also setting in the deployment.yaml
I am using default namespace
This is the beginning of the configMap (I can see it is created in google kubernetes)
I am running ls is the config directory to see if the development.json file has been mounted but it is not. I want the /config to be replaced and only contain the development.json file
I have also tried with the subPath parameter but same result
What am I doing wrong ? Should I see in the events that the configMap is mounted. There is no log of that except when I delete the configMap and try to do the mount, so I figure that the mounting is happening
apiVersion: v1
kind: ConfigMap
metadata:
name: config-development
namespace: default
data:
development.json: |
{
"production": false,
Here is the mount:
volumes:
- name: config-volume
configMap:
name: config-development
containers:
- name: salesforce-compare-api
image: XXXX
command: ["ls"]
args: ["config", "-la"]
imagePullPolicy: Always
env:
- name: NODE_ENV
value: "development"
volumeMounts:
- name: config-volume
mountPath: /config/development.json
CodePudding user response:
Usually, when the configmap cannot be mounted, the pod will not even start. So the fact that it started, shows that its mounted.
In any case, your volumeMounts looks problematic.
volumeMounts:
- name: config-volume
mountPath: /config/development.json
This lead to the full configmap being mounted into a folder named development.json, while you actually only want to mount the one file.
Use a subpath for this.
volumeMounts:
- name: config-volume
mountPath: /config/development.json
subPath: development.json
That said, if you config folder inside the container is otherwise empty, you can also drop the subpath and mount the configmap to the /config dir, since it will not override anything important.
volumeMounts:
- name: config-volume
mountPath: /config