Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two-way sync #2492

Open
balopat opened this issue Jul 17, 2019 · 49 comments
Open

Two-way sync #2492

balopat opened this issue Jul 17, 2019 · 49 comments

Comments

@balopat
Copy link
Contributor

balopat commented Jul 17, 2019

Syncing in Skaffold to the container works well. However, applications sometimes change files on the filesystem themselves. If this happens inside the container, it is hard to get that change quickly during development.

There might be two types of file changes:

  1. inside the code repository, e.g. under the project files in an IDE
  2. outside of the code repo, e.g. in /var/log/, or somewhere else

Mounting directories is tricky and slow, also can collide with Skaffold's one directional filesync.
Maybe Skaffold should be able to help with syncing back from the container in dev mode.

I would like to collect feedback from users who face this and see what use cases are there.

@wstrange
Copy link
Contributor

wstrange commented Jul 17, 2019

Our use case: We have a complex application with 100+ json configuration files. These files are updated by the application UI running in the container. To save them in git we need to get them back out to the developers environment.

We have tried using minikube volume mounts for this use case. It works- but has some drawbacks - such as complexity (we want to keep things simple for the developer), it doesn't work on non minikube environments, and you can get into a sync loop race with skaffold as files are updated.

Today we use kubectl cp to pull the files out of the container. It is low tech - but is working well enough. A little bit of chrome / ease of use around this workflow would be nice.

@antl3x
Copy link

antl3x commented Jul 17, 2019

Our use case: We have a complex application with 100+ json configuration files. These files are updated by the application UI running in the container. To save them in git we need to get them back out to the developers environment.

We have tried using minikube volume mounts for this use case. It works- but has some drawbacks - such as complexity (we want to keep things simple for the developer), it doesn't work on non minikube environments, and you can get into a sync loop race with skaffold as files are updated.

Today we use kubectl cp to pull the files out of the container. It is low tech - but is working well enough. A little bit of chrome / ease of use around this workflow would be nice.

Great to hear from you. We are facing the same challenge. The problem with the kubectl cp is that we need to give the pod name, which is dynamic.

So kubectl cp works only manually.

@wstrange
Copy link
Contributor

The problem with the kubectl cp is that we need to give the pod name, which is dynamic.

We use selector labels on kubectl cp (-l app=myapp)- so the shell script is reasonably generic.

@tejal29 tejal29 added the priority/p2 May take a couple of releases label Aug 26, 2019
@balopat balopat added priority/p0 Highest priority. We are actively looking at delivering it. and removed priority/p2 May take a couple of releases labels Sep 6, 2019
@strikeout
Copy link

strikeout commented Sep 17, 2019

Can we take some inspiration by how DevSpace solved bi-directional host<>pod sync?
They inject a small binary into the container which in turn scans and passes a list of files not present on the host.

https://github.com/devspace-cloud/devspace/tree/master/sync/inject

DevSpace establishes a bi-directional code synchronization between the specified local folders and the remote container folders. It automatically recognizes any changes within the specified folders during the session and will update the corresponding files locally and remotely in the background. It uses a small helper binary that is injected into the target container to accomplish this.
The algorithm roughly works like this:
Inject a small helper binary via kubectl cp into the target container
Download all files that are not found locally
Upload all files that are not found remotely
Watches locally and remotely for changes and uploads or downloads them

@tejal29 tejal29 added priority/p1 High impact feature/bug. and removed priority/p0 Highest priority. We are actively looking at delivering it. labels Sep 23, 2019
@dsebastien
Copy link

I don't know if my use case is valid as I'm just starting to use K8S, but I currently have a multi-stage docker build for two micro-services which need to be deployed to K8S.

I'm using Minikube and plan to deploy the "dev" stage of my dockerfiles to K8S. That "dev" stage's goal is to provide me with an environment in which I have all the necessary dependencies and tools to build (node, npm, etc). As such my goal is to develop, build and run from within K8S.

This setup was working fine with docker + docker-compose, where I could bind-mount my local source code into the containers and have it sync both ways.

At the moment I'm looking at solutions for this with K8S, but have found quite a lot of different things so far.. :)

