Michel L
Michel L

Reputation: 535

How to mimic Docker ability to pre-populate a volume from a container directory with Kubernetes

I am migrating my previous deployment made with docker-compose to Kubernetes. In my previous deployment, some containers do have some data made at build time in some paths and these paths are mounted in persistent volumes. Therefore, as the Docker volume documentation states,the persistent volume (not a bind mount) will be pre-populated with the container directory content.

I'd like to achieve this behavior with Kubernetes and its persistent volumes, How can I do ? Do I need to add some kind of logic using scripts in order to copy my container's files to the mounted path when data is not present the first time the container starts ?

Possibly related question: Kubernetes mount volume on existing directory with files inside the container

Upvotes: 2

Views: 2258

Answers (1)

LMR
LMR

Reputation: 101

I think your options are

  • ConfigMap (are "some data" configuration files?)
  • Init containers (as mentioned)
  • CSI Volume Cloning (clone combining an init or your first app container)
  • there used to be a gitRepo; deprecated in favour of init containers where you can clone your config and data from
  • HostPath volume mount is an option too
  • An NFS volume is probably a very reasonable option and similar from an approach point of view to your Docker Volumes
    • Storage type: NFS, iscsi, awsElasticBlockStore, gcePersistentDisk and others can be pre-populated. There are constraints. NFS probably the most flexible for sharing bits & bytes.

FYI The subPath might be of interest too depending on your use case and PodPreset might help in streamlining the op across the fleet of your pods

HTH

Upvotes: 6

Related Questions