Re: how to mount volume without override original data in pod

6,963 views
Skip to first unread message

Michelle Au

unread,
Jun 21, 2017, 1:03:42 PM6/21/17
to Hanks Justin, Kubernetes developer/contributor discussion
What environment are you running in?

If you're just using a local one-node cluster, then you can use the hostpath volume to mount pre-populated data.

But if you're using a multi-node cluster, then you need to prepopulate your data onto some networked storage first.

On Tue, Jun 20, 2017 at 8:31 PM, Hanks Justin <zhouh...@gmail.com> wrote:
Hi, I am a new comer to k8s, I have a question about volume usage in k8s.

From Docker Docs, there is a feature described in data volumes:

  • Volumes are initialized when a container is created. If the container’s base image contains data at the specified mount point, that existing data is copied into the new volume upon volume initialization. (Note that this does not apply when mounting a host directory.)

Use the docker command, it will be `$ docker run -d -P --name web -v /webapp training/webapp python app.py`. And the data in the path `/webapp` will be copied to somewhere in the host without empty it. 

How to implement this when using k8s. I tried `hostPath`, `PersistentVolumeClaim`, and they all load an empty directory to my mount point. Any suggestions?

Thank you for your time.

--
You received this message because you are subscribed to the Google Groups "Kubernetes developer/contributor discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-dev+unsubscribe@googlegroups.com.
To post to this group, send email to kubernetes-dev@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kubernetes-dev/6a0ffdd6-6180-4b8c-910f-d3236dd8802a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tim Hockin

unread,
Jul 1, 2017, 7:32:17 PM7/1/17
to Hanks Justin, Kubernetes developer/contributor discussion
Can you say more about hat you are trying to achieve?
Message has been deleted

Hanks

unread,
Jul 3, 2017, 1:52:33 AM7/3/17
to Tim Hockin, Kubernetes developer/contributor discussion
@thockin Thank you for your reply. Here is my usage, I have a data pre-populated postgresql image with a volume path set on `/var/lib/postgresql/data`, and I want to the data copied to the somewhere automatically when I create pod.

From Docker usage, [If the container’s base image contains data at the specified mount point, that existing data is copied into the new volume upon volume initialization], when I use `docker run -d -P --name db -v /var/lib/potgresql/data`, the data pre-populated in `/var/lib/potgresql/data` can be copied to a path in host.

So how to use k8s to achieve this, I tried volume settings, like `hostPath` and `PersistentVolumeClaim`, But they all override the data in path `/var/lib/potgresql/data`, with making it empty.  

Thank you for your time.
On Sun, Jul 2, 2017 at 8:32 AM, Tim Hockin <tho...@google.com> wrote:
Can you say more about hat you are trying to achieve?
On Jun 20, 2017 8:31 PM, "Hanks Justin" <zhouh...@gmail.com> wrote:
Hi, I am a new comer to k8s, I have a question about volume usage in k8s.

From Docker Docs, there is a feature described in data volumes:

  • Volumes are initialized when a container is created. If the container’s base image contains data at the specified mount point, that existing data is copied into the new volume upon volume initialization. (Note that this does not apply when mounting a host directory.)

Use the docker command, it will be `$ docker run -d -P --name web -v /webapp training/webapp python app.py`. And the data in the path `/webapp` will be copied to somewhere in the host without empty it. 

How to implement this when using k8s. I tried `hostPath`, `PersistentVolumeClaim`, and they all load an empty directory to my mount point. Any suggestions?

Thank you for your time.

--
You received this message because you are subscribed to the Google Groups "Kubernetes developer/contributor discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-dev+unsubscribe@googlegroups.com.

To post to this group, send email to kuberne...@googlegroups.com.

Clayton Coleman

unread,
Jul 3, 2017, 12:00:49 PM7/3/17
to Hanks, Tim Hockin, Kubernetes developer/contributor discussion
In intent, this seems is a small use case out of the broader "I want to be able to use content out of another image or container" feature (which has been discussed for a long time).  Ie "I want an empty dir which has the contents of an image directory by default".

The biggest challenge to that feature is the limitations of docker's current API (an images filesystem is complex to construct without creating and managing a container) and the open question about where we might want to go in the future (should mounting a directory from a container that exposes a fuse filesystem be considered part of the same feature).  But I do think there is a lot of desire to make such a feature happen.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-de...@googlegroups.com.

