1

How should Mutagen be configured, to synchronise local-host source code files with a Docker volume, onto a Kubernetes cluster?

I used to mount my project directory onto a container, using hostPath:

kind: Deployment
spec:
  volumes:
    - name: "myapp-src"
      hostPath:
        path: "path/to/project/files/on/localhost"
        type: "Directory"
  ...
  containers:
    - name: myapp
      volumeMounts: 
        - name: "myapp-src"
          mountPath: "/app/"

but this has permission and symlinks problems, that I need to solve using Mutagen.
At the moment, it works correctly when relying on docker-compose (run via mutagen project start -f path/to/mutagen.yml):

sync:
  defaults:
    symlink:
      mode: ignore
    permissions:
      defaultFileMode: 0664
      defaultDirectoryMode: 0775
  myapp-src:
    alpha: "../../"
    beta: "docker://myapp-mutagen/myapp-src"
    mode: "two-way-safe"

But it isn't clear to me how to configure the K8S Deployment, in order to use Mutagen for keeping the myapp-src volume in sync with localhost?

Kamafeather
  • 8,663
  • 14
  • 69
  • 99
  • Your source files should go into an _image_, not a volume, and in general it's difficult to sync out-of-cluster local files with a Kubernetes setup. Can you use a normal non-container local environment for development, and then run unit-tested self-contained images in your cluster setup? – David Maze Oct 13 '21 at 13:08
  • Nope, our company approach is to keep production and development environment as similar as possible. Avoiding containers is not what we want: the setup and sync works perfectly with containers & Mutagen, when run via `docker-compose`, why wouldn't K8s be able to do the same? – Kamafeather Oct 13 '21 at 13:24
  • Without mounting source code from host (only in development) the image needs to re-`build` & re-`run` for every single minimal change; this reduces productivity, I believe it doesn't fit development. – As mentioned I already was syncing host onto a (local) Kubernetes cluster using `hostPath`, and coding on the source code without needing to rebuild every time (even without using Mutagen). But I need Mutagen here because of additional requirements. – Kamafeather Oct 13 '21 at 13:25
  • By the way, to avoid misunderstandings: **the source files are already in the image**. My use case is to mount the localhost source files onto the ones packed in the image, so I can edit source code without rebuilding/redeploying. – Kamafeather Oct 13 '21 at 13:31

0 Answers0