Is it possible to mount a local computer folder to Kubernetes for development, like docker run -v

10.6k Views Asked by At

Do you know if it is possible to mount a local folder to a Kubernetes running container.

Like docker run -it -v .:/dev some-image bash I am doing this on my local machine and then remote debug into the container from VS Code.

Update: This might be a solution: telepresence Link: https://kubernetes.io/docs/tasks/debug-application-cluster/local-debugging/

Do you know it it is possible to mount a local computer to Kubernetes. This container should have access to a Cassandra IP address.

Do you know if it is possible?

2

There are 2 best solutions below

3
On

Kubernetes Volume

Using hostPath would be a solution: https://kubernetes.io/docs/concepts/storage/volumes/#hostpath

However, it will only work if your cluster runs on the same machine as your mounted folder.

Another but probably slightly over-powered method would be to use a distributed or parallel filesystem and mount it into your container as well as to mount it on your local host machine. An example would be CephFS which allows multi-read-write mounts. You could start a ceph cluster with rook: https://github.com/rook/rook

Kubernetes Native Dev Tools with File Sync Functionality

A solution would be to use a dev tool that allows you to sync the contents of the local folder to the folder inside a kubernetes pod. There, for example, is ksync: https://github.com/vapor-ware/ksync

I have tested ksync and many kubernetes native dev tools (e.g. telepresence, skaffold, draft) but I found them very hard to configure and time-consuming to use. That's why I created an open source project called DevSpace together with a colleague: https://github.com/loft-sh/devspace

It allows you to configure a real-time two-way sync between local folders and folders within containers running inside k8s pods. It is the only tool that is able to let you use hot reloading tools such as nodemon for nodejs. It works with volumes as well as with ephemeral / non-persistent folders and lets you directly enter the containers similar to kubectl exec and much more. It works with minikube and any other self-hosted or cloud-based kubernetes clusters.

Let me know if that helps you and feel free to open an issue if you are missing something you need for your optimal dev workflow with Kubernetes. We will be happy to work on it.

1
On

As long as we talk about doing stuff like docker -v a hostPath volume type should do the trick. But that means that you need to have the content you want to use stored on the Node that the Pod will run upon. Meaning that in case of GKE it would mean the code needs to exist on google compute node, not on your workstation. If you have local k8s cluster provisioned (minikube, kubeadm...) for local dev, that could be set to work as well.