Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 437
Chris G. Avatar asked Dec 19 '17 20:12

Chris G.


People also ask

Can you use Kubernetes for local development?

'Local Kubernetes development' aka 'development of containerised microservices in a local Kubernetes cluster' means that applications are designed and developed for a Kubernetes architecture – i. e. a developer works with a Kubernetes architecture locally.

Can I deploy in Kubernetes without Docker?

Quite the contrary; Kubernetes can run without Docker and Docker can function without Kubernetes. But Kubernetes can (and does) benefit greatly from Docker and vice versa. Docker is a standalone software that can be installed on any computer to run containerized applications.

Can Kubernetes automatically mount the storage of your choice?

Storage orchestration Kubernetes allows you to automatically mount a storage system of your choice, such as local storages, public cloud providers, and more.


2 Answers

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.

like image 45
Radek 'Goblin' Pieczonka Avatar answered Oct 02 '22 16:10

Radek 'Goblin' Pieczonka


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.

like image 110
Lukas Gentele Avatar answered Oct 02 '22 17:10

Lukas Gentele