Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mountPath overrides the rest of the files in that same folder

Tags:

kubernetes

I have a volume with a secret called config-volume. I want to have that file in the /home/code/config folder, which is where the rest of the configuration files are. For that, I mount it as this:

volumeMounts:
  - name: config-volumes
  - mountPath: /home/code/config

The issue is that, after deploying, in the /home/code/config I only have the secret file and the rest of them are gone

So the /home/code/config is an existing folder (not empty), I suspect that the volumeMount overwrites the folder.

Is there a way that this can be done without overwriting everything?

like image 640
Ankoku Avatar asked Sep 28 '16 15:09

Ankoku


2 Answers

You can do the following, taken from this GitHub issue

containers:
- volumeMounts:
  - name: config-volumes
    mountPath: /home/code/config
    subPath: config
volumes:
- name: config-volumes
  configMap:
    name: my-config

Suggested that your ConfigMapis called my-config and that you have a key config in it.

like image 95
Stevan Avatar answered Nov 13 '22 15:11

Stevan


Kubernetes Secrets are mounted as a directory, with each key as a file in that directory. So in your case, the config-volumes secret is mounted to /home/code/config, shadowing whatever that directory was before.

You could specify your volume mount as:

volumeMounts:
  - name: config-volumes
  - mountPath: /home/code/config/config-volumes

which would provide a config-volumes directory inside the config directory with files for your secret's keys inside.

like image 29
CJ Cullen Avatar answered Nov 13 '22 15:11

CJ Cullen