Here is my deployment file and I am applying it with command kubectl apply -f deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: scan-deployment
labels:
app: scan
spec:
replicas: 1
selector:
matchLabels:
app: scan
template:
metadata:
labels:
app: scan
spec:
volumes:
- name: shared-files
configMap:
name: shared-files
containers:
- name: scan-svc
image: scan:latest
imagePullPolicy: IfNotPresent
volumeMounts:
- name: shared-files
mountPath: /shared
Here I have my file test.txt
file which is located in ./shared/test.txt
that I have configured using configMap.
Now the thing is that I have subFolder in my local disk ./shared/xml
, ./shared/report
and I want to map /shared
with container but not able to do it. I don't want to map config files from these subfolder. Deployed code creates report in xml and pdf format and saves it in respective folder and I want to map that to local disk.
Configmaps don't support recursive directories. When you create Configmap from ./shared
directory, only the regular files in the directory are included. Sub directories are ignored.
You should create a regular volume from ./shared
directory then mount it to the container.
It would be nice, if you would tell us why you are not able to do it, but I assume it overwrites your content under /shared
, which is an expected behavior.
When you map your /shared
; on the host with /shared
in the container, it is going to be mapped correctly, but once configMap
gets created, it is going to overwrite the content of the path, by whatever is in the configMap
.