kubernetes - k3d how to use local directory as a Persistent volume

6.4k Views Asked by At

I am using k3d to run local kubernetes

I have created a cluster using k3d.

Now I want to mount a local directory as a persistent volume.

How can i do this while using k3d.

I know in minikube

$ minikube start --mount-string="$HOME/go/src/github.com/nginx:/data" --mount

Then If you mount /data into your Pod using hostPath, you will get you local directory data into Pod.

Is there any similar technique here also while using k3d

2

There are 2 best solutions below

0
On BEST ANSWER

According to the answers to this Github question the feature you're looking for is not available yet.

Here is some idea from this link:

The simplest I guess would be to have a pretty generic mount containing all the code, e.g. in my case, I could do k3d cluster create -v "$HOME/git:/git@agent:*" to get all the repositories on my host present in all agent nodes to be used for hot-reloading.

According to this documentation one can use the following command with the adequate flag:

k3d cluster create NAME -v [SOURCE:]DEST[@NODEFILTER[;NODEFILTER...]]

This command mounts volumes into the nodes

(Format:[SOURCE:]DEST[@NODEFILTER[;NODEFILTER...]]

Example:

`k3d cluster create --agents 2 -v /my/path@agent:0,1 -v /tmp/test:/tmp/other@server:0`

Here is also an interesting article how volumes and storage work in a K3s cluster (with examples).

0
On

I think this feature is not yet available https://github.com/k3d-io/k3d/issues/566

So far we can only mount volumn when we create a new cluster.

k3d cluster create mykube --volume HOME/go/src/github.com/nginx:/data