16

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?

Ankoku
  • 339
  • 1
  • 3
  • 7
  • 3
    You have to use the hidden subPath value, as shown here: https://stackoverflow.com/questions/33415913/whats-the-best-way-to-share-mount-one-file-into-a-pod – sprut Jun 28 '18 at 23:42

2 Answers2

18

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.

Stevan
  • 1,933
  • 1
  • 18
  • 19
3

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.

CJ Cullen
  • 5,452
  • 1
  • 26
  • 34