Skaffold looks really appealing for multiple reasons, but at the moment I'm thinking about combining skaffold and devspace to reach my goals. If Skaffold could do it all, then all the better :)

@paolomainardi
Copy link

Maybe I am missing something, but should’t be easy to just using an hostpath volume as docker does for local development ?

@maluio
Copy link

maluio commented Feb 16, 2020

@paolomainardi
Mounting the volume using a hostpath works.
However, I run into a lot of problems due to user id mapping between the user in the container and the user on the host system. There is a way to handle this mapping properly, but it is IMHO non-trivial to set up https://docs.docker.com/engine/security/userns-remap/

In case I am missing something a nudge into the right direction is highly appreciated.

@EnziinSystem
Copy link

Two-way file synchronization is really necessary.
In development mode, we often have to create models through scaffold programs such as migrate files, controllers, etc.

@tstromberg tstromberg added priority/p2 May take a couple of releases priority/p3 agreed that this would be good to have, but no one is available at the moment. and removed kind/feature-request priority/p1 High impact feature/bug. priority/p2 May take a couple of releases labels Apr 20, 2020
@tstromberg
Copy link
Contributor

Two-way sync can be especially tricky with remote clusters, where reverse mounts are not easily done.

I haven't heard about anyone actively planning on working on this, so I'm going to downgrade the priority. If someone wants to propose a design document, I'd love to take a look.

@EnziinSystem
Copy link

EnziinSystem commented Apr 25, 2020

@tstromberg

Two-way sync can be enabled locally for development mode, not a remote cluster.

For example:

I am a developer Ruby on Rails, I need to generate a model.

rails generate scaffold Post name:string title:string content:text

Many files generated in the pod/container, but I cannot copy them by the manual.

@pierreyves-lebrun
Copy link

Though tricky, two-way sync is essential as people developing in containers simply can’t use Skaffold at the moment.

Solutions such as Okteto or Devspace do have that feature so developers don’t have to pollute their local machine with dev dependencies.

@nkubala nkubala added help wanted We would love to have this done, but don't have the bandwidth, need help from contributors fixit kind/feature-request and removed kind/design discussion labels Jun 16, 2020
@simonoff
Copy link
Contributor

Guys! Such feature is a must have for full local development inside Kubernetes. I have reviewed the ways how to implement it - and only one way looks is better for me - inject a sidecar container which will do such sync. In similar way how the devspace doing it. What do you think?

@renzodavid9
Copy link
Contributor

Update about this issue: currently we had to deprioritize the work for this feature; it will imply a good amount of changes. We are aiming to resume work for this as soon as we have more cicles available for the work (hopefully some point in h2 2023). Thanks everyone for your inputs.

@renzodavid9 renzodavid9 added priority/p3 agreed that this would be good to have, but no one is available at the moment. and removed priority/p2 May take a couple of releases labels Mar 20, 2023
@bhack
Copy link

bhack commented May 23, 2023

@renzodavid9 I made a recap here on why it is hard to develop on Vscode + Kubernetes pod also with Skaffold at devcontainers/spec#10 (comment)

What do you think?

@samjurriaans
Copy link

Is there any chance that this features will be worked on in h2 2023 by the core team?

Cannot wait to have this feature in skaffold!

Are there any other Laravel developers using kubernetes and skaffold for dev environments who deal with this issue?

@euven
Copy link

euven commented Aug 23, 2023

Any update here? This is the only feature preventing us from using skaffold...

@shadiramadan
Copy link

I’m surprised this isn’t a higher priority issue.

@shadiramadan
Copy link

@samjurriaans this is an issue for any workflow that has configuration data generated by some process CLI/UI that runs on the container.

That data is necessary to sync in multi env environments so it is not wiped when restarting skaffold…

@ericzzzzzzz ericzzzzzzz added priority/p1 High impact feature/bug. and removed priority/p3 agreed that this would be good to have, but no one is available at the moment. labels Jan 9, 2024
@ericzzzzzzz ericzzzzzzz self-assigned this Jan 24, 2024
@ericzzzzzzz
Copy link
Contributor

ericzzzzzzz commented Jan 24, 2024

