Skip to content

Instantly share code, notes, and snippets.

@tallclair
Last active January 18, 2024 22:19
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save tallclair/9217e2694b5fdf27b55d6bd1fda01b53 to your computer and use it in GitHub Desktop.
Save tallclair/9217e2694b5fdf27b55d6bd1fda01b53 to your computer and use it in GitHub Desktop.
kubectl cp equivalents
# 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/foo_dir
tar cf - /tmp/foo_dir | kubectl exec -i <some-pod> -- tar xf -
# Copy /tmp/foo local file to /tmp/bar in a remote pod in a specific container
kubectl cp /tmp/foo <some-pod>:/tmp/foo -c <specific-container>
tar cf - /tmp/foo | kubectl exec -i <some-pod> -c <specific-container> -- tar xf -
# 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/foo
tar cf - /tmp/foo | kubectl exec -i -n <some-namespace> <some-pod> -- tar xf -
# Copy /tmp/foo from a remote pod to /tmp/bar locally
kubectl cp <some-namespace>/<some-pod>:/tmp/foo foo
kubectl exec -n <some-namespace> <some-pod> -- tar cf - /tmp/foo | tar xf -
# You can even copy a file from one pod to another!
kubectl exec <some-pod> -- tar cf - /tmp/foo | kubectl exec -i <other-pod> -- tar xf -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment