I'm trying to use a directory config map as a mounted volume inside of my docker container running a spring boot application. I am passing some of the mounted paths to the things like the spring application.yaml, but it doesn't appear the mount is working as expected as it can't find the config. For example
Create the configmap like so
kubectl create configmap example-config-dir \
--from-file=/example/config/
Kubernetes yaml
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: example
labels:
app: example
spec:
replicas: 1
selector:
matchLabels:
app: example
template:
metadata:
labels:
app: example
spec:
containers:
- name: example
image: example:latest
ports:
- containerPort: 8443
volumeMounts:
- name: config-vol
mountPath: /config
volumes:
- name: config-vol
configMap:
name: example-config-dir
And the Dockerfile (there are other steps which copy the jar file in which I haven't detailed)
VOLUME /tmp
RUN echo "java -Dspring.config.location=file:///config/ -jar myjarfile.jar" > ./start-spring-boot-app.sh"
CMD ["sh", "start-spring-boot-app.sh"]
As explained in Create ConfigMaps from Directories and Create ConfigMaps from files, when you create a ConfigMap using --from-file
, the filename becomes a key stored in the data section of the ConfigMap. The file contents become the key’s value.
To do the way you want, a better way would be creating the yml like this
apiVersion: v1
kind: ConfigMap
metadata:
name: special-config
namespace: default
data:
SPECIAL_LEVEL: very
SPECIAL_TYPE: charm
and then apply like this:
kubectl create -f https://k8s.io/examples/configmap/configmap-multikeys.yaml
When the pod runs, the command ls /config
produces the output below:
special.level
special.type
The way you did, should generate a file with same name as your original files and within it the contents of the file.