Hi friends, I created a poc for downstream-sync https://github.com/ericzzzzzzz/skaffold/tree/downstream-sync , we'd like some feedbacks to formalize the design, if you can help to try out, that would be great! thanks!

To use this, you need to clone https://github.com/ericzzzzzzz/skaffold/tree/downstream-sync and build from source (You may want to back up your exiting skaffold binary first :) )

  • Clone the repo : https://github.com/ericzzzzzzz/skaffold/tree/downstream-sync
  • Run make clean && Local=true make install to install skaffold with this feature
  • You can try it with examples/hot-reload project
  • For your own project, you need to define download stanza under artifacts.image in your skaffold.yaml, example https://github.com/ericzzzzzzz/skaffold/blob/eac1ce65c53861c0993c8442aca62389886d7872/examples/hot-reload/skaffold.yaml#L28-L36
    • remoteSrc, is the relative directory to your container workspace

    • localDst, is destination where you want to place the downloaded from from remote container, it is the relative directory to your skaffold project workspace, perhaps making localDst to artifact build context dir makes more sense, we can change it to that : )

    • Excludes, a list of rules to exclude files that you don't want to sync back to your local, it's using github.com/bmatcuk/doublestar for pattern matching (glob + ** to match multiple dirs)

    • Limitations:

      • This feature only works for image built by skaffold, if you have a remote image and you want to sync some files from that, you need to wrap it into another image
      • It only works for Deployment and Pod resources at the moment.
      • localDst is only supposed to be relative to the workspace, if the current version allows to sync files to somewhere outside the skaffold workspace, we should fix that later.
      • This feature only works for skaffold dev
      • Technically, it's not sync, delete is not supported

@ericzzzzzzz ericzzzzzzz removed help wanted We would love to have this done, but don't have the bandwidth, need help from contributors fixit labels Jan 24, 2024
@shadiramadan
Copy link

Hello @ericzzzzzzz I will test this out! Beyond testing what does the path look like for getting this feature in?

@shadiramadan
Copy link

I have developers that get confused by having to remember copying changes back to their filesystem due to this issue so I'm hoping to improve DX through this change!

@ericzzzzzzz
Copy link
Contributor

Hi @shadiramadan , Our team has placed the Skaffold project in a maintenance state (KTLO). This means we won't be actively adding new features ourselves. However, we wholeheartedly welcome community contributions in the form of pull requests. To facilitate this, I've completed a design document for this downstream file-sync feature. I'll share this document next week and create issues outlining the feature's MVP, making it easier for the community to get involved

@shadiramadan
Copy link

@ericzzzzzzz would Google consider donating the project to the CNCF if that is the case? I'm not sure what that process is like but it could give the project the boost it deserves. Skaffold has come a long way and there are definitely some quality of life changes that would make the DX more friendly and increase adoption!

@bendory
Copy link

bendory commented Apr 2, 2024

Hello @shadiramadan , I'm the Engineering Manager for the Skaffold team at Google.

We would very much consider donating Skaffold to the CNCF -- especially if doing so means more community involvement from folks like you! Any interest in partnering with us on working through that process?

@bhack
Copy link

bhack commented Apr 2, 2024

What are the next steps?

@bhack
Copy link

bhack commented Apr 2, 2024

I suppose you need to open a ticket at https://github.com/cncf/sandbox right?

@bhack
Copy link

bhack commented Apr 2, 2024

P.s. Google Kaniko recently it is trying to do the same:
cncf/sandbox#88

@bendory
Copy link

bendory commented Apr 2, 2024

@bhack Correct on both counts. We would like to hear from Skaffold users and contributors interested in working on and supporting such an application!

@bhack
Copy link

bhack commented Apr 2, 2024

Can you open and pin a new ticket on this?

@ericzzzzzzz
Copy link
Contributor

Here is the draft design proposal for downstream sync, https://github.com/ericzzzzzzz/skaffold/blob/downstream-sync/docs-v2/design_proposals/downstream-sync.md

@shadiramadan
Copy link

Thank you @ericzzzzzzz I'll review the design proposal and your existing work. No promises on my own timelines but this has been a TODO on my end for a while!

@ericzzzzzzz ericzzzzzzz removed their assignment Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests