Kubernetes configmap removes all the contents of existing directory

4/5/2019

I have created a configmap and a pod yaml file .

I have tried multiple solutions but none worked for me .

kubectl describe cm cf3
Name:         cf3
Namespace:    default
Labels:       <none>
Annotations:  <none>

Data
====
index.html:
----
hii im marimmo

Events:  <none

pod yaml file

apiVersion: v1
kind: Pod
metadata:
  name: dapi-test-pod
spec:
  containers:
  - name: test-container
    image: manya97/manya_tomcat:0.1

  volumeMounts:
  - name: config-volume
    mountPath: /apache-tomcat-8.0.32/webapps/SampleWebApp/index.html
    subPath: index.html
volumes:
- name: config-volume
  configMap:
          name: cf3

restartPolicy: Never

this was supposed to replace existing index.html file but somehow it removes all the content of SampleWebApp and places only index.html. I dont know if have done it in correct way , I want to replace only content of index.html. Might be possible that mounting works this way I do not know .

-- shubham_asati
configmap
kubernetes

1 Answer

4/6/2019

Mounts are always directory-based. So having a mount in your yaml file tells k8s to mount the contents of the configMap (which could be one or more files) into the directory.

Whatever has been inside of the directory before the mount is gone then.

See the official documentation here: https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/

There is a hint saying "Caution: If there are some files in the mount directory, they will be deleted."

-- gami86
Source: StackOverflow