Search code examples
kubernetesmountk3d

How do I use the local directory as a persistent volume in k3d?


I am using k3d to run local Kubernetes and created a cluster using k3d.

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

I know in minikube you can do:

$ 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 your local directory data into Pod.

Is there any similar technique in k3d?


Solution

  • 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).