To post to this group, send email to kuberne...@googlegroups.com.

Hanks

unread,
Jul 4, 2017, 7:38:47 AM7/4/17
to Clayton Coleman, Kubernetes developer/contributor discussion, Tim Hockin
Thank you for your reply.  I seems to get the point. Looking forward for this new feature:)

Clayton Coleman <ccol...@redhat.com>于2017年7月4日 周二01:00写道:
In intent, this seems is a small use case out of the broader "I want to be able to use content out of another image or container" feature (which has been discussed for a long time).  Ie "I want an empty dir which has the contents of an image directory by default".

The biggest challenge to that feature is the limitations of docker's current API (an images filesystem is complex to construct without creating and managing a container) and the open question about where we might want to go in the future (should mounting a directory from a container that exposes a fuse filesystem be considered part of the same feature).  But I do think there is a lot of desire to make such a feature happen.



On Jul 3, 2017, at 1:52 AM, Hanks <zhouh...@gmail.com> wrote:

@thockin Thank you for your reply. Here is my usage, I have a data pre-populated postgresql image with a volume path set on `/var/lib/postgresql/data`, and I want to the data copied to the somewhere automatically when I create pod.

From Docker usage, [If the container’s base image contains data at the specified mount point, that existing data is copied into the new volume upon volume initialization], when I use `docker run -d -P --name db -v /var/lib/potgresql/data`, the data pre-populated in `/var/lib/potgresql/data` can be copied to a path in host.

So how to use k8s to achieve this, I tried volume settings, like `hostPath` and `PersistentVolumeClaim`, But they all override the data in path `/var/lib/potgresql/data`, with making it empty.  

Thank you for your time.
On Sun, Jul 2, 2017 at 8:32 AM, Tim Hockin <tho...@google.com> wrote:
Can you say more about hat you are trying to achieve?
On Jun 20, 2017 8:31 PM, "Hanks Justin" <zhouh...@gmail.com> wrote:
Hi, I am a new comer to k8s, I have a question about volume usage in k8s.

From Docker Docs, there is a feature described in data volumes:

  • Volumes are initialized when a container is created. If the container’s base image contains data at the specified mount point, that existing data is copied into the new volume upon volume initialization. (Note that this does not apply when mounting a host directory.)

Use the docker command, it will be `$ docker run -d -P --name web -v /webapp training/webapp python app.py`. And the data in the path `/webapp` will be copied to somewhere in the host without empty it. 

How to implement this when using k8s. I tried `hostPath`, `PersistentVolumeClaim`, and they all load an empty directory to my mount point. Any suggestions?

Thank you for your time.

--
You received this message because you are subscribed to the Google Groups "Kubernetes developer/contributor discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-de...@googlegroups.com.
To post to this group, send email to kuberne...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kubernetes-dev/6a0ffdd6-6180-4b8c-910f-d3236dd8802a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Kubernetes developer/contributor discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-de...@googlegroups.com.
To post to this group, send email to kuberne...@googlegroups.com.

Tim Hockin

unread,
Jul 6, 2017, 8:17:14 PM7/6/17
to Clayton Coleman, Hanks, Kubernetes developer/contributor discussion
Simpler would be to just adopt Docker's semantics somehow, even if I
find this to be somewhat hacky.

e.g. could we add a `populateFromContainer: true` to the VolumeMount?
I am not sure how to do it - Docker doesn't really give us the right
hooks for it..

sarjeet singh

unread,
May 11, 2018, 12:59:00 PM5/11/18
to Kubernetes developer/contributor discussion
Sorry to jump out on an old thread... but, Just checking to see if there is a feature being implemented or alternate solution to do this today in k8s. 

I have a similar use case and trying to make it work with emptyDir but data directory is getting empty once container starts. Another temporary solution I am thinking is to use a different volume path and copy Data to it once container start or probably symlinking once container start to the data directory. 

-Sarjeet

Tim Hockin

unread,
May 11, 2018, 2:28:37 PM5/11/18
to ssarje...@gmail.com, Kubernetes developer/contributor discussion
Copying the data yourself is the normal solution to this.  As far as I know nobody has proposed a formal solution to this, and it doesn't come up very often anymore (since it is a discouraged pattern)

Jing Xu

unread,
Jun 21, 2018, 7:25:49 PM6/21/18
to Kubernetes developer/contributor discussion
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages