Conversation
Co-authored-by: Noelle Leigh <5957867+noelleleigh@users.noreply.github.com>
7ea0f57 to
09378ed
Compare
There was a problem hiding this comment.
Can you include a section here explaining why someone might want to use this tar-based method of getting files out of a container instead of using kubectl cp?
There was a problem hiding this comment.
I'll explain it to you, and then try to condense an explanation for the readme.
Here is what kubectl cp --help says:
Examples:
# !!!Important Note!!!
# Requires that the 'tar' binary is present in your container
# image. If 'tar' is not present, 'kubectl cp' will fail.
#
# For advanced use cases, such as symlinks, wildcard expansion or
# file mode preservation, consider using 'kubectl exec'.
# Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace <some-namespace>
tar cf - /tmp/foo | kubectl exec -i -n <some-namespace> <some-pod> -- tar xf - -C /tmp/bar
# Copy /tmp/foo from a remote pod to /tmp/bar locally
kubectl exec -n <some-namespace> <some-pod> -- tar cf - /tmp/foo | tar xf - -C /tmp/bar
These more advanced examples are what tarfetch is doing - allowing a bit more flexibility than kubectl cp and puts it in a nice UI button.
I mentioned flexibility... in the less advanced examples for kubectl cp, it can only work when you know the exact name of the pod (odd since you can use a pattern like deploy/<deployment name> when using the kubectl exec examples). This means we can create a sync button which points at a deployment as a sync target.
# Copy /tmp/foo_dir local directory to /tmp/bar_dir in a remote pod in the default namespace
kubectl cp /tmp/foo_dir <some-pod>:/tmp/bar_dir
# Copy /tmp/foo local file to /tmp/bar in a remote pod in a specific container
kubectl cp /tmp/foo <some-pod>:/tmp/bar -c <specific-container>
# Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace <some-namespace>
kubectl cp /tmp/foo <some-namespace>/<some-pod>:/tmp/bar
# Copy /tmp/foo from a remote pod to /tmp/bar locally
kubectl cp <some-namespace>/<some-pod>:/tmp/foo /tmp/bar
There was a problem hiding this comment.
Maybe something like...
## Alternatives
### Syncback
[Syncback](https://github.com/tilt-dev/tilt-extensions/tree/master/syncback) was the first Tilt extension to enable synchronization of files out of a Kubernetes container. Unfortunately it relies on rsync being installed on the host and container systems; a requirement which is rarely fulfilled by default (contrast this with tar, which is pre-installed on most Unix-y systems and can be made available through Windows Subsystem for Linux).
### kubectl cp
Kubectp has a [copy command](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#cp) which relies on tar as well (tarfetch is designed from the "advanced use cases" mentioned in `kubectl cp --help`). The biggest difference between using tarfetch and using `kubectl cp` is the constraints of the latter. Where `kubectl cp` requires an explicit pod name, tarfetch (leveraging `kubectl exec`) can derive the correct pod from a `<type>/<name>` declaration (i.e. `deployment/my-app`).There was a problem hiding this comment.
That looks good to me (minus the "Kubectp" typo).
Uh oh!
There was an error while loading. Please reload this page.