How to avoid override the container directory when using pvc in kubernetes?
Asked Answered
R

1

6

When using pvc to persist the container data, it seems pvc always override the container's directory, the original data in directory will not be available, what's the reason ?

Rab answered 8/8, 2018 at 5:58 Comment(5)
docker volume seems it could copy the content of directory.Rab
it's unclear what you're asking about. Is it about the contents of a directory before you mounted to it something else?Consumable
yes, I would like to persist the the content of directory with pvc, but after mount with pvc , the content lost, how to solve ?Rab
I'm sure in linux it's not possible to obtain a mountpoint contents after you mounted something. Unless you actually mean something else, in that case you need to explain your problem with better details.Consumable
seems only support directory mount using softlink.Rab
H
7

This is by design. Kubelet is responsible for preparing the mounts for your container, and they can come from plaethora of different storagebackends. At the time of mounting they are empty and kubelet has no reason to put any content in them.

That said, there are ways to achieve what you seem to expect by using init container. In your pod you define init container using your docker image, mount your volume in it in some path (ie. /target) but instead of running regular content of your container, run something like

cp -r /my/dir/* /target/ 

which will initiate your directory with expected content and exit allowing further startup of the pod

Haldis answered 8/8, 2018 at 6:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.