4

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

Santhosh
  • 9,965
  • 20
  • 103
  • 243
  • Did you see [this example](https://dev.to/bbende/k3s-on-raspberry-pi-volumes-and-storage-1om5#:~:text=K3s%20comes%20with%20a%20default,where%20the%20pod%20is%20located.) how volumes and storage work in a K3s cluster? – kkopczak Mar 16 '22 at 01:04
  • Were you able to do it? I'm looking for a way to do the same thing. – Pedro Rodrigues Jun 28 '22 at 15:01

2 Answers2

3

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

thor
  • 21,418
  • 31
  • 87
  • 173
kkopczak
  • 742
  • 2
  • 8
1

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
Oceania Water
  • 267
  • 2
  • 11